-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup jemalloc in default Dockerfile to optimize memory allocation #50943
Conversation
7db4239
to
f2c1f0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we should do this, as it's really a no brainer in term of performance.
However as is this PR break a few stuff and need some more work. IIRC the jemalloc
package comes with a command that does the proper LD_PRELOAD, we should just use that.
railties/lib/rails/generators/rails/app/templates/Dockerfile.tt
Outdated
Show resolved
Hide resolved
cfea2c8
to
14e81ea
Compare
Apologies for the drive-by comment, but I think the "better way" would be to patch Ruby directly to use libjemalloc, as mastodon shows: https://github.com/mastodon/mastodon/blob/1666b1955992e16f4605b414c6563ca25b3a3f18/Dockerfile#L108-L113
Happy to make a PR for this change if it is desired! |
I'm aware of this technique, but I don't want to patch a binary that comes from a previous layer, and the LD_PRELOAD leaking isn't a big concern except for Google Chrome, which is an extremely niche use in production, and is easily worked around by add |
Gotchu! |
@@ -1,5 +1,10 @@ | |||
#!/bin/bash -e | |||
|
|||
# Enable jemalloc for reduced memory usage and reduce latency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo:
# Enable jemalloc for reduced memory usage and reduce latency. | |
# Enable jemalloc for reduced memory usage and reduced latency. |
Or just removing is more succint imo:
# Enable jemalloc for reduced memory usage and reduce latency. | |
# Enable jemalloc for reduced memory usage and latency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@byroot @northeastprince I'm not seeing jemalloc being used in the process map. Can you double check? Compare the output of
on the rails server process vs the output using
in the entrypoint script |
Otherwise it won't applied to the execed process. Fix: #50943 (comment)
Yeah, I forgot to add |
Otherwise it won't applied to the execed process. Fix: rails#50943 (comment)
Otherwise it won't applied to the execed process. Fix: rails#50943 (comment)
Otherwise it won't applied to the execed process. Fix: rails#50943 (comment)
Ruby's use of
malloc
can create memory fragmentation problems, especially when using multiple threads like Puma does. Switching to an allocator that uses different patterns to avoid fragmentation can decrease memory usage by a substantial margin.