Search code examples
c#asp.netasp.net-mvcsignalrsignalr-hub

How significant is the performance difference between in-memory and database storage


I am creating a chat application in signalr. It currently has some functionality with storing to a database for permanent storage of messages. I want to implement user lists and have been re-reading this article:

http://www.asp.net/signalr/overview/signalr-20/hubs-api/mapping-users-to-connections#inmemory

How significant is this difference between in-memory storage? Is there likely to be more than a second difference between say, 1000 users and 10,000 users messaging each other at a normal rate of say 1msg per second (they've had lots of sugar)? And how useful is it? Any references to previous tests on performance would be hugely appreciated.

Secondly, I may be going about this the wrong way, but if I want to store a list of users and there are multiple chat-rooms, I assume I will need a separate dictionary per room? And if so, is this feasable since I want users to also be able to generate their own rooms too. I just don't see how in-memory can be achieved this way.

Thank you


Solution

  • I hate to provide a single link for an answer but this OSS fully functional chat room https://jabbr.net addresses everything you're worried about.

    Source: https://github.com/jabbr/jabbr

    To comment on your main concern in-memory vs db: DB adds the ability to persist data or even scale out your application BUT is FAR less performant than in-memory. Now don't get me wrong, even though it's FAR less performant it doesn't mean it'll take seconds to send messages depending on your app... It's all about tradeoffs.

    As for applying a DB oriented architecture to 1000 vs 10,000 users it all depends on how you implement it. For instance scale out provider REDIS runs all in-memory but then persists to disk on an interval. This is obviously extremely fast but allows for "some" data loss.