Install jemalloc in docker image (#8553)

Co-authored-by: Will Hunt <willh@matrix.org>
Co-authored-by: Erik Johnston <erik@matrix.org>
This commit is contained in:
Mathieu Velten 2021-03-16 12:32:18 +01:00 committed by GitHub
parent 1383508f29
commit ccf1dc51d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

1
changelog.d/8553.docker Normal file
View file

@ -0,0 +1 @@
Use jemalloc if available in docker.

View file

@ -69,6 +69,7 @@ RUN apt-get update && apt-get install -y \
libpq5 \ libpq5 \
libwebp6 \ libwebp6 \
xmlsec1 \ xmlsec1 \
libjemalloc2 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY --from=builder /install /usr/local COPY --from=builder /install /usr/local

View file

@ -204,3 +204,8 @@ healthcheck:
timeout: 10s timeout: 10s
retries: 3 retries: 3
``` ```
## Using jemalloc
Jemalloc is embedded in the image and will be used instead of the default allocator.
You can read about jemalloc by reading the Synapse [README](../README.md)

View file

@ -3,6 +3,7 @@
import codecs import codecs
import glob import glob
import os import os
import platform
import subprocess import subprocess
import sys import sys
@ -213,6 +214,13 @@ def main(args, environ):
if "-m" not in args: if "-m" not in args:
args = ["-m", synapse_worker] + args args = ["-m", synapse_worker] + args
jemallocpath = "/usr/lib/%s-linux-gnu/libjemalloc.so.2" % (platform.machine(),)
if os.path.isfile(jemallocpath):
environ["LD_PRELOAD"] = jemallocpath
else:
log("Could not find %s, will not use" % (jemallocpath,))
# if there are no config files passed to synapse, try adding the default file # if there are no config files passed to synapse, try adding the default file
if not any(p.startswith("--config-path") or p.startswith("-c") for p in args): if not any(p.startswith("--config-path") or p.startswith("-c") for p in args):
config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data") config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data")
@ -248,9 +256,9 @@ running with 'migrate_config'. See the README for more details.
args = ["python"] + args args = ["python"] + args
if ownership is not None: if ownership is not None:
args = ["gosu", ownership] + args args = ["gosu", ownership] + args
os.execv("/usr/sbin/gosu", args) os.execve("/usr/sbin/gosu", args, environ)
else: else:
os.execv("/usr/local/bin/python", args) os.execve("/usr/local/bin/python", args, environ)
if __name__ == "__main__": if __name__ == "__main__":