Gunicorn spiking CPU to 100% on certain pages...killing performance

Viewed 2183

I have a Django app that is being served through Nginx / Gunicorn. When loading certain pages, Gunicorn is spiking in CPU usage to 100% and totally killing performance, causing the page to take 10 seconds to load.

I am not making any DB calls - I have all the results loaded into memcached already. It should be very fast so this insane slow down is wild.

gunicorn_start:

NAME="name"                                  # Name of the application
MAINDIR=/opt/name/
DJANGODIR=/opt/name/path             # Django project directory
SOCKFILE=/opt/name/run/gunicorn.sock  # we will communicte using this unix socket
USER=nginx                                       # the user to run as
GROUP=nginx                                      # the group to run as
NUM_WORKERS=3                                     # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=name.settings             # which settings file should Django use
DJANGO_WSGI_MODULE=name.wsgi                     # WSGI module name

lscpu:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             8
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 63
Model name:            Intel(R) Xeon(R) CPU E5-2660 v3 @ 2.60GHz
Stepping:              2
CPU MHz:               2593.993
BogoMIPS:              5187.98
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              25600K
NUMA node0 CPU(s):     0-7

nginx.conf:

user  nginx;
worker_processes  8;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    client_max_body_size 20M;
    keepalive_timeout  0;

    gzip  on;
    gzip_vary on;
    gzip_min_length 10240;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/javascript application/xml;
    gzip_disable "MSIE [1-6]\.";

    include /etc/nginx/conf.d/*.conf;

This is deployed to a remote test server. I have tried setting the NUM_WORKERS in gunicorn_start to 1, 3, 9, and 17 but the issue persists regardless.

When I turn off gunicorn and run it locally on the machine with manage.py runserver, the problem goes away and the speeds are fine, so I know the problem lies either in Nginx or Gunicorn.

0 Answers
Related