hkcomori
hkcomori

Reputation: 33

Although the "Process" setting value is 2, uWSGI starts 3 processes

I run Flask app using uWSGI.

I set uWSGI "Process" value is 2.

However, uWSGI starts 3 processes.

Why is this? What does the third process do?

Details

The following is the result of executing service uwsgi status.

● uwsgi.service - uWSGI
   Loaded: loaded (/etc/systemd/system/uwsgi.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2020-03-02 18:00:45 JST; 3 days ago
 Main PID: 26656 (uwsgi)
   Status: "The Emperor is governing 1 vassals"
    Tasks: 5 (limit: 1103)
   CGroup: /system.slice/uwsgi.service
           tq11620 /usr/local/bin/uwsgi --ini app1.ini
           tq14304 /usr/local/bin/uwsgi --ini app1.ini
           tq26656 /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --die-on-term --logto /var/log/uwsgi/emperor.log --logfile-chmod 640 --touch-logreopen /var/log/uwsgi/emperor.log.trigger
           tq26664 /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --die-on-term --logto /var/log/uwsgi/emperor.log --logfile-chmod 640 --touch-logreopen /var/log/uwsgi/emperor.log.trigger
           mq26666 /usr/local/bin/uwsgi --ini app1.ini

I found two emperor processes and three vassal processes.

The result of ps aux | grep uwsgi is following:

user     721  0.0  1.1  58456 11356 ?        Ss   11:37   0:00 /usr/local/bin uwsgi --emperor /etc/uwsgi/vassals --die-on-term --logto /var/log/uwsgi/emperor.log --logfile-chmod 640 --touch-logreopen /var/log/uwsgi/emperor.log.trigger
user     795  0.0  0.2  52424  2540 ?        S    11:37   0:00 /usr/local/bin uwsgi --emperor /etc/uwsgi/vassals --die-on-term --logto /var/log/uwsgi/emperor.log --logfile-chmod 640 --touch-logreopen /var/log/uwsgi/emperor.log.trigger
user     796  0.0  5.2 168676 52608 ?        S    11:37   0:02 /usr/local/bin uwsgi --ini app1.ini
user    1056  0.0  5.3 173056 53444 ?        S    11:37   0:04 /usr/local/bin uwsgi --ini app1.ini
user    1057  0.0  5.3 173136 53412 ?        S    11:37   0:03 /usr/local/bin uwsgi --ini app1.ini
user    2602  0.0  0.0  14428  1000 pts/1    S+   13:22   0:00 grep --color=auto uwsgi

I use the emperor.

/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --die-on-term --logto /var/log/uwsgi/emperor.log --logfile-chmod 640 --touch-logreopen /var/log/uwsgi/emperor.log.trigger

The following is the INI file of uWSGI.

[uwsgi]
base = /home/shizai/%n
chdir = %(base)
module = webapp.view:app
master = true
processes = 2
gevent = 1024
socket = /tmp/uwsgi_%n.sock
chmod-socket = 666
vacuum = true
die-on-term = true

logto = /var/log/uwsgi/%n.log
logfile-chmod = 640
touch-logreopen = /var/log/uwsgi/%n.log.trigger
log-encoder = format ${strftime:%%Y/%%m/%%d %%H:%%M:%%S} - ${msgnl}
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true

harakiri = 90

touch-reload = .uwsgi_touch

Environment

Thank you.

Upvotes: 0

Views: 593

Answers (2)

comte
comte

Reputation: 3344

It's normal behaviour: master = true and workers = 2 will start 3 processes: 1 master and 2 workers.

Upvotes: 1

hkcomori
hkcomori

Reputation: 33

The role of the three spawned processes was found. There is one master process and two worker processes.

I found the following in /var/log/uwsgi/app1.ini:

2020/03/06 11:37:51 - spawned uWSGI master process (pid: 796)
2020/03/06 11:37:51 - spawned uWSGI worker 1 (pid: 1056, cores: 1024)
2020/03/06 11:37:51 - spawned uWSGI worker 2 (pid: 1057, cores: 1024)

Unfortunately I don't know why emperor has two processes. I have not set the value of processes to emperor. In this case, is it the same value as the number of CPU cores?

Upvotes: 1

Related Questions