开发者

Save chat room data in Application variable or DB, where is better?

开发者 https://www.devze.com 2023-01-23 15:48 出处:网络
My application isWeb App Chat Room , it supports following features: 1.Create/Join/Close room 2.Send message in room (just live message, offline message might be supported in future)

My application is Web App Chat Room , it supports following features:

1.Create/Join/Close room

2.Send message in room (just live message, offline message might be supported in future)

I have done logic for application, but I'm considering where to save chat room data (message,room information, and users in room) ? I see开发者_如何学Go there are 2 options:

1. Application variable

2. Using file or database

-What if I saved in Application variable:

In case of there are 2000 rooms and 10000 users online, mean I have to persistence in Application variable (actually in RAM memory) information of 2000 rooms, more than 10000 message (text), these numbers might be increased by second if there are more users online in real time. and what's next ? I don't know what will happen to server, crash ? or my web app will be terminated ? whatever I don't want both results!

-What if I saved in file or DB (i.e: SQL Server DB)

Because of web application, clients have to send request every 1 second to fetch data (messages and user list in room). So in case of there are 2000 rooms and 10000 users online, means they will make 10000 requests every 1 second to DB. I don't know what will happen to DB, there are a lot of connections and in EVERY 1 second, can DB still be alive to serve request ?

I don't know where saving is good now because both seem are bad solution :(. What is your opinion ? please give me some ideas for this ? thank so much!


Database are made for this, to make a lot of requests, write and read data... they have a good optimize and not write everything down you know, they use cache and memory for make what you say.

I say use database, just take care to make a good design of your table. :) and delete old and not used data from your rooms time to time.

0

精彩评论

暂无评论...
验证码 换一张
取 消