Read building a high-performance Web site server concurrency processing power-1

Source: Internet
Author: User
Tags posix

The more requests a Web server can handle per unit of time, the better it becomes the ability of the Web server, which embodies what we often call "server concurrency processing power."

Throughput

The concurrent processing ability of Web server, generally use the number of requests processed by the server in unit time to describe its concurrency capability, it is customary to call it throughput rate (throughput), the unit is "REQS/S".

    • Number of concurrent users

People often confuse the number of concurrent users and throughput, in fact, they are not the same, the throughput rate refers to a certain number of concurrent users in the case of the server processing request capacity of the quantitative embodiment; the number of concurrent users is the total number of users who send requests to the server at a time.

Multi-threaded concurrency for the same domain name URLs under the maximum number of concurrent downloads, the specific restrictions vary depending on the browser, for example, under http/1.1, IE7 support two concurrent connections, IE8 support 6 concurrent connections, FIREFOX3 support 4 concurrent connections. On the other hand, Web servers generally limit the maximum number of concurrent services, such as the maxclients parameter of Apache.

CPU Concurrency Calculation

The server can process a request at the same time, the operating system through the multi-execution flow system design so that multiple tasks can take turns using system resources, including CPU, memory and I/O and so on.

Process

The general implementation of a multi-execution flow is a process.

Process scheduling has a kernel, and from the kernel point of view, the purpose of the process is to assume the entity that allocates system resources. At the same time, a process can also be understood as the amount of data that a logger instance is currently running to, and multiple processes are associated with these data processes through different process descriptors.

Each process has its own independent memory address and life cycle. The process is created using the fork () system call.

Lightweight process

Data cannot be shared because the processes are relatively independent. For this reason, after Linux2.0, it provides support for lightweight processes, which are created by a new system called Clone () and managed directly by the kernel, exist independently as normal processes, and each own a process descriptor, but these processes have allowed some resources to be shared.

Lightweight processes reduce the overhead of memory and provide direct support for data sharing for multi-process applications.

Thread

The POSIX 1003.1c defines a ready-made interface "Pthread" for Linux. From the kernel point of view, multithreading is just a normal process, it is by the user state through a number of library functions to simulate the implementation of multi-execution flow, so the management of the more ready-to-use complete in the user state. This implementation is less expensive than process and lightweight processes, but it behaves poorly on multiprocessor servers (SMP) because only the kernel's process scheduler is authorized to allocate more than one CPU time.

Another of the POSIX threads is the real linuxthreads, which can be said to be a kernel-level thread (Kernel-level Threads), because it creates threads through Clone (), that is, it is implemented by associating threads with lightweight processes Each thread is actually a lightweight process, so that the thread is managed entirely by the kernel's process scheduler, so his support for SMP is better, but thread switching costs more than a user-configured thread.

Linuxthreads has joined the current version of GLIBC and libc.

Process Scheduler

The Process Scheduler (Scheduler) in the kernel maintains process queues in various states. In Linux, the process Scheduler maintainer is a queue that contains all the running processes, called the "Run Queue", a set of a list that includes all the dormant processes and zombie processes.

One of the important tasks of the process scheduler is to determine the next running process, which is processed by the process priority, which is determined by the process itself, but the process scheduler dynamically adjusts their priority as the process runs.

The priority attribute of the process in Linux is precedence, which is represented in the top result, while the dynamic adjustment for the process is reflected in the nice properties of the process, which is expressed in the top result with NI.

650) this.width=650; "Src=" http://misc.zhangsr.cn/resources/img/blog/attachment/201504/1_20150420090229.jpg " Style= "Font-family:simsun;font-size:medium;white-space:normal;background-color:rgb (255,255,255);" Alt= "1_ 20150420090229.jpg "/>

PR represents the process scheduler allocated to the process of the length of the clock, the number of clocks, how long a clock needs to be associated with the CPU frequency and operating system platform, such as Linux generally 10ms, then the PR value of 20 indicates that the process time is 200ms.

The Linxu2.6 process Scheduler prefers I/o-intensive processes because these processes usually block (in addition to asynchronous I/O) after initiating I/O operations and do not consume too much CPU time.

System load

At any time through the/PROC/LOADAVG, you can view the system running queue situation.

650) this.width=650; "Src=" http://misc.zhangsr.cn/resources/img/blog/attachment/201504/1_20150420132734.jpg " Style= "Font-family:simsun;font-size:medium;white-space:normal;background-color:rgb (255,255,255);" Alt= "1_ 20150420132734.jpg "/>

6/1564, 6 indicates the number of processes in the test run queue, and 1564 represents the total number of processes at this time. The rightmost 25689 represents the last process ID created by this point. The left 0.24, 0.52, 0.58 three values represent the system load for the last 1 minutes, 5 minutes, and 15 minutes, respectively.

The system load is the average of the processes in the queue that are ready to wait in a unit of time, and the higher the system load, the busier the CPU is.

Process switching

In order for all processes to use system resources in turn, the process scheduler suspends the running process when necessary, and restores a previously suspended process, which is called process switching, or "context."

The essence of a process being suspended is to take its data out of the CPU registers in the kernel stack, and the essence of a process recovery is to reload its data into the CPU register.

Nmon is a Linux monitoring tool that can provide monitoring pages based on server terminal commands. The sampling results for a server at a time using Nmon are as follows:

650) this.width=650; "Src=" http://misc.zhangsr.cn/resources/img/blog/attachment/201504/1_20150420134200.jpg " Style= "Font-family:simsun;font-size:medium;white-space:normal;background-color:rgb (255,255,255);" Alt= "1_ 20150420134200.jpg "/>

Contextswitch indicates that the context switch is now averaging 12614.9 times per second, which is the necessary work for the operating system to function properly.

Iowait

Iowait is the percentage of time that the CPU is idle and waiting for the I/O operation to complete. Iowait often does not represent the performance of I/O operations, and it is designed to measure CPU performance.

650) this.width=650; "Src=" http://misc.zhangsr.cn/resources/img/blog/attachment/201504/1_20150420142106.jpg " Style= "Font-family:simsun;font-size:medium;white-space:normal;background-color:rgb (255,255,255);" Alt= "1_ 20150420142106.jpg "/>

When the iowait is high, the CPU time of the current task is less than the I/O operation time, and the CPU monitoring data is obtained by Nmon as follows:

650) this.width=650; "Src=" http://misc.zhangsr.cn/resources/img/blog/attachment/201504/1_20150420142300.jpg " Style= "Font-family:simsun;font-size:medium;white-space:normal;background-color:rgb (255,255,255);" Alt= "1_ 20150420142300.jpg "/>

At this point the iowait is 0% and the system is not busy.


—————————— This article is published synchronously in ZHANGSR my personal blog ——————————

Read building a high-performance Web site server concurrency processing power-1

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.