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

时间:2019-09-09 08:39:08

标签: ruby-on-rails ruby rvm jemalloc

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

Rails version:5.2 Ruby version:2.5.1

我尝试过

ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"

我得到的输出是

-lpthread -lgmp -ldl -lcrypt -lm

我看到了一篇文章Lower Memory Usage of your Rails App with Jemalloc,但它使用了rbenv

2 个答案:

答案 0 :(得分:1)

我设法通过以下步骤添加了jemalloc:

安装Jemalloc库:

sudo apt install libjemalloc-dev

使用编译参数重新安装当前安装的ruby版本,以包括Jemalloc支持:

rvm reinstall 2.5.1 -C -with-jemalloc

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

ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"

它应该输出如下内容:

-lpthread -ljemalloc -lgmp -ldl -lcrypt -lm

答案 1 :(得分:0)

更新为@ ste20654答案

对我来说,这个命令

ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"

返回

-lm

这是有效的

ruby -r rbconfig -e "puts RbConfig::CONFIG['MAINLIBS']"

OR

ruby -r rbconfig -e "puts RbConfig::CONFIG['SOLIBS']"

返回的结果(如果使用jemalloc正确编译了ruby)

-lz -lpthread -lrt -lrt -ljemalloc -lgmp -ldl -lcrypt -lm