View the tcp method of the Process in apache, and view the tcp method of the Process in apache

Source: Internet
Author: User

View the tcp method of the Process in apache, and view the tcp method of the Process in apache
The following are the running Modes of apache: view the running mode of apache and view the commands:

httpd -lCompiled in modules:core.cprefork.chttp_core.cmod_so.c
View the running mode of apache
Httpd-M | grep prefork # This is the running mode
View the number of apache configuration processes
Cat/usr/local/apache2/conf/extra/httpd-mpm.conf # Configuration
 
  
ServerLimit 1024 # maximum number of processes on the apache server (see MaxClients for details) startServers 10 # Number of processes started by default at apache startup MinSpareServers 10 # minimum number of idle processes MaxSpareServers 30 # maximum number of idle processes MaxClients 1024 # maximum number of processes on the client MaxRequestsPerChild 300 # Processing of each process maximum number of requests
 
View tcp connections

Count port 80 connections

netstat -nat|grep -i "80"|wc -l

Netstat-an prints the current network connection status of the system, while grep-I "80" is used to extract connections related to port 80. wc-l is used to calculate the number of connections. The final number returned is the total number of requests on all port 80.

Count the number of httpd protocol connections or processes
ps -ef|grep httpd|wc -l
View the current number of concurrent apache workers:
netstat -an | grep ESTABLISHED | wc -l
View the number of concurrent Apache requests and their TCP connection status: Linux Command:
Netstat-n | awk '/^ tcp/{++ S [$ NF]} END {for (a in S) print, S [a]} 'time _ WAIT 8947 WAIT for enough TIME to ensure that the remote TCP receives the confirmation of the connection interruption request. FIN_WAIT1 15 waits for the remote TCP connection interruption request, or the previous connection interruption request confirmation FIN_WAIT2 1 from remote TCP wait connection interruption request ESTABLISHED 55 represents an open connection SYN_RECV 21 then receives and sends a connection request and waits for the other party to request the connection confirm CLOSING 2 no connection status LAST_ACK 4 wait for confirmation of the original connection interruption request sent to remote TCP

SYN_RECV indicates the number of requests waiting for processing, ESTABLISHED indicates the normal data transmission status, and TIME_WAIT indicates the number of requests waiting for timeout.

TCP connection status

In TCP/IP, TCP provides reliable connection services and uses three handshakes to establish a connection.

First handshake: when a connection is established, the client sends the syn Packet (syn = j) to the server and enters the SYN_SEND status. Wait for the server to confirm;

The second handshake: when the server receives the syn packet, it must confirm the customer's SYN (ack = j + 1) and send a SYN Packet (syn = k), that is, the SYN + ACK packet, the server enters the SYN_RECV status;

The third handshake: the client receives the server's SYN + ACK package and sends the ACK (ack = k + 1) Confirmation package to the server. After the package is sent, the client and server enter the ESTABLISHED status, complete three handshakes.

Client TCP status migration: CLOSED-> SYN_SENT-> ESTABLISHED-> FIN_WAIT_1-> FIN_WAIT_2-> TIME_WAIT-> CLOSED

Server TCP status migration:

CLOSED-> LISTEN-> SYN_RECEIVE-> ESTABLISHED-> CLOSE_WAIT-> LAST_ACK-> CLOSED

Apache process count Optimization

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.

1. view the current number of connections:
ps aux | grep httpd | wc -l
Calculate the average memory usage of httpd:
ps aux|grep -v grep|awk '/httpd/{sum+=$6;n++};END{print sum/n}'

Because the pages are basically static pages, CPU consumption is very low, and the memory occupied by each process is not much, about 200 K.

The server memory is 2 GB, and about 500 mb (conservatively estimated) is required except for services started normally. The remaining 1.5 GB is available, so theoretically is supported.10241024*1024/200000 = 8053.06368

There are about 8 K processes, and it should be no problem to Support 2 W simultaneous access (8 K of them can be accessed quickly, and other processes may need to wait 1 or 2 seconds to connect, and it will be smooth once connected)

To control the MaxClients of the maximum number of connections, you can configure it as follows:
 
                  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.

Note: I personally learn and understand things. If you have any questions, please point out thank you!

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.