Home > Mobile >  How to improve the ability of handling concurrency server (collection)
How to improve the ability of handling concurrency server (collection)

Time:09-25

What is the server concurrent processing capacity
A server can handle in unit time request, the more the higher the capacity of the server, or server concurrent processing ability stronger
What method to measure the server concurrent processing capacity
1. The throughput rate
Server processing throughput rate, the unit of time the maximum number of requests, the req/s
2. Pressure test
There is a principle must be clear first, if 100 users separately 10 requests to the server at the same time, with one user to the server requests for 1000 times in a row, pressure on the server is the same? Is actually not the same, for each user, continuous sends the request is actually refers to send a request and receive the response data before sending a request, so for a user to the server requests for 1000 times in a row, at any time the server nic only one request in the receive buffer, with 100 users separately 10 requests to the server at the same time, the server nic receive buffer up to 100 requests, waiting to be processed clearly at this moment the server pressure is bigger,
Stress tests about time and subdivided the following two kinds:
User average request latency (here temporarily not put the data in the network transmission time, and the user PC computing in the calculation of local time) in general, the average user request the average waiting time=server processing time * number of concurrent users
Server average request processing time
How to improve the concurrent processing ability of server
1. Improve the ability of CPU parallel computing
The server can handle multiple requests, at the same time lies in the design of the operating system through multiple execution flow system allows multiple tasks to take turns using system resources, these resources include CPU, memory and I/o. the I/O here mainly refers to the disk I/O, and network I/O,
2. Consider reducing memory allocation and release
Server in the process of the work, need a lot of memory, the memory allocation and release work is particularly important,
Apache, for example, at the beginning of running an application for large memory as memory pool, and if necessary then directly obtained in the memory pool, do not need to allocate, avoid the frequent memory allocation and release of memory consolidation time,
Again like Nginx using multiple threads to handle requests, that can be Shared between multiple threads memory resources, thus reduce its overall memory usage greatly, in addition, Nginx phase memory allocation strategy, to each according to his need, timely release, making the number of memory usage in a small scope,
3. Consider using a persistent connection
Persistent connections are long connection, it itself is a common way of TCP communications, which continue to send in a TCP connection points data and continuous connection, under the permission, the less connection times, more conducive to improve the performance of; Especially for intensive images or pages such as small data request processing has obvious acceleration,
HTTP Connection to the browser and the web server work together, the current browser supports long Connection generally, in the HTTP request header contains data about long Connection statement, as follows: the Connection: Keep Alive -
Mainstream web server support long connection, such as apache, you can use long KeepAlive off close connection,
Apache's default Settings for the 5 s, if the set time is too long, may lead to invalid resource possession, to maintain a large number of idle process, affect server performance,
4. Improve the I/O model
I/O operations according to the different divided into many types of equipment, such as memory I/O and network I/O, disk I/o. for network I/O and disk I/O, the speed is much slower, although use RAID disk array can through parallel disk disk to speed up the disk I/O, buy dalian exclusive network bandwidth and the use of high bandwidth network adapter can improve the speed of network I/O, but these I/O operations need kernel system calls to complete, these need the CPU to scheduling, this makes the CPU has to waste precious time to wait for slow I/O operations, we wanted the CPU enough little time on the scheduling of I/O operations, how to make high-speed CPU and slow I/O device to better coordinate work, is one of the topics being discussed modern computer, a variety of I/O model is the essential difference between CPU participation way,
1. The DMA technology
Asynchronous I/O
2.3. I/O multiplexing
4. The Sendfile
5. The memory mapping
6. Direct I/O

5. Improve server concurrency strategy
Server concurrency strategy, the purpose of is to get the I/O operations and CPU overlap as far as possible, on the one hand, let the CPU when the I/O wait don't idle, on the other hand to let the CPU on the I/O scheduling to spend the least amount of time as far as possible,
A process to deal with a connection, non-blocking I/O
That will have multiple concurrent requests when they arrive at the same time, the server must prepare multiple processes to handle the request, the process of overhead restricts the number of simultaneous connections, but from the perspective of stability and compatibility, is its relative safety, the collapse of any child process will not affect the server itself, you can create a new child processes; That strategy is the fork and the typical example is the Apache prefork mode, for concurrency is not high (e.g., 150) within the site at the same time rely on the choice of application in the Apache other function Apache or can be,
A thread to handle a connection, a non-blocking IO
This way allows through multiple threads in a process to handle multiple connections, a thread with a connection, Apache worker model is the typical example, makes it can support more concurrent connections, but this model's overall performance is not as good as prefork, so generally do not choose the worker pattern,
A process to deal with multiple connections, asynchronous I/O
A thread to handle multiple connections at the same time, the potential premise condition is to use the IO multiplexing ready notice,
The process of this case, will handle multiple connections called worker processes or service process, the number of worker can be configured, such as in Nginx worker_processes 4,
A thread to handle multiple connections, asynchronous I/o
Even with high performance I/o multiplexing ready notice, but still cannot avoid disk IO wait, more efficient way is to use asynchronous I/o disk file, at present there are few Web server supports the asynchronous I/o on real significance,
6. Improving the hardware environment
At present about so many first, later have other aspects on the server can communicate together!
  • Related