Skip to content

Commit

Permalink
Merge "Use gevent in gunicorn"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul CI authored and Gerrit Code Review committed Feb 7, 2025
2 parents cc22319 + 93f9ea1 commit 57bb2d2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ COPY requirements.txt setup.py /opt/dci-control-server/

RUN microdnf update && \
microdnf -y install python3-pip python3-wheel && \
microdnf -y install python3-devel gcc postgresql-devel && \
rpm -qa | sort > /tmp/rpms_before && \
microdnf -y install python3-devel make gcc gcc-c++ postgresql-devel diffutils findutils file && \
rpm -qa | sort > /tmp/rpms_after && \
pip3 --no-cache-dir install -r requirements.txt && \
microdnf -y remove python3-devel gcc postgresql-devel && \
comm -13 /tmp/rpms_before /tmp/rpms_after | xargs microdnf remove && \
rm /tmp/rpms_before /tmp/rpms_after && \
microdnf -y clean all

# install source after
Expand Down
7 changes: 7 additions & 0 deletions dci/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
from sqlalchemy import exc as sa_exc
from sqlalchemy.orm import sessionmaker

try:
import psycogreen.gevent

psycogreen.gevent.patch_psycopg()
except ImportError:
pass

logger = logging.getLogger(__name__)

zmq_sender = None
Expand Down
23 changes: 20 additions & 3 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import multiprocessing
import os

default_nb_workers = multiprocessing.cpu_count() * 2 + 1
workers = int(os.getenv("DCI_NB_WORKERS", default_nb_workers))
# Don't manage workers with gunicorn but by spawning more containers and let haproxy handle balancing
DEFAULT_NB_WORKERS = 1
workers = int(os.getenv("DCI_NB_WORKERS", DEFAULT_NB_WORKERS))
worker_connections = int(os.getenv("DCI_GUNICORN_WORKER_CONNECTIONS", 50))
worker_class = "gevent"

# Restart worker after a certain amount of requests to mitigate memory leaks, etc. …
max_requests = 1000
# Add some jitter to avoid all workers restarting at the same time.
max_requests_jitter = 250

accesslog = "-"
access_log_format = (
'%(h)s:%({x-forwarded-for}i)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
)

# Some default values from gunicorn that might be of interest to tune
# max_connections = 1000
# backlog = 2048
# timeout = 30
# graceful_timeout = 30
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ pyparsing==2.1.10 # pyparsing-2.1.10-7.el8.src.rpm baseos
pytz==2017.2 # pytz-2017.2-9.el8.src.rpm appstream
psycopg2==2.7.5;python_version<="3.6" # python-psycopg2-2.7.5-7.el8.src.rpm appstream
psycopg2-binary;python_version>"3.6"
psycogreen
pyOpenSSL==19.0.0 # pyOpenSSL-19.0.0-1.el8.src.rpm appstream
jsonschema==2.6.0 # python-jsonschema-2.6.0-4.el8.src.rpm appstream
SQLAlchemy==1.3.2 # python-sqlalchemy-1.3.2-2.module_el8.5.0+761+faacb0fb.src.rpm appstream

alembic==1.3.1 # python-alembic-1.3.1-1.el8.src.rpm centos-openstack-train
six==1.14.0 # python-six-1.14.0-2.el8.src.rpm centos-openstack-train
requests==2.22.0 # python-requests-2.22.0-7.el8.src.rpm centos-openstack-train
gunicorn
gunicorn[gevent]

flask==1.1.1 # python-flask-1.1.1-1.el8.src.rpm centos-openstack-train
jinja2==2.10.1 # python3-jinja2-2.10.1-5.el8_10.noarch
Expand Down

0 comments on commit 57bb2d2

Please sign in to comment.