Why Sinatra request takes EM thread?

不打扰是莪最后的温柔 提交于 2019-12-02 04:33:06
gpavlidi

Ok, so it seems Sinatra starts Thin in threaded mode by default causing the above behavior. You can add

set :threaded, false

in your Sinatra configure section and this will prevent the Reactor defering requests on a separate thread, and blocking when under load.

Source1

Source2

muffinista

Unless I'm misunderstanding something about your question, this is pretty much how EventMachine works. If you check out the docs for EM.defer, they state:

Don't write a deferred operation that will block forever. If so, the current implementation will not detect the problem, and the thread will never be returned to the pool. EventMachine limits the number of threads in its pool, so if you do this enough times, your subsequent deferred operations won't get a chance to run.

Basically, there's a finite number of threads, and if you use them up, any pending operations will block until a thread is available.

It might be possible to bump threadpool_size if you just need more threads, although ultimately that's not a long-term solution.

Is Sinatra multi threaded? is a really good question here on SO about Sinatra and threads. In short, Sinatra is awesome but if you need decent threading you might need to look elsewhere.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!