flask + gunicorn application performance optimizations with workers

  flask, gunicorn, kubernetes, python, python-3.x

I have a flask application running behind Gunicorn. I have setup 6 workers. The application is hosted within kubernetes and the pod has 3 CPU cores with 12 GB Memory. I am performance testing this application using JMeter. When I run my Jmeter tests with 5 concurrent users with no Gunicorn workers setup , the average response time that I am seeing is around 1 second. However when I setup 6 workers , the average response time shot up to 5 seconds. I logged into the pod and used "top" to see if the CPU or Memory utilization is high. I saw the stats for different workers showing up and below is one of the sample snapshots. The utilization is extremely low; however I am unable to to figure what is causing the increased response times. Based on the server logs , the actual processing is taking approximately 800 ms for each call [even this seems to have increased a bit when I had no workers defined vs 6 workers]. Is there any config that I am missing or is there any additional debugging that I can perform?

top - 01:52:43 up 12:23,  0 users,  load average: 10.05, 11.00, 9.27
Tasks:   9 total,   1 running,   8 sleeping,   0 stopped,   0 zombie
%Cpu(s):  9.0 us,  2.6 sy,  0.0 ni, 86.8 id,  0.0 wa,  0.5 hi,  1.0 si,  0.0 st
KiB Mem : 26353267+total, 95762880 free, 78529440 used, 89240344 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 17440603+avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
    15 nobody    20   0 1597756 239496  34792 S  22.3  0.1   6:54.83 gunicorn
     1 nobody    20   0  222136  23624   9096 S   0.0  0.0   0:00.60 gunicorn
    10 nobody    20   0 1597624 239376  34792 S   0.0  0.1   6:20.14 gunicorn
    11 nobody    20   0 1599648 241504  34800 S   0.0  0.1   7:03.91 gunicorn
    12 nobody    20   0 1597904 239728  34792 S   0.0  0.1   6:51.04 gunicorn
    13 nobody    20   0 1597608 239444  34792 S   0.0  0.1   6:45.63 gunicorn
    14 nobody    20   0 1597556 239052  34792 S   0.0  0.1   6:07.40 gunicorn

Source: Python Questions

One Reply to “flask + gunicorn application performance optimizations with workers”

LEAVE A COMMENT