ruby - How to run two functions concurrently from one route in Sinatra? -
i'm trying understand ruby concurrency sinatra app. here is:
require 'sinatra' '/a' sleep 10 "result_a" end '/b' "result_b" end if run ruby app.rb or shotgun app.rb , go both /a , /b - /b not loaded until /a executes , loads itself. when deploy app heroku though, , go /a /b, /b loaded immediately. understand it, heroku process concurrent (or multithreaded?) opposed local processes.
my questions are: how run app concurrently on local server? possible run, eg, 2 functions concurrently 1 route?
install unicorn.
gem install unicorn the official docs aren't great can find plenty of tutorials showing how configure , start parallel server processes allow serve multiple requests concurrently.
it works forking process, means it's thread-safe, means concurrent requests won't share memory state each other. in fact, won't share memory @ all, if app has enormous memory footprint (e.g. kind of in-memory database) need different solution. otherwise, unicorn popular , reliable concurrency tool ruby web apps; may allowing heroku exhibit concurrency you're seeing.
ruby multithreading heroku concurrency sinatra
No comments:
Post a Comment