How to keep track of Resque workers in New Relic while working on Heroku?

We have an application that launches resok workers on Heroku. We installed the New Relic add-in, and according to docs, the new relic agent should automate the work of professionals. However, we do not see the output in the Background Jobs tab of the New Relic panel.

According to the same docs, we did not touch the newrelic.yml file. We do not know what is wrong and how to effectively debug it. What do we need to do?

+7
source share
3 answers

It turned out that our problem was caused by the presence of our own custom handlers, Resque.before_fork and Resque.after_fork .

The NewRelic RPM will automatically set the hooks using Resque.before_fork and Resque.after_fork to establish a communication channel for workers. As a restriction to Resque, it only runs the last assigned / Proc block for hook_name and after_fork. Thus, if you have your own custom bindings before_fork / after_fork, you must * configure the agent’s communication channel manually, for example. in config / initializers / custom_resque.rb file:

 Resque.before_fork do |job| NewRelic::Agent.register_report_channel(job.object_id) # extra custom stuff here end Resque.after_fork do |job| NewRelic::Agent.after_fork(:report_to_channel => job.object_id) # extra custom stuff here end 

This code is directly taken from the gem RPM file gems/newrelic_rpm-3.5.0/lib/new_relic/agent/instrumentation/resque.rb

RPM error update 12/27/2012:. After deploying the above methodology, we found that when using in a branched mode (for example, Resque) when accessing the RPM file, a file leak occurs. We have seen error messages like ActiveRecord::StatementInvalid: ArgumentError: too large fdsets: SET client_min_messages TO '' . After repeated searches, we found that this was because ActiveRecord was trying to open a database connection and could not, because the number of file descriptors was exhausted. A new relic has confirmed that an error occurs when questioning the plan of explanation. This happens when many Resque jobs are running that connect to the database.

Error update 1/28/2013: After a multiple head failure, we found out that this error was caused by an unsupported interaction with resque-lonely_job , which uses the Resque before_perform hook, which can stop the Resque job with the exception of Resque::Job::DontPerform . The RPM client does not properly clean up file leaks in this situation. The new Relic has been informed and is working on a fix.

Error Update 4/10/2013: This is fixed. We use 3.6.0.78, and it handles this case. No file descriptor leaks! Thank you, New Relic.

+11
source

I had the same problem because the New Relic agent did not start with my Resque workers. Therefore, I updated the resque:setup rake task to start the agent manually :

 task "resque:setup" => :environment do if ENV['NEW_RELIC_APP_NAME'] NewRelic::Agent.manual_start :app_name => ENV['NEW_RELIC_APP_NAME'] end end 
+4
source

Tried @trliner's suggestion, but I kept getting this error:

 rake aborted! undefined local variable or method `establish_connection' for ActiveRecord::Base:Class 

There is a simpler solution, just add NEWRELIC_ENABLE env to your heroku instance and everything should work:

 heroku config:set NEWRELIC_ENABLE=true 
+1
source

All Articles