Set the correct number of threads

Source: Internet
Author: User
Tags website performance

High-performance server architecture
I searched for Seda and found this article "Analysis and Simulation of Seda performance optimization ".
For the number of threads. For a Web request, the code execution time is St (service time), and the IO wait time for reading files and network calls is wt (wait time ), if the number of CPUs is n and the number of cores is m, the number of threads Tc (thread count) is:

 

TC = N * m * (1 + WT/ST)

 

If there is only one single-core CPU, if the IO is 40 ms and the program execution takes 20 ms, the following execution sequence can be obtained.

Request1 is executed for 20 milliseconds and waits for 40 milliseconds. In this case, the CPU is idle.

Request2 then runs for 20 milliseconds and waits for 40 milliseconds. At this time, request1 still needs to wait for 20 milliseconds.

Request3 then runs for 20 milliseconds and waits for 40 milliseconds. At this time, request2 still needs to wait for 20 milliseconds, and request1 has been executed.

Request4 can reuse the request1 thread.

According to this formula, if one single-core CPU exists in the following three application scenarios:

S1: St = 10 wt = 0 Tc = 1

S2: St = 10 wt = 50 Tc = 6

S3: St = 10 wt = 100 Tc = 11

S1 is purely computation with no I/O and only consumes the CPU; S2 is access to local files, with disk I/O; S3 is a database call with network I/O.

If S1 accounts for 10% of the total number of requests, S2 accounts for 20%, and S3 accounts for 70%, what is the TC? If the percentage is per

 

TC = N * m * (1 + (WT1 * Per1 + WT2 * per2... WTN * Pern)/(ST1 * Per1 + st2 * per2... STN * Pern ))


That is
Total wait time/total execution time

In the preceding scenario, the formula is as follows:

TC = 1*1*(1 + 80/10) = 9

That is to say, it is appropriate to set nine threads. Correctly estimate each scenario and obtain data for each scenario. By analyzing the ratio of each scenario, we can calculate the theoretical value of the number of threads. Of course, we also need to measure three CPU indicators based on stress testing: CPU utilization, load average, and context switch rate.
.

 

For details about SEDA, study it later.


========================================================== ========================================

Performance-related articles:

LoadRunner uses ODBC to write MySQL scripts

Monitors the Linux resources of the server during stress testing of LoadRunner.

The stress test measures three CPU indicators: CPU utilization, load average, and context switch rate.

High-performance server architecture)

Conversion from PV to TPS and TPS fluctuation in website performance tests

Use gtmetrix to optimize your webpage (Integrating yslow and firebug functions)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.