0

I have a service:

[Unit]
Description=tweetsift

After=network.target

[Service]
User=root
Group=root
WorkingDirectory=/var/www/html
ExecStart=sudo /usr/bin/nice -n -20 sudo -u root sudo gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app

Restart=on-failure

[Install]
WantedBy=multi-user.target

When I run sudo systemctl status tweet I see that I am using /usr/bin/nice for the main PID. However it is not taking on the workers.

 tweetsift.service - tweet
     Loaded: loaded (/etc/systemd/system/tweet.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-01-09 04:36:08 UTC; 5min ago
   Main PID: 3124 (sudo)
      Tasks: 12 (limit: 4661)
     Memory: 702.8M
        CPU: 7.580s
     CGroup: /system.slice/tweet.service
             ├─3124 sudo /usr/bin/nice -n -20 sudo -u root sudo gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app
             ├─3125 sudo -u root sudo gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app
             ├─3126 sudo gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app
             ├─3127 /usr/bin/python3 /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app
             ├─3128 /usr/bin/python3 /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app
             ├─3129 /usr/bin/python3 /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app
             ├─3130 /usr/bin/python3 /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app
             └─3131 /usr/bin/python3 /usr/local/bin/gunicorn -w 4 -b 0.0.0.0:5000 endpoint:app

I am running a machine learning script that sucks down the CPU. I tried using nice python3 tweet.py and it works and doesn't kill the process.

However, when I try call the api endpoint I built. The service starts up using a worker and then gets killed for OOM (Out of Memory).

I am using Ubuntu 20.04 & Apache2

Any ideas? I was able to get nice running on the main PID by updating the /etc/sudoers/ and adding a line to allow sudo to use it.

But I still can't get the script to run as a service using nice for the workers PIDs too when they start up upon an API call to the flask app I've got running.

I am using gunicorn (version 20.1.0)

Thanks!

I've tried everything at this point. I want nice to be applied to gunicorn workers when my flask app has an api call sent to it without getting killed for OOM.

I'm using a 4GB Intel 80GB Disk premium intel droplet on DigitalOcean.

davidism
  • 121,510
  • 29
  • 395
  • 339
lasvegas
  • 39
  • 7

0 Answers0