1.swoole process model
swoole is a framework for a multi-process model, when starting a process swoole application, altogether will create 2 + n + m threads, n is the number of worker processes, m is TaskWorker number of processes, a master process and a manager process, relationship As shown below
Master process-based process, which creates Manager processes, Reactor threading Work / thread
Where the relationship between the three processes are:
Reactor threads:
- Responsible for maintaining client
TCP
connections, network processingIO
, protocol processing, send and receive data - It is completely non-blocking asynchronous mode
- All of
C
the code, in addition toStart
/Shudown
event callback, but does not execute any PHP code - The
TCP
client buffering incoming data, spliced, split into a complete request packet Reactor
Operate in a multi-threaded manner
Worker process
- Accepted by the
Reactor
thread posted request packet, and executes thePHP
callback data processing - Generating response data and sent to
Reactor
the thread, theReactor
sending thread to theTCP
client - Can be asynchronous non-blocking mode, it can be synchronous blocking mode
Worker
Run as multiple processes
TaskWorker process
- Accepted by the
Worker
process by theswoole_server->task/taskwait
method of delivery of mission - Processing tasks, and returns the data (using
swoole_server->finish
) to theWorker
process - Completely synchronous blocking mode
TaskWorker
Run as multiple processes