1. Calculate the network throughput. Calculation reference formula: Concurrent connectionestablishedmin (serverkeepalive, servertimeout: the number of concurrent server transmission links divided by the minimum value between the keepalive setting of the server software and the timeout setting of the server software. The calculated value is keepaliv.
1. Calculate the network throughput.
Calculation reference formula:
Concurrency = connection establishEd/Min (server keepalive, serverTimeOut)
Translation:
Concurrency = the minimum value between the number of server transmission links divided by the keepalive setting of the server software and the timeout setting of the server software
The number calculated in this formula is the average value in the keepalive period, which is a little smaller than the actual average value. If you want to find the maximum value, you must set keepalive to 0 or 1, and then test it several times.
Connection established is the link currently being transmitted by the server. However, when keepalive is enabled, the new transmission link will always exist until keepalive/timeout closes the link; if the client closes the link, the connection established will also be closed. However, there are usually few such links. Most browsers support keepalive and comply with server configurations.
In linux, you can view the connection established number inCommandLine execution:
NetStat-Est |GrepConnections established |Cut-D c-f 1
How to view keepalive and timeout numbers to view the web server software configuration file
Note: This method can only be used for front-end servers or layer-7 switches. The front-end servers are often inaccurate due to cache or connection.
2. Use server log computing
Every time the server processes a request, it will leave a piece of information in the log. Therefore, it is most accurate to use the log of the server software. However, this calculation method may also be large, the maximum value is required.
First, make sure that the server software writes all requests to a log file and the log file is continuously recorded.
To save time and server resources, take out the last 10 thousand records of the log file for statistics. I will use the default main format of nginx as an example:
Run the following command:
Tail-10000 nginx. log | awk '{print $4;}' |Sort|Uniq-C
The command is to take the last 10 thousand records of the log file, and then use awk to obtain a column ($4) indicating the time in the log file, and then sort the column once, finally, uniq is used to merge adjacent duplicate rows in the column and calculate the number of merged rows.
Among them, sort and uniq are a safe method to ensure that logs in the same second are first merged and then merged, in this way, logs of the same second will not be cut into several segments.
The output is as follows:
23 [09/Sep/2008: 20: 26: 02
26 [09/Sep/2008: 20: 26: 03
17 [09/Sep/2008: 20: 26: 04
20 [09/Sep/2008: 20: 26: 05
...
70 [09/Sep/2008: 20: 29: 43
61 [09/Sep/2008: 20: 29: 44
45 [09/Sep/2008: 20: 29: 45
37 [09/Sep/2008: 20: 29: 46
2 [09/Sep/2008: 20: 29: 47
In these outputs, the first and last records are completely unreliable because time may be cut off.
If the output is less than 10 rows, expand the range and change tail-10000 to tail-100000 to get the last 100,000 rows of data statistics.
If you only need to view the maximum value, you can use the sort command to sort and use the head command to retrieve the first 10 rows of records:
Tail-10000 nginx. log | awk '{print $4;}' | sort | uniq-c | sort-nr | head
The awk command is a powerful command. Here we only use the simplest awk '{print $4;}', which means to split each line of logs by space, then the cut result is $1 $2 $3 from left to right ..., the default main log time field of nginx is $4, so $4 is used here. For logs of other formats, find the number of columns according to this method:
Take the default apache log as an example:
Head-1 apache. log
The output is similar to the following:
60.8.207.86-[09/Sep/2008: 21: 03: 58 + 0800] GET/HTTP/1.0 200 11141 http: // www.SuDone.com Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
After awk is split by space, 60.8.207.86 means $1, $2 and $3 are both-, and [09/Sep/2008: 21: 03: 58 is $4, this requires statistics. Well, how does apache have the same log as nginx? Only now.
The command is basically unchanged. Run the following command:
Tail-10000 apache. log | awk '{print $4;}' | sort | uniq-c | sort-nr | head
Note:IdFor apache after the server, the log will become like this:
60.8.207.86, 127.0.0.1--[09/Sep/2008: 21: 03: 58 + 0800] GET/HTTP/1.0 200 11141 http://www.sudone.com Mozilla/4.0 (compatible; MSIE 6.0; windows NT 5.1; SV1)
Because the first segment of the log: x_forwarded_for contains spaces, the time segment changes between $3, $4, and $5, and thus cannot be determined, you can use an awk or cut to split it with the [Symbol:
Tail-10000 apache. log | awk-F ['{print $2;}' | awk '{print $1;}' | sort | uniq-c | sort-nr | head
Or
Tail-10000 apache. log | cut-d [-f 2 | awk '{print $1;}' | sort | uniq-c | sort-nr | head
In this way, the statistics are accurate.