Skip to content
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

PID not listening? #54

Open
shellandbull opened this issue Apr 26, 2016 · 4 comments
Open

PID not listening? #54

shellandbull opened this issue Apr 26, 2016 · 4 comments

Comments

@shellandbull
Copy link

shellandbull commented Apr 26, 2016

Hello! I have the following setup, using rails 4.0.6

def create
  require "rbtrace"
  pid    = Process.pid
  result = system("bundle exec rbtrace -u 5000 -p #{pid} -e 'load #{Rails.root}/script/heap_dump.rb'")
  render json: { status: result }
end
  • require "rbtrace" returns true
  • my Gemfile does not require the gem, i.e: gem "rbtrace", require: false

And I still get the following error:

Error: argument --pid (pid is not listening for messages, did you `require "rbtrace"`).

PID is defined and I'm running in a separate thread which I later then join to the main one, i.e:

# heap_dump.rb

Thread.new do
  require "objspace"
  # should rbtrace be required here?
  ObjectSpace.trace_object_allocations_start
  GC.start
  filename = "#{DateTime.now.strftime("%d-%^B-%Y")}-#{ENV["USER"]}-#{Rails.env.upcase}.json"
  ObjectSpace.dump_all(output: File.open(filename, "w"))

  s3 = Aws::S3::Resource.new(credentials: Aws::Credentials.new(ENV["AWS_ACCESS_KEY_ID"], ENV["AWS_SECRET_ACCESS_KEY"]),
                             region: "us-east-1")

  object = s3.bucket("memory-benchmarks").object(filename)
  object.upload_file(filename, acl: "authenticated-read")
end.join

Maybe I need to require rbtrace on the block passed to the new thread :) but if there's any known issues around requiring the library it would be good to know :)

I'm also using puma as my web server

@jamo
Copy link

jamo commented Apr 26, 2016

Just out of curiosity, have you tried with latest Rails version (or even lates 4.0.x series (4.0.13)

@tmm1
Copy link
Owner

tmm1 commented Apr 26, 2016

When you run system() it blocks the current process so it cannot listen to rbtrace messages. Invoking rbtrace from the current process to connect back to itself doesn't make much sense and is not recommended.

@shellandbull
Copy link
Author

@tmm1 what would be the best recommendation based on my intention?

@olivervbk-studiare
Copy link

olivervbk-studiare commented Jul 27, 2017

You could execute it with:
system("nohup bundle exec rbtrace -u 5000 -p #{pid} -e 'load #{Rails.root}/script/heap_dump.rb' &")
Though if you're running unicorn there seems to be a problem getting rbtrace to attach itself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants