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

Async::Reactor#run_once time #143

Open
tleish opened this issue Oct 5, 2023 · 2 comments
Open

Async::Reactor#run_once time #143

tleish opened this issue Oct 5, 2023 · 2 comments

Comments

@tleish
Copy link

tleish commented Oct 5, 2023

In testing moving a Goliath/EventMachine app to Falcon/Async, we found that request using async-http was a bit slower. In profiling async-http, I noticed 89% of the time was taken in Async::Reactor#run_once. It's not clear to me if this is just waiting for the HTTP response or if something else is going on. If waiting for response, the response from httpbin.org averages 62ms, where Async::Reactor#run_once takes approximately 260ms.

profile-1696534166_flamegraph

ruby 2.7
async-http 0.60.2
async 1.31.0

require 'async'
require 'async/http/internet'
require 'ruby-prof-flamegraph'

def ruby_prof_wrapper
  RubyProf.start

  results = yield

  result = RubyProf.stop
  printer = RubyProf::FlameGraphPrinter.new(result)

  dir = File.dirname(__FILE__)
  file = File.join(dir, "profile-#{Time.now.to_i}.data")
  File.open(file, 'w') {|file| printer.print(file)}
  results
end

data = {'life' => 42}

Async do
  internet = nil
  ruby_prof_wrapper do
    # Make a new internet:
    internet = Async::HTTP::Internet.new
  
    # Prepare the request:
    headers = [['accept', 'application/json']]
    body = [JSON.dump(data)]
  
    # Issues a POST request:
    response = internet.post("https://httpbin.org/anything", headers, body)
  
    # Save the response body to a local file:
    pp JSON.parse(response.read)
  end
ensure
  # The internet is closed for business:
  internet.close
end
@ioquatix
Copy link
Member

ioquatix commented Oct 5, 2023

Thanks, I'll take a look. I don't think we expect to see a significant difference, so there may be a performance regression. The sample code is useful.

@tleish
Copy link
Author

tleish commented Oct 5, 2023

FYI, if you right-click and download the SVG from github to your local machine, you can then open the interactive flamgraph in your browser to see better details.

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

2 participants