Application of Online Status Service in Website System

My previous blog article “Talk about Facebook’s chat system architecture”, analyzed Facebook’s chat system architecture. Some ideas and systems are divided, and they are also very for even not to do chat systems, such as general website systems There is a reference. For example, the online status server (Presence).

Online status service, this is a service that maintains the current online user list of the website, accepts the query of other modules. It is a basic service that implements the statistics website at the same time, maintaining online user lists, etc. In Facebook’s chat system The online state is serving the chat system, so the online state is a “strong” online, that is, the user holds a connection with the Comet server, which can accept the server to push (PUSH) message.

But in a general website application, it is not required to be strong online. The server sends a heartbeat package.

For a website at the same time, 1 billion PV website, the newly received heartbeat is approximately 1 billion, i.e., 10,000 requests per second. To achieve such an online state The server is also a challenge.

The most common implementation is the method of PHP + MySQL. The server inserts a user online record when receiving the heartbeat package, or updates the time field of this record, and then there is a timing to clean up the timeout user. This. MYSQL is easy to become bottlenecks.

So, the second method appeared, that is, replacing MySQL to Redis. However, the loss of PHP itself is also very large, and the performance of a single server reaches 10,000 QPS is almost impossible.

A further plan is to develop a dedicated HTTP server with C / C ++, fully integrate logic processing (such as PHP) and storage (REDIS). Because this is a dedicated HTTP server, you can only support a finite subset of HTTP protocols, It can be done with ready-made libraries such as libevent. Libevent also provides a network framework. The storage section can design a good high-speed memory data structure, which should be higher than the reic performance, because Redis is universal storage, performance will have some loss According to the capacity of REDIS 30000 to 50000 QPS, such a C / C ++ memory logic server should easily reach a single server processing speed 1000QPS, which is 10 billion requests per day.

Look at my blog students, if you can make such a server, welcome to send me the Github address, everyone exchanges.