toy/image_optim

Cannot allocate memory - grep

leoluchini opened this issue · 1 comments

Hi,

I'm doing a ruby migration (3.0.5) in the current system and when I run the specs I got an error. This call is inside a service and is called many times and couldn't find the explanation for this error

Failure/Error: @image_optim ||= ImageOptim.new(image_optim_config)
Errno::ENOMEM:
Cannot allocate memory - grep
# /usr/local/bundle/gems/image_optim-0.31.3/lib/image_optim/cmd.rb:44:in ``'
# /usr/local/bundle/gems/image_optim-0.31.3/lib/image_optim/cmd.rb:44:in `capture'
# /usr/local/bundle/gems/image_optim-0.31.3/lib/image_optim/config.rb:220:in `processor_count'
# /usr/local/bundle/gems/image_optim-0.31.3/lib/image_optim/config.rb:120:in `threads'
# /usr/local/bundle/gems/image_optim-0.31.3/lib/image_optim.rb:88:in `block in initialize'
# /usr/local/bundle/gems/image_optim-0.31.3/lib/image_optim.rb:87:in `each'
# /usr/local/bundle/gems/image_optim-0.31.3/lib/image_optim.rb:87:in `initialize'

This is the image_optim_config

{
  :skip_missing_workers=>true,
  :nice=>10,
  :advpng=>false,
  :gifsicle=>false,
  :jhead=>false,
  :jpegoptim=>false,
  :allow_lossy=>true,
  :oxipng=>false, 
  :jpegrecompress=>false, 
  :jpegtran=>{
    :copy_chunks=>false, 
    :progressive=>true, 
    :jpegrescan=>false
  }, 
  :optipng=>false, 
  :pngcrush=>false, 
  :pngout=>false, 
  :pngquant=>false, 
  :svgo=>false
}

I'm using version 0.31.3 for image_optim

toy commented

The command that is fails with the error is very simple grep -c processor /proc/cpuinfo and the error is clearly stating that there is no memory to run the command. So first question is if system is really low on memory, maybe worth checking what free (free -m) says before initialising ImageOptim. Otherwise maybe per process resource limit is reached then it is worth checking ruby process memory consumption.