apache 2.x版本目前有好几种并发处理模块, 需要在编译的时候通过–with-mpm=xxx指定,常用的并发处理模式是prefork和worker。prefork这种模式比较古老,纯进程并发,没有线程,处理方式跟apache1.x是一样的,适用于那些没有线程库或者不想使用线程的服务器;worker是多进程多线程的模式,在worker模式下,有一个唯一的父进程(控制进程),这个父进程会根据需要生成若干子进程,每个子进程会有一个监听线程和若干个服务线程(每个子进程的服务线程数目都是固定的,由ThreadsPerChild指定),监听线程负责监听客户端请求并把它们交给服务线程处理。理论上worker模式的性能会比prefork模式优秀,处理同样多的请求的时候占用的资源会比prefork少。
按照官方文档说法:
The server can be better customized for the needs of the particular site. For example, sites that need a great deal of scalability can choose to use a threaded MPM like worker or event, while sites requiring stability or compatibility with older software can use a prefork.
worker
This Multi-Processing Module (MPM) implements a hybrid multi-process multi-threaded server. By using threads to serve requests, it is able to serve a large number of requests with fewer system resources than a process-based server. However, it retains much of the stability of a process-based server by keeping multiple processes available, each with many threads.
prefork
This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.
worker模块的配置参数: