Web Services processing, various I/O models are detailed,

Source: Internet
Author: User

One, process, thread?

A process is an entity of a program that has a certain independent function that is already running on the computer. Before linux2.4, the process is the basic operation of the Unit, in a thread-only system, the thread is the most basic unit of operation, and the process is only a thread of the container, the program itself is only instructions, data and the organization of the description of the process is the real running instance of the program. Several processes may be related in the same program, and each process can run independently or asynchronously. Modern computer systems can load multiple programs into storage at the same time in the form of processes and are shared by time to show the sensation of running simultaneously on a single processor, as well as the operating system or computer architecture using multithreaded technology (each line routine represents a separate execution context within a process). Parallel threads of the same program can actually run concurrently on a multi-CPU host or network.

Second, common Web service mode

    1. a process for Web request processing:

(1), the user initiates the request to the server network card;

(2), the server NIC received the request, transferred to the kernel processing;

(3), the kernel according to the request corresponding socket, the request to work in the user control of the Web server process;

(4), the Web server process according to the user request, to the kernel system calls, request access to the corresponding resources;

(5), the kernel discovers that the Web server process requests a resource that exists on the hard disk, and therefore connects the disk through the driver;

(6), the kernel dispatches the disk, obtains the necessary resources;

(7), the kernel stores the resources in its own buffer, and notifies the Web server process;

(8), the Web server process obtains the resources through the system call, and copies them into the process's own buffer;

(9), the Web server process to form a response, through the system call to the kernel to respond to their own user requests;

(10), the kernel will respond to the network card;

(11), the network card sends the response to the user;

To put it simply: User request--service user space--system call--kernel space--kernel-to-disk read Web page resources--Return to user space--respond to users.

2. Comparison of three working models:

Multi-process mode : For each request to start a process to handle, because in the operating system, the build process, the destruction process, inter-process switching is very CPU and memory, when the load is high, performance will be significantly reduced.

Pros: Stability! Stability is best because separate processes are used to handle geographic requests, and processes are independent, and individual process issues do not affect other processes

Cons: Occupy Resources! When the request is too large, a large number of processes are required to process the request, the process is generated, the switching overhead is high, and the inter-process resources are independent, resulting in memory reuse.

Multithreading : A process with multiple threads to process user requests, because the thread overhead is significantly less than the process, and some resources can also be shared, so the efficiency is high.

Pros: Less overhead! The thread portion of the data is shared, and the resource overhead required to switch between thread generation and thread is much smaller than switching between processes

Cons: Stability! Thread switching too quickly can cause thread jitter, and too many threads can cause server instability.

Async : Processing requests in a non-blocking manner is the least expensive in three ways, but although the asynchronous approach is efficient, the requirements are high, because scheduling between multiple tasks can have a total failure if a failure occurs, so using asynchronous work is generally a relatively simple function, However, it conforms to the server task schedule, and there is no program in the code that affects the dispatch error code.

Pros: Best Performance! A process or thread processes multiple requests, does not require additional overhead, performs best, and consumes the least resources.

Cons: Stability! An error in a process or thread can cause a large number of requests to be unhandled or even cause the entire server to go down.

Three, various I/O model detailed

Through a connection analysis, we know that the Web server process working in the user space is unable to directly manipulate I/O and needs to be done through system calls.

The process requests I/O to the kernel for system calls, the kernel dispatches the resources from IO to the kernel buffer (wait stage), and the kernel also needs to copy the data from the kernel buffer (copy phase) to the user space of the Web server process to complete the IO dispatch. These phases are time-based, and the I/O actions can be divided into the following v modes, depending on the processing wait mechanism in the wait and copy phases:

Blocking I/O: All processes are completely blocked

Non-blocking I/O: Returns immediately if there is no data buffer

I/O multiplexing (SELECT and poll): block separately in wait and copy stages (SELECT and poll)

Signal-driven I/O: not blocking in wait phase, but blocking during copy phase (signal-driven I/O, notification)

asynchronous I/O: Fully nonblocking mode provides a signal whenever I/O is complete

Blocking and non-blocking:

Blocking and non-blocking refers to whether an operation is performed until the end of the operation, or return immediately.

Blocking: Wait in the out-of-the-box until the chef finishes cooking and sends the dish to the window, then the waiter sends the dish to the user's hands.

Non-blocking: Wait a while to the window to ask the chef, a dish is good no, if not first deal with other things, and so will ask again;

Synchronous and asynchronous:

Synchronization and Asynchrony are another concept, which is a property of the event itself.

Waiter directly with the chef to deal with the dish out, the waiter direct guidance, but only when the chef will send the food to the waiter hand this process is normal completion, this is synchronous events, synchronization can only be blocked to do.

Some restaurants have a special food transfer staff, when the chef stir-fried dishes, the transfer of vegetables to the food transfer window, and inform the waiter, this becomes asynchronous. Async can also be divided into two types: notification and without notification. The front said that belongs to with the notice, some of the dishes may work initiative is not very good, will not be proactive notice you, you need to pay attention to the state, this is the asynchronous without notification. Asynchronous blocking and non-blocking are all possible. Non-blocking is divided into two ways: Active query and passive reception of messages, passive efficiency is higher, because the majority of the active query is doing a useless

Full asynchronous I/O:

Back I/O, whether I or O, access to peripherals (disks) can be divided into two stages of request and execution, the request is to look at the status of the peripheral information, execution is the real I/O operation


Web Services processing, various I/O models are detailed,

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.