From ba9190cbafad52aff2bca10f14670aec3b19cdd5 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Thu, 15 Oct 2020 10:31:44 +0200 Subject: [PATCH 1/6] Install jemalloc deb Signed-off-by: Mathieu Velten --- changelog.d/8553.docker | 1 + docker/Dockerfile | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog.d/8553.docker diff --git a/changelog.d/8553.docker b/changelog.d/8553.docker new file mode 100644 index 000000000000..9779cca55f5b --- /dev/null +++ b/changelog.d/8553.docker @@ -0,0 +1 @@ +Install jemalloc deb in docker image. diff --git a/docker/Dockerfile b/docker/Dockerfile index 27512f860092..ba82cf4cec40 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -66,6 +66,7 @@ RUN apt-get update && apt-get install -y \ libpq5 \ libwebp6 \ xmlsec1 \ + libjemalloc2 \ && rm -rf /var/lib/apt/lists/* COPY --from=builder /install /usr/local From 22726ff2022deb6f4b023baaae4fdcb606646c95 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Thu, 15 Oct 2020 13:45:46 +0200 Subject: [PATCH 2/6] Add doc --- docker/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docker/README.md b/docker/README.md index c8f27b8566fc..ef41048a998e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -205,3 +205,14 @@ healthcheck: timeout: 10s retries: 3 ``` + +## Using jemalloc + +Jemalloc is embedded in the image and can be used instead of the default allocator +(cf main README for more infos). + +To do so you can add this to your `docker run` commands: + +``` +-e LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 +``` From a71a02602db143194baeb58d9d175f161f7b5669 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 11 Mar 2021 16:10:20 +0000 Subject: [PATCH 3/6] Use jemalloc by default --- docker/README.md | 10 ++-------- docker/start.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docker/README.md b/docker/README.md index 14cd2eb238bc..3a7dc585e7b5 100644 --- a/docker/README.md +++ b/docker/README.md @@ -207,11 +207,5 @@ healthcheck: ## Using jemalloc -Jemalloc is embedded in the image and can be used instead of the default allocator -(cf main README for more infos). - -To do so you can add this to your `docker run` commands: - -``` --e LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 -``` +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) \ No newline at end of file diff --git a/docker/start.py b/docker/start.py index 0d2c590b8838..495376539693 100755 --- a/docker/start.py +++ b/docker/start.py @@ -3,9 +3,9 @@ import codecs import glob import os +import platform import subprocess import sys - import jinja2 @@ -213,6 +213,14 @@ def main(args, environ): if "-m" not in args: args = ["-m", synapse_worker] + args + + jemallocpath = f"/usr/lib/{platform.machine()}-linux-gnu/libjemalloc.so.2" + + if os.path.isfile(jemallocpath): + environ['LD_PRELOAD'] = jemallocpath + else: + log(f"Could not find {jemallocpath}, will not use") + # 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): config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data") @@ -248,9 +256,9 @@ def main(args, environ): args = ["python"] + args if ownership is not None: args = ["gosu", ownership] + args - os.execv("/usr/sbin/gosu", args) + os.execve("/usr/sbin/gosu", args, environ) else: - os.execv("/usr/local/bin/python", args) + os.execve("/usr/local/bin/python", args, environ) if __name__ == "__main__": From 11be1ea73e0f52ab3ad3e25641f064c4eb893f8a Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 11 Mar 2021 16:14:55 +0000 Subject: [PATCH 4/6] Styling --- docker/start.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/start.py b/docker/start.py index 495376539693..6e0b0d21ddb8 100755 --- a/docker/start.py +++ b/docker/start.py @@ -6,6 +6,7 @@ import platform import subprocess import sys + import jinja2 @@ -213,11 +214,10 @@ def main(args, environ): if "-m" not in args: args = ["-m", synapse_worker] + args - jemallocpath = f"/usr/lib/{platform.machine()}-linux-gnu/libjemalloc.so.2" if os.path.isfile(jemallocpath): - environ['LD_PRELOAD'] = jemallocpath + environ["LD_PRELOAD"] = jemallocpath else: log(f"Could not find {jemallocpath}, will not use") From 76e0757fb3e20c8bc9da008a995c0f3e931ae6d7 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 11 Mar 2021 16:49:18 +0000 Subject: [PATCH 5/6] update changelog --- changelog.d/8553.docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/8553.docker b/changelog.d/8553.docker index 9779cca55f5b..f99c4207b806 100644 --- a/changelog.d/8553.docker +++ b/changelog.d/8553.docker @@ -1 +1 @@ -Install jemalloc deb in docker image. +Use jemalloc if available in docker. From 6ec66b00c224bb775f607f6567502f7656b83465 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 16 Mar 2021 10:42:32 +0000 Subject: [PATCH 6/6] Replace fstrings with % formats Co-authored-by: Erik Johnston --- docker/start.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/start.py b/docker/start.py index 6e0b0d21ddb8..16d6a8208a5f 100755 --- a/docker/start.py +++ b/docker/start.py @@ -214,12 +214,12 @@ def main(args, environ): if "-m" not in args: args = ["-m", synapse_worker] + args - jemallocpath = f"/usr/lib/{platform.machine()}-linux-gnu/libjemalloc.so.2" + jemallocpath = "/usr/lib/%s-linux-gnu/libjemalloc.so.2" % (platform.machine(),) if os.path.isfile(jemallocpath): environ["LD_PRELOAD"] = jemallocpath else: - log(f"Could not find {jemallocpath}, will not use") + log("Could not find %s, will not use" % (jemallocpath,)) # 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):