19

I have rails 4.2 + sidekiq on ubuntu setup and I'm starting my jobs with cron every hour with something like

bin/rails runner -e production 'MyJob.perform_later'

This basically take a job and puts data to redis, so that sidekiq could take it and start from there. But everytime i do this I have this spring proccesses stuck and waiting for something (consuming memory)

ps aux | grep spring
root      Sl   07:13   0:00 spring server | myapp | started 6 secs ago
root      Ssl  07:13   0:03 spring app    | myapp | started 6 secs ago | production mode

Sometimes I see like 10 of those. Is there any way not to start spring server?

Thank you.

Yanis
  • 4,847
  • 2
  • 17
  • 17

2 Answers2

29

If you want to keep spring in general, you can temporarily disable spring for a single command by prefixing it with the DISABLE_SPRING environment variable:

DISABLE_SPRING=1 bin/rails runner -e production 'MyJob.perform_later'
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
janfoeh
  • 10,243
  • 2
  • 31
  • 56
23

This happens because you are using the spring gem and your bin folder has been "springified".

If you take a look in the bin/rails file you will see that spring is loaded before moving on with running whatever you requested from it.

You could "un-springify" your bin folder by running

bin/spring binstub --remove --all

This would mean of course that you opt out from all performance benefits that spring provides you. This should be OK for production environments. In fact, it is recommended that you do not install spring in your production environments [1].

So I suggest that you modify your Gemfile and place spring under the development group. In production you usually do something like:

bundle install --without development test

That way spring will never make it to your production servers. See also this related issue on Github.

--

1 . Spring project readme file

Kostas Rousis
  • 5,918
  • 1
  • 33
  • 38