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

use with sinatra and don't block #2

Closed
jots opened this issue Jul 2, 2017 · 5 comments
Closed

use with sinatra and don't block #2

jots opened this issue Jul 2, 2017 · 5 comments

Comments

@jots
Copy link

jots commented Jul 2, 2017

I'm using falcon with sinatra (set :server, %w[falcon] ) and trying to get it to handle multiple requests in a non blocking fashion.

I have this route:

get "/r/:name" do |name|
  r = R.do_all(name) # this is blocking for about a second
  r.to_json
end

I test it with:
ab -c 10 -n 10 http://localhost:4567/r/name
I would expect that to take about 1 second, but it takes about 10.

Is there something else I need to do to make it not block?

@ioquatix
Copy link
Member

What does R.do_all do?

@tobidelius
Copy link

@jots just found this and after a quick peek it looks like it's only the IO operations that are run async, á la node.js :). That means that reading the file system, doing database calls etc will allow another fiber to do its work.

Would you mind describing what R.do_all is doing?

@ioquatix or perhaps I got it wrong?

@ioquatix
Copy link
Member

ioquatix commented Sep 2, 2017

@sandelius Even reading from the file system will block the entire reactor. There are trade-offs in the design of such a system and also limitations within Ruby itself. Ideally, we could yield while reading from the file system. In practice, network operations are the highest latency.

@tobidelius
Copy link

@ioquatix ahh sounds fair

@ioquatix
Copy link
Member

ioquatix commented Feb 2, 2018

It's trivial enough to design a thread pool to handle blocking / computational workloads, e.g.

https://github.com/socketry/async-process/blob/master/lib/async/process/child.rb

@ioquatix ioquatix closed this as completed Feb 2, 2018
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

3 participants