我的服务器出现了内存泄漏问题(在rails上使用ruby编写) 我想实现一个临时解决方案,在内存超出时自动重启dynos。做这个的最好方式是什么?它有风险吗?
答案 0 :(得分:3)
如果您将Puma用作服务器,那么有一个很好的解决方案。
https://github.com/schneems/puma_worker_killer
当RAM超过某个阈值时,您可以重新启动服务器:
例如:
PumaWorkerKiller.config do |config|
config.ram = 1024 # mb
config.frequency = 5 # seconds
config.percent_usage = 0.98
config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds
end
PumaWorkerKiller.start
另外,为了防止数据库中存在数据损坏和其他有趣问题,我还建议您确保使用原子事务。