如何使用rvm将jemalloc添加到现有的rails服务器?

Jos*_* Kj 5 ruby ruby-on-rails rvm jemalloc

如何在 Rails 服务器上运行的 ruby​​ 中添加 jemalloc?我们使用 rvm 安装了 ruby​​。

Rails version:5.2 Ruby version:2.5.1

我试过

ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
Run Code Online (Sandbox Code Playgroud)

我得到的输出为

-lpthread -lgmp -ldl -lcrypt -lm
Run Code Online (Sandbox Code Playgroud)

我看到一篇文章使用 Jemalloc 降低 Rails 应用程序的内存使用率,但它使用 rbenv

小智 6

我设法使用以下步骤添加 jemalloc:

安装 Jemalloc 库,最好使用发行版的包管理器。(apt、pacman、brew 等):

# For instance, on Ubuntu:
sudo apt install libjemalloc-dev
Run Code Online (Sandbox Code Playgroud)

使用编译标志重新安装当前安装的 ruby​​ 版本以包含 Jemalloc 支持:

rvm reinstall 2.6.6 -C --with-jemalloc
Run Code Online (Sandbox Code Playgroud)

旧版本的 ruby​​ 使用编译标志语法-with-jemalloc(带有一个破折号),但 Ruby 2.6 及更高版本使用--with-jemalloc(带有两个破折号)。

然后检查 Jemalloc 支持是否已正确添加:

# For ruby >= 2.6:
ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"
# For ruby < 2.6:
ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
Run Code Online (Sandbox Code Playgroud)

它应该输出类似:

-lpthread -ljemalloc -lgmp -ldl -lcrypt -lm
Run Code Online (Sandbox Code Playgroud)


tec*_*eet 5

更新@ste20654 答案

对我来说这个命令

ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"
Run Code Online (Sandbox Code Playgroud)

-lm
Run Code Online (Sandbox Code Playgroud)

有效的是这个

ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"
Run Code Online (Sandbox Code Playgroud)

或者

ruby -r rbconfig -e "puts RbConfig::CONFIG['SOLIBS']"
Run Code Online (Sandbox Code Playgroud)

返回(如果 ruby​​ 使用 jemalloc 正确编译)

-lz -lpthread -lrt -lrt -ljemalloc -lgmp -ldl -lcrypt -lm
Run Code Online (Sandbox Code Playgroud)