image_optim icon indicating copy to clipboard operation
image_optim copied to clipboard

Cannot allocate memory - grep

Open leoluchini opened this issue 3 years ago • 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

leoluchini avatar Apr 18 '23 08:04 leoluchini

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.

toy avatar Apr 20 '23 21:04 toy