-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Agent shutdown adds 3 seconds to short scripts #1313
Comments
Hello, @jdelStrother! Great to hear from you! We're returning from a company-wide vacation and will triage this today. Thanks for your patience and your submission! |
Hi @jdelStrother! Thanks for pointing this out to us. I've re-categorize this as an enhancement/feature request since the three second wait time was deliberately programmed into the It doesn't seem like it's necessary in all cases and is considerably slowing down the shutdown process. I'll see if we can skip the loop if Resque instrumentation isn't installed. |
Actually, I'm starting to succumb to death-by-a-thousand-cuts, thinking of this issue every time I run a simple command like |
Interesting, the agent shouldn't be running during a command like Let me know if it is still using the default value and should be ignoring that task. If that is the case, I can look into what might be going on. |
Ah - How about |
Oh interesting, that makes sense! That change flew under our radar, we haven't made updates to adjust to that. I'll have to add a ticket to our backlog for us to look into making ignoring those tasks automatically work with Thor as well. We do have another config option to control when the agent starts,
Hopefully that helps! Let me know if you run into any issues with that, or if something isn't working as expected with this. |
Thanks - that looks promising, I'll give it a go |
Hi @jdelStrother and anyone else who comes across this issue. Regarding not wanting to have the agent start in certain CLI/TUI contexts such as when running This change will go out in a future agent release. In the meantime, Rails 7 users can update their # newrelic.yml
- # autostart.denylisted_constants: Rails::Console
+ autostart.denylisted_constants: Rails::Command::ConsoleCommand,Rails::Command::CredentialsCommand,Rails::Command::Db::System::ChangeCommand,Rails::Command::DbConsoleCommand,Rails::Command::DestroyCommand,Rails::Command::DevCommand,Rails::Command::EncryptedCommand,Rails::Command::GenerateCommand,Rails::Command::InitializersCommand,Rails::Command::NotesCommand,Rails::Command::RoutesCommand,Rails::Command::SecretsCommand,Rails::Console,Rails::DBConsole |
Work has been completed on this issue. |
FWIW I keep running into commands that still load the agent and so make them a lot slower than they should be. (eg For now I've just updated my bin/rails script so that it prevents NewRelic from starting, unless it's specifically running #!/usr/bin/env ruby
# frozen_string_literal: true
# Prevent NewRelic from starting when using one-off short commands like `bin/rails db:prepare`.
# (NewRelic adds 3 seconds to short scripts, which is annoying for stuff that might otherwise take 0.5 seconds
# https://github.com/newrelic/newrelic-ruby-agent/issues/1313)
if !["server", "s"].include?(ARGV[0])
ENV["NEW_RELIC_AGENT_ENABLED"] ||= "false"
end
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require "rails/commands" but it would be nice if StartWorkerThread didn't have this slow shutdown behaviour. |
Thanks for letting us know about the undesired behavior, @jdelStrother, and for the workaround too! Given that something like |
Hi @jdelStrother. PR #2623 should take care of |
Hi @jdelStrother, we had a bug report for 9.10.0. Including We decided to remove We're going to look more closely into how we can prevent the agent from starting with certain rake commands executed by Rails. The issue to track this work is: #2692 If you were relying on the default, we recommend you manually update
|
No problem, I'll continue disabling newrelic in our (Just to be clear, I have no issue with newrelic autostarting in any of our processes - even the short lived ones. If the 3 second pause on shutdown could be eliminated I'd happily just let newrelic start anywhere.) |
Description
When running a short-lived process, the newrelic agent shutdown often adds 3 seconds to the total runtime.
Without newrelic:
with newrelic:
Expected Behavior
NewRelic doesn't stall for 3 seconds while trying to shut down the agent thread.
The problem occurs here -
newrelic-ruby-agent/lib/new_relic/agent/agent/start_worker_thread.rb
Lines 43 to 51 in 2516b9b
connect
in deferred_work to complete. (On my machine,connect
takes around 1.1 seconds)Not sure of a clean fix that completely avoids race conditions... maybe
stop_event_loop
needs to loop a few times?pretty gross though, there must be a better way.
Impact
Low, those 3 seconds aren't going to kill me. It's just irritating when I run a script from the terminal, see it finish, but then have to sit there waiting like an idiot for newrelic to fail to kill its worker thread.
For Maintainers Only or Hero Triaging this bug
Suggested Priority (P1,P2,P3,P4,P5):
Suggested T-Shirt size (S, M, L, XL, Unknown):
The text was updated successfully, but these errors were encountered: