View the number of Apache concurrent requests and their TCP connection status in Linux

Source: Internet
Author: User
View the number of httpd processes (that is, the number of concurrent requests that Apache can process in prefork mode): Linux command: ps-ef | grephttpd | wc-l return result example: 1388 indicates that Apache can process 1388 concurrent requests. The value of Apache can be based on the load...
View the number of httpd processes (that is, the number of concurrent requests that Apache can process in prefork mode): Linux command: ps-ef | grep httpd | wc-l return result example: 1388 indicates that Apache can process 1388 concurrent requests. this value is automatically adjusted based on the load. the peak value of each server in my group has reached 2002. View the number of concurrent Apache requests and their TCP connection status: Linux command: www.2cto.com netstat-n | awk '/^ tcp/{++ S [$ NF]} END {for (a in S) print, S [a]} 'return result example: LAST_ACK 5 SYN_RECV 30 ESTABLISHED 1597 FIN_WAIT1 51 FIN_WAIT2 504 TIME_WAIT 1057 where SYN_RECV indicates the number of requests awaiting processing; ESTABLISHED indicates normal data transmission status; TIME_WAIT indicates the number of requests that have been processed and wait for the timeout to end. How can I reasonably set the maximum number of connections for apache httpd? The number of online users of a website increases, and the access time is slow. It is initially considered that the server resources are insufficient, but after repeated tests, once connected, you can quickly open it by constantly clicking different links on the same page, this phenomenon means that the maximum number of connections in apache is full, and new visitors can only wait in queue for idle connections. if the connection is established, the default value is 5 seconds). you do not need to re-open the connection. Therefore, the solution is to increase the maximum number of connections of apache. 1. Where can I set it? The server is FreeBSD 6.2, apache 2.24, and uses the default configuration (FreeBSD does not load the custom MPM configuration by default). The default maximum number of connections is 250 at/usr/local/etc/apache22/httpd. load the MPM configuration in conf (remove the preceding note): # Server-pool management (MPM specific) include etc/apache22/extra/httpd-mpm.conf visible MPM configuration in/usr/local/etc/apache22/extra/httpd-mpm.conf, but inside according to the httpd working mode divided a lot of blocks, which one is the current httpd working mode? You can run apachectl-l to view: Compiled in modules: www.2cto.com core. c prefork. c http_core.c mod_so.c can see the prefork word. Therefore, the current httpd should work in the prefork mode. the default configuration of the prefork mode is: StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 0 2. how much does it add? Theoretically, the larger the number of connections is, the better, but it must be within the capacity range of the server. this is related to the CPU, memory, bandwidth, and so on of the server. To view the number of connections, you can use: ps aux | grep httpd | wc-l or: pgrep httpd | wc-l to calculate the average memory usage of httpd: ps aux | grep-v grep | awk '/httpd/{sum + = $6; n ++}; END {print sum/n}' because basically all pages are static pages, CPU consumption is very low, and the memory occupied by each process is not much, about 200 KB. The server memory is 2 GB, and about 500 MB (conservatively estimated) is required except for services started normally. GB is available, theoretically, 1.5*1024*1024*1024/200000*8053.06368 = www.2cto.com can be supported for about 8 K processes. it is no problem to support concurrent accesses (ensure that 8 k of them can access the website quickly, others may take 1 or 2 seconds to connect, but once connected, it will be smooth) MaxClients that controls the maximum number of connections, so you can try to configure it: StartServers 5 MinSpareServers 5 MaxSpareServers 10 ServerLimit 5500 MaxClients 5000 MaxRequestsPerChild 100 Note: the maximum value of MaxClients is 250 by default. to exceed this value, you must explicitly set ServerLimit, and put ServerLimit before MaxClients. The value must not be smaller than that of MaxClients. Otherwise, a prompt will appear when you restart httpd. After restarting httpd, run pgrep httpd | wc-l repeatedly to check the number of connections. you can see that the number of connections does not increase after the value of MaxClients is reached, but the website access is smooth at this time, you don't need to be greedy and set a higher value. Otherwise, the server memory will be consumed if the website access suddenly increases. you can adjust the memory usage according to the future access pressure trend and memory usage changes, until an optimal setting value is found. (MaxRequestsPerChild cannot be set to 0, and the server may crash due to memory leakage.) formula for optimal maximum value calculation: www.2cto.com memory <(total_hardware_memory/memory) * 2apache_max_process = memory * 1.5 attached: number of HTTPD connections detected in real time: watch-n 1-d "pgrep httpd | wc-l" author yangemil
Related Article

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.