Linux Nineth Week Micro jobs

Source: Internet
Author: User

1, please describe a complete HTTP request processing process;

The HTTP communication mechanism is that during a complete HTTP communication, the following 7 steps will be completed between the Web browser and the Web server:

  1. Establish a TCP connection

    Before HTTP work begins, the Web browser first establishes a connection to the Web server over the network, which is done through TCP, which works with the IP protocol to build the Internet, known as the TCP/IP protocol family, so the internet is also known as a TCP/IP network. HTTP is a higher level of application layer protocol than TCP, according to the rules, only the lower layer protocol is established before higher-level protocol connections, so first to establish a TCP connection, the port number of the general TCP connection is 80;

  2. Web browser sends request command to Web server  

    Once a TCP connection is established, the Web browser sends a request command to the Web server. For example: get/sample/hello.jsp http/1.1;
  3. Web browser sends request header information

    After the browser sends its request command, it also sends some other information to the Web server in the form of header information, and then the browser sends a blank line to notify the server that it has ended sending the header information.
  4. Web server Answer

    After the client makes a request to the server, the server will reply back to the client, http/1.1 the first part of the answer is the version number of the protocol and the response status code;
  5. Web server sends answer header information

    Just as the client sends information about itself along with the request, the server also sends the user its own data and the requested document with the answer;

  6. Web server sends data to browser

    After the Web server sends the header information to the browser, it sends a blank line to indicate that the header information is sent to this end, and then it sends the actual data requested by the user in the format described in the Content-type reply header information;
  7. Web server shuts down TCP connection

In general, once the Web server sends the request data to the browser, it closes the TCP connection, and then if the browser or server joins this line of code in its header information: connection:keep-alive;

The TCP connection remains open after it is sent, so the browser can continue to send requests through the same connection. Maintaining a connection saves the time it takes to establish a new connection for each request and also saves network bandwidth.

2. What are the processing models supported by HTTPD, and what environments are they used for?

Apache has two working models, a process-based Preforker model and a worker model based on thread-and process-blending.

1) prefork mode

Prefork mode can be considered an old but very stable Apache model. When Apache starts, it will fork some sub-processes in advance and wait for the request to come in. This is done to reduce the overhead of frequently creating and destroying processes. Each child process has only one thread, and within a single point in time, only one request can be processed;

Advantages: Mature and stable, compatible with all new and old modules. At the same time, there is no need to worry about thread safety. (The expansion of our common mod_php,php does not need to support thread safety);

Disadvantage: A process consumes more of the system resources, consuming more memory. Moreover, it is not good at handling high concurrent requests, in which case it will put the request into the queue and wait until there are available processes before the request is processed.

2)worker mode

Worker mode is a mixed mode that uses multi-process and multithreading compared to the previous one. It also pre-fork several sub-processes (a smaller number), and then each child process creates some threads, including a listener thread. Each request comes over and is assigned to 1 threads to service. Threads are lighter than processes because threads typically share the memory space of the parent process, so memory consumption is reduced. In high concurrency scenarios, the performance is better because there are more threads available than prefork.

Some people will find it strange, so why not use multithreading here, but also to introduce multi-process?

The main reason is that stability needs to be considered, and if one thread hangs abnormally, it causes the parent process to hang with the other normal child threads (they are all under the same process). In order to prevent this unusual scenario from appearing, you cannot use all the threads, use multiple processes and add multiple threads, and if a thread has an exception, the only part of the service that is affected is Apache, not the entire service.

Pros: Take up less memory and perform better with high concurrency.

Disadvantage: Thread-safe issues must be considered because multiple child threads are the memory addresses of the shared parent process. If you use the long connection of keep-alive, a thread will always be occupied, perhaps there is almost no request in the middle, need to wait until the timeout will be released. If too many threads are occupied, this can also lead to the availability of service-free threads in high concurrency scenarios.

3) Event mode

This is the newest pattern in Apache, which is already stable and usable in the current version. It is similar to the worker pattern, the biggest difference is that it solves the keep-alive scenario, the long-occupied threads of the resource waste problem (some threads because of being keep-alive, where the empty hanging wait, the middle of almost no request to come, or even wait until the timeout). Event

In MPM, there will be a dedicated thread to manage these keep-alive types of threads, and when there is a real request coming in, pass the request to the service thread, and then allow it to be released after execution is complete. This enhances the request processing capability in high concurrency scenarios.


3, the source code compiled installation lamp environment (based on the WordPress program), and write detailed installation, configuration, testing process.















This article is from the "11822904" blog, please be sure to keep this source http://11832904.blog.51cto.com/11822904/1959614

Linux Nineth Week Micro jobs

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.