工作人员完成后,Sidekiq不会释放内存 [英] Sidekiq not deallocating memory after workers have finished
问题描述
我有大约六个Sidekiq工人,它们执行 JSON爬网.根据端点的数据集大小,它们在1分钟至4小时之间结束.尤其是,观看耗时4小时的长记录,我发现记忆随着时间的推移会略有增加.
这不是问题,直到我想再次安排相同的工人作业.直到我遇到Linux OOM Killer之后,内存才被释放并堆积,这使我的Sidekiq进程摆脱了.
内存泄漏?我看到了ObjectSpace中不同对象的数量:
ObjectSpace.each_object.inject(Hash.new(0)) { |count, o| count[o.class] += 1 }
那里实际上并没有增加,散列,数组等的集合保持不变,垃圾收集器清除了短暂的增加,并且gc.stat[:count]
告诉我,垃圾收集器也在工作. /p>
即使在工作人员完成后,例如我记录了 [完成] ,不再有工作人员忙,内存也没有释放.是什么原因呢?我可以为此做些什么吗?写一个终结器?
唯一的当前解决方案:重新启动Sidekiq进程.
我正在使用Ruby 2.0.0,并使用Ruby MRI.
对于JSON解析,我使用 Yajl ,因此是C绑定.我需要它,因为它似乎是唯一可以正确实现流式读写的快速JSON解析器.
撰写Sidekiq的迈克·佩勒姆在这里解决了此问题: Ruby企业版.
不知道这有什么帮助,但是就是这种情况-直接从马口中出来.
I have about six Sidekiq worker which perform JSON crawling. Dependent on the endpoint's dataset size they finish between 1min and 4h. Especially, watching the long one, which takes 4h, I see a very slight increase of memory over time.
It's not a problem, until I want to schedule the same worker jobs again. The memory is not deallocated and stacks up, until I run into the Linux OOM Killer which gets rid of my Sidekiq process.
Memory leak? I watched the number of different objects in ObjectSpace:
ObjectSpace.each_object.inject(Hash.new(0)) { |count, o| count[o.class] += 1 }
There is not really an increase there, the set of hashes, arrays, etc. stays the same, short increases are swept away by the Garbage Collector and gc.stat[:count]
tells me, that the Garbage Collector is working, too.
Even after the worker finishes, e.g. I get the [Done] logged and no workers are busy any more, the memory is not deallocated. What are the reasons for that? Can I do something against this? Write a finalizer?
The only current solution: Restart the Sidekiq process.
I am on Ruby 2.0.0 and use Ruby MRI.
For the JSON parsing I use Yajl, thus a C binding. I need it because it seems the only fast JSON parser that properly implements streamed reading and writing.
Mike Perham who wrote Sidekiq addressed this here: http://www.mikeperham.com/2009/05/25/memory-hungry-ruby-daemons/
tl;dr version: MRI will not give the memory back, the most you can do is control the heap, and to do that, Ruby Enterprise Edition was suggested.
Don't know that any of this helps, but that is the situation - straight from the horse's mouth.
这篇关于工作人员完成后,Sidekiq不会释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!