Do you use polling or long polling for small push applications in the station's message/messaging function?
Recently to do a small application, also looked up a lot of information. Now more tangled in which to use, the main consideration is the server load problem, looking to understand the elder brother pointing twos.
1) Ajax to do a 3-second polling, one will have a lot of invalid requests, and if the previous request server did not respond to the next request on the way, the server must also pear Alexander.
2) Do long polling words, a user on a connection, the server to hold at the same time so many connections, pear is also very big AH.
Little brother to the specific structure do not understand, anyway, these 2 methods put in this very tangled, because I will not analyze the specific server load or anything.
Another: The server for the Sheng and other cloud host and this small application to the immediacy of the requirements are not high.
------Solution--------------------
In the station letter also to do push send is relatively rare, the user stops in a page time is not too long. If there is such a need, it is really should add a memcache, whenever a user has an update operation, but also update memchache.
In addition, the station letter is to consider the mass function, at this time only need to insert a record, when the user login to complete. Also divide the content into another table.
------Solution--------------------
Relationship Number Sender recipient message number status
1 ID1 ID2 3 read/unread
This is a relational table, plus a message table, a user table.
In the station letter is generally a count of unread letters, select Count to get all the user unread letters of the number, within the tolerable limit of Ajax to the database to reduce the query pressure, can be a 120-second cache storage unread bar number, and then 20 seconds a pull, then the finished.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.