undefinedfix
Sign in

The problem of the number of processes after the start of the spool server

user3511269 edited in Wed, 31 Aug 2022

Start server configuration

$server->set(
            [
                'enable_static_handler' => true,
                'document_root'         => '/usr/share/nginx/xin_mount_dev/swoole30/demo/data/',
                'task_worker_num'       => 4,
                'worker_num'            => 2,
               
            ]

        );

View startup process

[email protected]_dev:/home/tb/mount_sh_all# ps -aux |grep ws_server
root      1826  0.0  3.5 390640 36572 pts/1    Sl+  23:03   0:00 php ws_server_oop.php
root      1827  0.0  0.8 316412  8368 pts/1    S+   23:03   0:00 php ws_server_oop.php
root      1829  0.0  0.8 306152  8824 pts/1    S+   23:03   0:00 php ws_server_oop.php
root      1830  0.0  0.8 306152  8824 pts/1    S+   23:03   0:00 php ws_server_oop.php
root      1831  0.0  0.8 306152  8824 pts/1    S+   23:03   0:00 php ws_server_oop.php
root      1832  0.0  0.8 306152  8824 pts/1    S+   23:03   0:00 php ws_server_oop.php
root      1833  0.0  0.8 308456  9080 pts/1    S+   23:03   0:00 php ws_server_oop.php
root      1834  0.0  0.8 308456  9080 pts/1    S+   23:03   0:00 php ws_server_oop.php
root      1837  0.0  0.1  12944  1032 pts/0    S+   23:04   0:00 grep --color=auto ws_server

Other information

[email protected]_dev:/proc/1828# ls -ail
total 0
22348 dr-xr-xr-x   9 root root 0 Jun  8 23:03 .
    1 dr-xr-xr-x 133 root root 0 Jun  8 22:29 ..
22611 dr-xr-xr-x   2 root root 0 Jun  8 23:08 attr
22593 -rw-r--r--   1 root root 0 Jun  8 23:08 autogroup
22588 -r--------   1 root root 0 Jun  8 23:08 auxv
22616 -r--r--r--   1 root root 0 Jun  8 23:08 cgroup
22608 --w-------   1 root root 0 Jun  8 23:08 clear_refs
22596 -r--r--r--   1 root root 0 Jun  8 23:08 cmdline
22594 -rw-r--r--   1 root root 0 Jun  8 23:08 comm
22622 -rw-r--r--   1 root root 0 Jun  8 23:08 coredump_filter
22615 -r--r--r--   1 root root 0 Jun  8 23:08 cpuset
22602 lrwxrwxrwx   1 root root 0 Jun  8 23:08 cwd -> /usr/share/nginx/xin_mount_dev/swoole30/demo/server
22587 -r--------   1 root root 0 Jun  8 23:08 environ
22604 lrwxrwxrwx   1 root root 0 Jun  8 23:08 exe -> /usr/bin/php7.0
22583 dr-x------   2 root root 0 Jun  8 23:08 fd
22585 dr-x------   2 root root 0 Jun  8 23:08 fdinfo
22625 -rw-r--r--   1 root root 0 Jun  8 23:08 gid_map
22623 -r--------   1 root root 0 Jun  8 23:08 io
22591 -r--r--r--   1 root root 0 Jun  8 23:08 limits
22620 -rw-r--r--   1 root root 0 Jun  8 23:08 loginuid
22584 dr-x------   2 root root 0 Jun  8 23:08 map_files
22599 -r--r--r--   1 root root 0 Jun  8 23:08 maps
22601 -rw-------   1 root root 0 Jun  8 23:08 mem
22606 -r--r--r--   1 root root 0 Jun  8 23:08 mountinfo
22605 -r--r--r--   1 root root 0 Jun  8 23:08 mounts
22607 -r--------   1 root root 0 Jun  8 23:08 mountstats
22586 dr-xr-xr-x   5 root root 0 Jun  8 23:08 net
22349 dr-x--x--x   2 root root 0 Jun  8 23:03 ns
22600 -r--r--r--   1 root root 0 Jun  8 23:08 numa_maps
22618 -rw-r--r--   1 root root 0 Jun  8 23:08 oom_adj
22617 -r--r--r--   1 root root 0 Jun  8 23:08 oom_score
22619 -rw-r--r--   1 root root 0 Jun  8 23:08 oom_score_adj
22610 -r--------   1 root root 0 Jun  8 23:08 pagemap
22590 -r--------   1 root root 0 Jun  8 23:08 personality
22626 -rw-r--r--   1 root root 0 Jun  8 23:08 projid_map
22603 lrwxrwxrwx   1 root root 0 Jun  8 23:08 root -> /
22592 -rw-r--r--   1 root root 0 Jun  8 23:08 sched
=========================================
[email protected]_dev:/proc/1828# ps -aux |grep 1827 |grep -v grep
root      1827  0.0  0.8 316412  8368 pts/1    S+   23:03   0:00 php ws_server_oop.php
[email protected]_dev:/proc/1828# ps -aux |grep 1826 |grep -v grep
root      1826  0.0  3.5 390640 36572 pts/1    Sl+  23:03   0:00 php ws_server_oop.php
[email protected]_dev:/proc/1828# ps -aux |grep 1828 |grep -v grep
[email protected]_dev:/proc/1828# ps -aux |grep 1831 |grep -v grep
root      1831  0.0  0.8 306152  8824 pts/1    S+   23:03   0:00 php ws_server_oop.php

