if the use of cache is one of Twitter's big points, the other aspect is its message queue. Why use Message Queuing? [14] The explanation is "isolate user requests and related operations so that the peak flow (move operations out of the synchronous request cycle, amortize load over time)".
in order to understand the meaning of this passage, may wish to look at an example. January 20, 2009 Tuesday, President Barack Obama took office and delivered his speech. As the first black president in American history, Obama's inauguration sparked a backlash that led to a surge in Twitter traffic, as shown in Figure 4.
Figure 4. Twitter burst during the inauguration of Barack Obama, 1/20/2009, Tuesday
At the peak of the
, Twitter received 350 new messages per second, a peak of about 5 minutes. According to statistics, the average Twitter user is "chased" by 120 people, that is to say, the average of 350 messages is sent 120 times [16]. This means that at this 5-minute peak, the Twitter site needs to send 120 = 42,000 messages per second.
face Flood Peak, how can we ensure that the site does not crash? The approach is to quickly accept, but postpone the service. For example, during the dinner rush, restaurants are often full. For new customers, the restaurant attendants are not shut out but let the customers wait in the lounge. This is what [14] says, "Isolating user requests and related operations in order to flatten traffic peaks".
How can quarantine be implemented? When a user visits the Twitter site, it is the Apache web Server that receives him. Apache does a very simple thing, it will be the user's request resolution, forward to mongrel Rails Sever, mongrel is responsible for the actual processing. and Apache Teng shot to meet the next user. This avoids the embarrassment of users not being connected to the Twitter site during the flood peak.
Although Apache's work is simple, it does not mean that Apache can host an unlimited number of users. The reason is that Apache resolves the user request, and after forwarding to the Mongrel server, the process that resolves the user request is not immediately released, but instead goes into an empty loop, waiting for the Mongrel server to return the results. In this way, the number of users that Apache can host at the same time, or more accurately, the number of concurrent connections that Apache can hold (concurrent 50x15), is actually subject to the number of processes that Apache can hold. Process mechanisms within the Apache system see Figure 5, where each worker represents a process.
How many concurrent connections can
Apache hold? [22] The experimental results are 4,000, see Figure 6. How can you improve the concurrent user capacity of Apache? One idea is to not let the connection be subject to the process. You might want to put the connection as a data structure, store it in memory, and release the process until the Mongrel server returns the result, then reload the data structure into the process.
in fact Yaws Web server[24], that's what it does [23]. So it's not surprising that Yaws can hold more than 80,000 concurrent connections. But why does Twitter use Apache instead of yaws? Perhaps because the Yaws is written in Erlang, and the Twitter engineer is unfamiliar with the new language (But you need into house Erlang experience [17]).
Source: (http://blog.sina.com.cn/s/blog_46d0a3930100fd5c.html)-Anatomy of Twitter "4" Floods need isolation _ Deng kan _ Sina blog
Figure 5. Apache Web Server System architecture [21]
Figure 6. Apache vs. Yaws. The horizonal axis shows the parallel requests, the vertical one shows the throughput (Kbytes/second). The red curve is yaws and running on NFS. The blue one is Apache, running on NFS while the "green one is" also Apache but on a local file system. Apache dies at the 4,000 parallel sessions, while the yaws is e.g. functioning in over 80,000 parallel. [22]
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.