Apache Web Server Architecture
-
Apache uses 1 thread/connection, This is not Recommended.
Main thread forks 3-10 children, Each child creates 20-25 threads depending on load.
Children creates threads at startup and never creates more. Listener listens for connections & gives connection to other threads.
main()
|-- child-process1
| |-------------|----------------------|----
| thread1 thread2 thread25
|
|-- child-process2
|
|-- child-process3
|
-- Listener-Thread (80, 8443)
//maintains Idle thread pool(thread-4, thread-17, thread-10, thread-50)
@startuml
!pragma teoz true
participant browser as b
box apache Web Server
box Send Response #Azure
control "Response\nSender" as rs #lightBlue
end box
control "main()" as m #lightBlue
box listen Connections #Azure
control listener as l #lightBlue
control "Event MPM\nMultiProcessing Module" as mpm #lightBlue
end box
queue MessageQ as mq
box Process Requests #Azure
control "Req-Handler\nWorker-Threads" as wt #lightBlue
database DB as db #LightPink
end box
end box
hnote over m
forks 3-10
children
20-25
threads/child
end note
hnote over mpm
Different MPM
for different
use case. eg:
Prefork, Worker
, Event
end note
m -> l: Create listener thread
hnote over l
listening on
80 = http
443 = https
end note
m -> wt: Create worker thread
m -> rs: Create Sender thread
b -> l: http://test.com
l -> m: event (GET)
m -> mpm: Create EVENT MPM, Use 2 Threads
l -> mpm: HTTP GET
mpm -> mq: serve GET
wt -> mq: Pick
mq -> wt: Send test.com \n to client
wt -> db: images,text,videos
db -> wt: content
wt -> mq: "topic=Send\ncontent"
mq -> rs: "topic=Send\ncontent"
rs -> b: Content
@enduml