What does the 1828 process ID represent?

[email protected]_dev:/home/tb/mount_sh_all# pstree -p 1826
php(1826)─┬─php(1827)─┬─php(1829)
          │           ├─php(1830)
          │           ├─php(1831)
          │           ├─php(1832)
          │           ├─php(1833)
          │           └─php(1834)
          └─{php}(1828)

It can be seen that master ID is: 1826manager_ PID is: 1827, what is 1828?

2 Replies
jakab922
commented on Thu, 01 Sep 2022

Look at the configuration. There should be eight processes. One master 1manager process 2worker 4task

aroberts86
commented on Thu, 01 Sep 2022
#进程树关系
php(1672)─┬─php(1673)─┬─php(1676)
          │           ├─php(1677)
          │           ├─php(1678)
          │           ├─php(1679)
          │           ├─php(1680)
          │           └─php(1681)
          ├─{php}(1674)
          └─{php}(1675)
#追踪master进程,epoll_wait          
strace -p 1672
strace: Process 1672 attached
epoll_wait(19, [], 4096, 1000)          = 0
madvise(0x7ff8e800f000, 4096, MADV_DONTNEED) = 0
epoll_wait(19, [], 4096, 1000)          = 0
epoll_wait(19, [], 4096, 1000)          = 0
madvise(0x7ff8e800f000, 4096, MADV_DONTNEED) = 0
epoll_wait(19, [], 4096, 1000)          = 0
epoll_wait(19, ^Cstrace: Process 1672 detached
 <detached ...>
#追踪manager进程,wait
[email protected]_dev:/home/tb# strace -p 1673
strace: Process 1673 attached
wait4(-1, 
#追踪{线程},epoll_wait 
[email protected]_dev:/home/tb# strace -p 1674
strace: Process 1674 attached
epoll_wait(21, 

#追踪{线程},epoll_wait 
[email protected]_dev:/home/tb# strace -p 1675
strace: Process 1675 attached
epoll_wait(22, 

#追踪woker task进程
[email protected]_dev:/home/tb# strace -p 1676
strace: Process 1676 attached
read(11, 
#查看1672线程 
[email protected]_dev:/home/tb# ps -T -p 1672
  PID  SPID TTY          TIME CMD
 1672  1672 pts/0    00:00:00 php
 1672  1674 pts/0    00:00:00 php
 1672  1675 pts/0    00:00:00 php
#查看1673 manager进程
[email protected]_dev:/home/tb# ps -T -p 1673
  PID  SPID TTY          TIME CMD
 1673  1673 pts/0    00:00:00 php
#查看线程
[email protected]_dev:/home/tb# ps -T -p 1674
  PID  SPID TTY          TIME CMD
#查看线程
[email protected]_dev:/home/tb# ps -T -p 1675
  PID  SPID TTY          TIME CMD
#查看woker task进程
[email protected]_dev:/home/tb# ps -T -p 1676
  PID  SPID TTY          TIME CMD
 1676  1676 pts/0    00:00:00 php
#查看woker task进程
[email protected]_dev:/home/tb# ps -T -p 1677
  PID  SPID TTY          TIME CMD
 1677  1677 pts/0    00:00:00 php
[email protected]_dev:/home/tb# 

clipboard.png

The main process of spool is a multithreaded program. There is a very important group of threads called reactor threads. It is the thread that handles TCP connection and sends and receives data. After accepting a new connection, the main thread of spool will assign the connection to a fixed reactor thread, which is responsible for listening to the socket. When the socket is readable, the data is read, the protocol is parsed, and the request is delivered to the worker process. When the socket is writable, the data is sent to the TCP client.Reactor threads, reactor_ Num = > 2. Use this parameter to adjust the number of event processing threads in the main process to make full use of multi-core. By default, the same number of CPU cores will be enabled. reactor_ Num is recommended to be 1-4 times the number of CPU coresreactor_ Num must not exceed the maximum value of zoom_ CPU_ Num 4reactor thread can use multi-core. For example, if the machine has 128 cores, the underlying layer will start 128 threads. Each thread can maintain an EventLoop. There is no lock between threads, and instructions can be executed in parallel by 128 core CPU. Considering the performance loss of operating system scheduling to a certain extent, it can be set to CPU core number 2 to maximize the utilization of each CPU core.