1. Introduction to apache service:
Apache HTTP Server (Apache for short) is an open source
web server of the Apache Software Foundation. It can run on most computer operating systems. It is widely used due to its multi-platform and security. It is one of the most popular web server-side software. One. It is fast, reliable and can be extended through a simple API to compile Perl/Python and other interpreters into the server
It was originally only used for small-scale or experimental Internet networks, and later gradually expanded to various Unix systems, especially the support for Linux is quite perfect. Apache has a variety of products that can support SSL technology and support multiple virtual hosts. Apache is a process-based structure. Processes consume more system expenses than threads and are not suitable for multi-processor environments. Therefore, when an Apache Web site is expanded, it is usually to increase
servers or expand cluster nodes rather than increase processor. So far, Apache is still the most used web server in the world, with a market share of about 60%
2. The Apache server has the following features:
supports the latest HTTP/1.1 communication protocol. Apache is one of the first Web servers to use the HTTP/1.1 protocol. It is fully compatible with the HTTP/1.1 protocol and backward compatible with the HTTP/1.0 protocol. Apache has made the necessary preparations for all the content provided by the new agreement.
supports multiple computer platforms. Apache can run on almost all computer operating systems, including mainstream UNIX, Linux and Windows operating systems.
has a simple and powerful file-based configuration process. The configuration file is simple and easy to operate. Users can modify Apache by directly modifying the configuration file information of Apache, which is very convenient to operate.
supports real-time monitoring of server status and custom server logs. Apache provides great flexibility in recording logs and monitoring the running status of
the server itself. You can monitor the status of the server through a Web browser, or you can customize the log according to your needs.
supports multiple methods of HTTP authentication.
Support Web directory modification. Users can use specific directories as web directories.
Support CGI scripts, such as Perl, PHP, etc.
Support server-side include instructions (SSI).
Support secure Socket layer (SSL).
Support FastCGI.
supports virtual hosting. That is, multiple HTTP services are provided by using different host names on
one server. Apache supports three types of virtual host services based on IP, host name and port number.
Track user sessions. When users browse Apache-based Web sites, they can be tracked through Apache's mod_usertrack module.
supports dynamic shared objects. Apache modules can be dynamically loaded at runtime, which means that these modules can be loaded into the server process space, thereby reducing system memory overhead.
supports multiple processes. When the load increases,
the server will quickly generate sub-processes to handle, thereby improving the responsiveness of the system.
Support the function modules provided by third-party software developers. For example, Apache can support Java Servlet after loading the mod_jserv module, so that Java applications can be run.
MPM supporting multi-threaded and multi-process mixed model. When the MPM type is designated as worker, because it uses threads to process, it can handle a large number of requests, and the overhead of system resources is less than that of a process-based server.
Support real-time monitoring of server status and custom server logs
Support general gateway interface
Support IP-based and domain-based virtual hosting
Integrated proxy server module
3, apache working mode:
Apache 2.X supports plug-in parallel processing modules, called multiple processing modules (MPM). When compiling apache, you must choose or can only choose one MPM. For UNIX-like systems, there are several different MPMs to choose from, which will affect the speed and scalability of apache.
Worker MPM: Use multiple sub-processes, and each sub-process has multiple threads. Each thread processes a request, and the MPM is usually a good choice for high-traffic servers. Because it requires less memory and is more scalable than prefork MPM. More suitable for load balancing occasions.
The working principle of prefork is that after the control process initially establishes "StartServers" sub-processes, in order to meet the needs of MinSpareServers settings, create a process, wait one second, continue to create two, wait another second, continue to create four... In this way, the number of processes created is increased exponentially, up to 32 per second, until the value set by MinSpareServers is satisfied. This is the origin of prefork. This mode eliminates the need to generate new processes when the request comes. Thus reducing system overhead to increase performance.
The working principle of the worker is that the main control process generates "StartServers" sub-processes. Each sub-process contains a fixed number of ThreadsPerChild threads, and each thread processes the request independently. Similarly, in order not to generate threads when the request arrives, MinSpareThreads and MaxSpareThreads are set The minimum and maximum number of idle threads; MaxClients sets the total number of threads in all child processes. If the total number of threads in the existing child processes cannot meet the load, the control process will spawn new child processes.
Prefork MPM: Use multiple child processes, but each child process does not contain multiple threads. Each process only handles one connection. It is as fast as the worker MPM on many systems, but requires more memory. This threadless design is better than worker MPM under certain conditions, because it can be applied to third-party modules that do not have thread safety (such as PHP3/4/5), and on platforms that do not support thread debugging It is easy to debug and has higher stability than worker MPM.
prefork is the default working mode of apache. You can add the parameter -with-mpm-work to select the working mode when compiling.
In a nutshell
The feature of prefork is pre-derived
1: This mode eliminates the need to generate new processes when the request arrives, thereby reducing system overhead
2: Can prevent accidental memory leaks
3: When the server load drops, it will automatically reduce the number of child processes
The characteristics of work are:
Multi-processing module supporting mixed multi-thread and multi-process
For a high-traffic http service, work mpm is a better choice, because work mpm occupies less memory than prefork.