Linux view number of connections, number of concurrent

Source: Internet
Author: User

Linux view number of connections, number of concurrent Blog Category:
    • Xiao Kee
Linux

Soft connection

BAT Code
    1. Ln-s/home/ictfmcg/data/photo/var/jtnd/data/photo



The connector configuration for Tomcat 6 is as follows

XML code
  1. <Connector port="8080" protocol="http/1.1 "
  2. connectiontimeout="20000"
  3. redirectport="8443"
  4. maxthreads= "acceptcount=" />




The last two parameters have the following meanings:

Maxthreads:tomcat the maximum number of threads to start, that is, the number of simultaneous tasks, with a default value of 200

Acceptcount: When the number of threads started by Tomcat reaches maximum, the number of requests queued is accepted, the default value is 100



How these two values work, see the following three scenarios

Scenario 1: Accept a request when the number of threads that Tomcat started does not arrive maxthreads,tomcat will start a thread to process the request.

Case 2: Accept a request, at which time the number of threads that Tomcat started has reached Maxthreads,tomcat will put this request into the waiting queue, waiting for the idle thread.

Scenario 3: When a request is accepted, the number of threads that Tomcat started has reached MaxThreads, and the number of requests waiting in the queue has reached Acceptcount, and Tomcat rejects the request directly, returning connection refused

MaxThreads How to configure

General server operations include volume aspects: 1 calculation (mainly CPU consumption), 2 waits (IO, database, etc.)

In the first extreme case, if our operation is purely computational, then the main limitation of the system response time is the computing ability of the CPU, at this time maxthreads should be set as small as possible, reduce the number of threads competing for CPU at the same time, can improve the calculation efficiency, improve the overall processing capacity of the system.

In the second extreme case, if our operation is purely IO or database, then the main limitation of response time becomes waiting for external resources, when the maxthreads should be set as large as possible, so as to improve the number of simultaneous processing requests, thus improving the overall processing capacity of the system. In this case, because Tomcat is processing more requests at the same time, you need to focus on Tomcat's virtual machine memory settings and Linux open file restrictions.

I encountered a problem in the test, maxthreads I set the relatively large, such as 3000, when the number of threads of service is large to a certain extent, usually in the early 2000, the response time of a single request will increase sharply,

Best of all, this is why, looking around for the answer is not the result, I conclude that the reason may be that the CPU thread switching time consumption as the number of threads increases more and more large,

The CPU uses most of the time to switch directly over the 2000 + threads, and of course the CPU has no time to process our programs.

Previously it has been simple to think multithreading = high efficiency. In fact, multithreading itself does not improve CPU efficiency, but too many threads will reduce CPU efficiency.

When the number of CPU cores < threads, the CPU needs to switch back and forth on multiple threads directly to ensure that each thread gets CPU time, which is what we usually call concurrent execution.

So the MaxThreads configuration is definitely not as big as the better.

In real-world applications, our operations will contain the above two types (calculation, wait), so the MaxThreads configuration does not have an optimal value, it must be configured according to the specific situation.

The best practice is: on the basis of continuous testing, continuous adjustment, optimization, to get the most reasonable configuration.

Acceptcount configuration, I generally set the same size as maxthreads, this value should be mainly based on the application's access peaks and averages to weigh the configuration.

If set to a smaller size, you can guarantee that the accepted request will be faster, but the exceeding request may be rejected directly

If the set is large, there may be a large number of request timeouts, because the processing power of our system is certain.
1. View the current number of concurrent accesses to Apache: www.2cto.com
  

BAT Code
    1. Netstat-an | grep established | Wc-l

  
Compare the number of maxclients in httpd.conf.
  
2. How many processes are viewed:
  

BAT Code
    1. PS Aux|grep httpd|wc-l


  
3, you can use the following parameters to view the data
Server-status?auto
  

BAT Code
    1. #ps-ef|grep Httpd|wc-l


1388
Count the number of httpd processes, and a single request initiates a process that is used for the Apache server.
Indicates that Apache can handle 1388 concurrent requests, which Apache can automatically adjust according to the load situation.
  

BAT Code
    1. #netstat-nat|grep-i "|wc-l "


4341
Netstat-an will print the current network link state of the system, while Grep-i "80" is used to extract connections related to port 80, wc-l the number of connections counted. Www.2cto.com
The final number returned is the total number of requests for all 80 ports currently.
  

BAT Code
    1. #netstat-na|grep Established|wc-l


376
Netstat-an Prints the current network link state of the system, and grep established extracts information about the established connection. Then wc-l statistics.
The final number returned is the total number of established connections for all current 80 ports.
  

BAT Code
    1. netstat-nat| | grep ESTABLISHED|WC


-View detailed records of all established connections

To view the number of concurrent requests for Apache and its TCP connection status:
Linux commands:
  

BAT Code
    1. Netstat-n | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, S[a]} '


Examples of returned results:
Last_ack 5
SYN_RECV 30
Established 1597
Fin_wait1 51
Fin_wait2 504
Time_wait 1057
One of the
SYN_RECV indicates the number of requests waiting to be processed;
Established indicates the normal data transmission status;
Time_wait indicates the number of requests that have finished processing and waiting for the timeout to expire. (This parameter is not quite understand, why is waiting for the end of the timeout, please teach the great God)

Linux view number of connections, number of concurrent

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.