locked
How to save a large data of chat room in asp.net chat application ? RRS feed

  • Question

  • User-877462416 posted

    Hi guys,

    I'm developing chat application on asp.net mvc, in my app, user can create room and invite other join to chat, but don't need to save chat room information.

    So, I designed to save all chat message ,room information and user info in Session and clear it when owner close the room.

    I'm worry about stressing server when I save alot of data (include room info, user info, and message) in Session if there are up to 5000 rooms created and alot of messages transfered in that room.

    Is my solution good enough ? is it ok to save in Session ? if it was bad, could you guys tell better solution, please !

    Wednesday, November 3, 2010 5:36 AM

Answers

  • User-952121411 posted

    2. Saving on file or database

     

    Option '2' to save this temporary data in a medium but not in In-Process Session State is still probably the better idea. As you mentioned, saving thousands of clients data in session could overload the memory (although if you have a web farm of 1000 servers each with 32GB of ram or something it may not be of concern), but for the typical scenario you might put too much load on the server.

    Saving objects or values out of process to SQL Server will bypass this issue of memory overuse.  As far as connections? Well SQL Server is a beast and so is ADO.NET. When used together you are able to leverage some fantastic built in capabilities like connection pooling, etc to minimize the issues with many concurrent db connections. The only real concern is just making sure if you change session to out of process to a medium like SQL Server, that all of your data being persisted is Serializable. Meaning, you could not say store in the database a SQLCommand object or something similar because it is not natively serailizable. But based on the type of information it sounds like you are going to save off for a chat, you should be fine (int, string, long, etc).

    As suggested prior, you might need to do a proof of concept to put light on which method is better based on your hardware and number of clients. In the meantime, have a look to the following for more information:

    SQL Server Connection Pooling (ADO.NET):

    http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx

    ASP.NET Session State:

    http://msdn.microsoft.com/en-us/library/ms972429.aspx

    Session-State Modes:

    http://msdn.microsoft.com/en-us/library/ms178586.aspx

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 5, 2010 9:49 AM

All replies

  • User541108374 posted

    Hi,

    like in most of such cases: measure. 

    Personally I would probably go for a database solution or make the session state out of process in the database if required to work with session state.


    Grz, Kris.

    Wednesday, November 3, 2010 6:14 AM
  • User-877462416 posted

    Because my app is web chat application so client must request to server every 1 second, seem there is no good solution between these solutions:

    1. Using Application or Server variable to save message data and chat room info which actually data will be saved on RAM until timeout

    2. Saving on file or database

    Both are bad, because :

    1. If we chose to save on Server variable (actually save on ram), the server might crash and our web app might be terminated when number of users and chat rooms up to thousand by thousand... or even more.....

    2. If we chose save to DB, we must open connection every 1s, and not only 1 connection, there is thousand by thousand clients connect every 1s, I don't know what DB server can handle those connections...hic

    Please give me good solution for this ?

    Wednesday, November 3, 2010 10:48 AM
  • User-952121411 posted

    2. Saving on file or database

     

    Option '2' to save this temporary data in a medium but not in In-Process Session State is still probably the better idea. As you mentioned, saving thousands of clients data in session could overload the memory (although if you have a web farm of 1000 servers each with 32GB of ram or something it may not be of concern), but for the typical scenario you might put too much load on the server.

    Saving objects or values out of process to SQL Server will bypass this issue of memory overuse.  As far as connections? Well SQL Server is a beast and so is ADO.NET. When used together you are able to leverage some fantastic built in capabilities like connection pooling, etc to minimize the issues with many concurrent db connections. The only real concern is just making sure if you change session to out of process to a medium like SQL Server, that all of your data being persisted is Serializable. Meaning, you could not say store in the database a SQLCommand object or something similar because it is not natively serailizable. But based on the type of information it sounds like you are going to save off for a chat, you should be fine (int, string, long, etc).

    As suggested prior, you might need to do a proof of concept to put light on which method is better based on your hardware and number of clients. In the meantime, have a look to the following for more information:

    SQL Server Connection Pooling (ADO.NET):

    http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx

    ASP.NET Session State:

    http://msdn.microsoft.com/en-us/library/ms972429.aspx

    Session-State Modes:

    http://msdn.microsoft.com/en-us/library/ms178586.aspx

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 5, 2010 9:49 AM