View the maximum number of connections of nginx

View the maximum number of connections of nginx

(1) The parameter that controls the maximum number of connections allowed by a single Nginx process is worker_connections , which should be adjusted according to server performance and memory usage

(2) The maximum number of connections of a process is limited by the maximum number of open files of a Linux system process. Only after executing “ulimit -HSn 65535” can worker_connections take effect

cat /proc/sys/fs/file-max View the system-level maximum limit
ulimit -n View user-level limits
(3) The number of connections includes proxy server connections, client connections, etc. The total number of concurrent connections of Nginx = number of workers * worker_connections

The number of workers: worker_process, preferably consistent with the number of CPU cores, not greater than the number of CPU cores.

worker_connections: the maximum number of concurrent connections for a single process

View the number of concurrent connections of nginx
By checking the concurrent connections of Nginx, we can know the load of the website more clearly. There are two ways to view Nginx concurrently (the reason why I say this is because the author only knows two), one is through the web interface, and the other is through commands. The web view is more accurate than the results displayed by the command view. The two viewing methods are described below

No1, view through browser
When viewing through the web interface, Nginx needs to enable the status module, that is, add –with-http_stub_status_module when installing Nginx, then configure Nginx.conf, and add the following content to the server point

location /status {
stub_status on;
access_log /usr/local/nginx/logs/status.log;
auth_basic “NginxStatus”; }

After restarting Nginx after configuration, we can visit http://localhost/status through the browser to view

Active connections //The number of active connections currently being processed by Nginx.
server accepts handledrequests //A total of 8 connections have been processed, 8 handshakes have been successfully created, and a total of 500 requests have been processed.
Reading //nginx reads the number of Header information from the client.
Writing //Nginx returns the number of Header information to the client.
Waiting //When keep-alive is turned on, this value is equal to active – (reading + writing), which means that Nginx has finished processing the resident connection that is waiting for the next request command

No2, View by command
#netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’

FIN_WAIT_1 648
FIN_WAIT_2 581

CLOSED // No connection is active or in progress
LISTEN //The server is waiting for an incoming call
SYN_RECV //A connection request has arrived, waiting for confirmation
SYN_SENT //The application has started, open a connection
ESTABLISHED //Normal data transmission status/current number of concurrent connections
FIN_WAIT1 // app says it’s done
FIN_WAIT2 //The other side has agreed to release
ITMED_WAIT //Wait for all groups to die
CLOSING // both sides try to close at the same time
TIME_WAIT //The other side has initialized a release
LAST_ACK //wait for all packets to die

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.