Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit ccf1dc5

Browse files
MatMaulHalf-Shoterikjohnston
authored
Install jemalloc in docker image (#8553)
Co-authored-by: Will Hunt <[email protected]> Co-authored-by: Erik Johnston <[email protected]>
1 parent 1383508 commit ccf1dc5

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

changelog.d/8553.docker

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use jemalloc if available in docker.

docker/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ RUN apt-get update && apt-get install -y \
6969
libpq5 \
7070
libwebp6 \
7171
xmlsec1 \
72+
libjemalloc2 \
7273
&& rm -rf /var/lib/apt/lists/*
7374

7475
COPY --from=builder /install /usr/local

docker/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,8 @@ healthcheck:
204204
timeout: 10s
205205
retries: 3
206206
```
207+
208+
## Using jemalloc
209+
210+
Jemalloc is embedded in the image and will be used instead of the default allocator.
211+
You can read about jemalloc by reading the Synapse [README](../README.md)

docker/start.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import codecs
44
import glob
55
import os
6+
import platform
67
import subprocess
78
import sys
89

@@ -213,6 +214,13 @@ def main(args, environ):
213214
if "-m" not in args:
214215
args = ["-m", synapse_worker] + args
215216

217+
jemallocpath = "/usr/lib/%s-linux-gnu/libjemalloc.so.2" % (platform.machine(),)
218+
219+
if os.path.isfile(jemallocpath):
220+
environ["LD_PRELOAD"] = jemallocpath
221+
else:
222+
log("Could not find %s, will not use" % (jemallocpath,))
223+
216224
# if there are no config files passed to synapse, try adding the default file
217225
if not any(p.startswith("--config-path") or p.startswith("-c") for p in args):
218226
config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data")
@@ -248,9 +256,9 @@ def main(args, environ):
248256
args = ["python"] + args
249257
if ownership is not None:
250258
args = ["gosu", ownership] + args
251-
os.execv("/usr/sbin/gosu", args)
259+
os.execve("/usr/sbin/gosu", args, environ)
252260
else:
253-
os.execv("/usr/local/bin/python", args)
261+
os.execve("/usr/local/bin/python", args, environ)
254262

255263

256264
if __name__ == "__main__":

0 commit comments

Comments
 (0)