我有一个rake task
,当我在控制台中运行它时,它是killed
。这个rake task
使用cca 40.000 rows
表运行,我想这可能是Out of memory的问题。
另外,我相信这个使用的查询已经过优化,可以处理长表:
MyModel.where(:processed => false).pluck(:attribute_for_analysis).find_each(:batch_size => 100) do |a|
# deal with 40000 rows and only attribute `attribute_for_analysis`.
end
此任务将来不会定期运行,因此我想避免使用某些工作监控解决方案,例如God
等...但考虑background jobs
例如Rescue job。
我使用Ubuntu
,ruby 2.0
和rails 3.2.14
> My free memory is as follows:
Mem: total used free shared buffers cached
3891076 1901532 1989544 0 1240 368128
-/+ buffers/cache: 1532164 2358912
Swap: 4035580 507108 3528472
问题:
rake task is always killed
(已回答)rake task
运行(未回答 - 仍被杀死)total-vm
,aton-rs
,file-rss
(未回答)更新1
- 有人解释?:
之间的区别
- 总-VM
- 匿名-RSS
- 文件RSS
$ grep "Killed process" /var/log/syslog
Dec 25 13:31:14 Lenovo-G580 kernel: [15692.810010] Killed process 10017 (ruby) total-vm:5605064kB, anon-rss:3126296kB, file-rss:988kB
Dec 25 13:56:44 Lenovo-G580 kernel: [17221.484357] Killed process 10308 (ruby) total-vm:5832176kB, anon-rss:3190528kB, file-rss:1092kB
Dec 25 13:56:44 Lenovo-G580 kernel: [17221.498432] Killed process 10334 (ruby-timer-thr) total-vm:5832176kB, anon-rss:3190536kB, file-rss:1092kB
Dec 25 15:03:50 Lenovo-G580 kernel: [21243.138675] Killed process 11586 (ruby) total-vm:5547856kB, anon-rss:3085052kB, file-rss:1008kB
更新2
rake task
仍被杀死。MyModel.where(:processed => false).find_in_batches do |group| p system("free -k") group.each do |row| # process end end