diff --git a/http_service/Dockerfile b/http_service/Dockerfile index 192d9660c6..ac05994f01 100644 --- a/http_service/Dockerfile +++ b/http_service/Dockerfile @@ -19,4 +19,4 @@ ENV MPLCONFIGDIR=/opt/matplotlib RUN python -c "import matplotlib.font_manager" && chmod -R a+rwX $MPLCONFIGDIR # Run the Pulse listener in the background -CMD (bugbug-http-pulse-listener &) && gunicorn -b 0.0.0.0:$PORT bugbug_http.app --preload --timeout 30 -w 3 +CMD (bugbug-http-pulse-listener &) && gunicorn -c python:bugbug_http.gunicorn_conf -b 0.0.0.0:$PORT bugbug_http.app --preload --timeout 30 -w 3 diff --git a/http_service/bugbug_http/gunicorn_conf.py b/http_service/bugbug_http/gunicorn_conf.py new file mode 100644 index 0000000000..6ff0f12c1a --- /dev/null +++ b/http_service/bugbug_http/gunicorn_conf.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. + +"""Gunicorn configuration for the web processes (loaded with ``-c python:bugbug_http.gunicorn_conf``).""" + +import gc + +# With --preload, the workers share the master's memory (the imported modules) until they write to +# it, and a garbage collection writes to every object it traverses. Following +# https://docs.python.org/3/library/gc.html#gc.freeze, collections are disabled while the app is +# preloaded (this module is loaded before it), so that they don't free objects and leave holes +# that the workers' allocations would fill, writing to the shared pages. +gc.disable() + + +def pre_fork(server, worker): + # Move the objects allocated so far to the permanent generation, which collections don't + # traverse, then enable the collections again: in the master, which keeps running (e.g. Sentry's + # threads), and in the worker, which inherits them. + gc.freeze() + gc.enable() diff --git a/scripts/integration_test.sh b/scripts/integration_test.sh index a3ebee110c..73f24e711f 100755 --- a/scripts/integration_test.sh +++ b/scripts/integration_test.sh @@ -61,7 +61,7 @@ sleep 1 redis-cli -n 4 FLUSHDB # Start the http server -gunicorn -b 127.0.0.1:8000 bugbug_http.app --preload --timeout 30 -w 3 & +gunicorn -c python:bugbug_http.gunicorn_conf -b 127.0.0.1:8000 bugbug_http.app --preload --timeout 30 -w 3 & gunicorn_pid=$! # Start the background worker