4 ms·
Try making something that depends on an I/O resource that is really slow, that will give you more of a feeling for it quickly. I did this in one of my projects
by aarongough 16y ago
Try making something that depends on an I/O resource that is really slow, that will give you more of a feeling for it quickly.
I did this in one of my projects (Ajax-Gist.com) where I was directly querying a 3rd party API (GitHub) for each request. That meant that each request was client->server roundtrip time plus server->api roundtrip time, which worked out to be around 200ms, or a total throughput of 5 requests per second.
This is obviously unacceptable and a complete waste of resources so I re-wrote the whole thing to be asynchronous. The new application, running in a single thread on the same hardware can now handle around 70 requests per second with 30 concurrent users. That's pretty damn fast for a Rails application...
Now I didn't use Node to solve my problem (though I considered it!) but the principles and the message I took away was the same. I think it's a handy tool to have in your toolkit, but as you've already realized it's simply not necessary for a lot of projects, particularly smaller ones.
- mcantor 16y agoJust FYI, http://ajaxgist.com http://ajaxgist.com results in a 404. What library/technique did you end up using to make your app asynchronous?
- aarongough 16y agoHaha, I got my own domain name wrong! Clearly it's been a long day... Link: http://ajax-gist.com/ http://ajax-gist.com/ In the end I built what was essentially a proof-of-concept asynchronous Rails 3 application. The libraries I used under the hood to get everything async were: * Rack/Fiber-Pool: http://github.com/mperham/rack-fiber_pool http://github.com/mperham/rack-fiber_pool * EM Synchrony: http://github.com/igrigorik/em-synchrony http://github.com/igrigorik/em-synchrony * Eventmachine: http://rubyeventmachine.com/ http://rubyeventmachine.com/ Using Rails for what is essentially a thin proxy is overkill, and I could have gotten better performance with Node or by writing a Rack application directly. But I wanted to take the opportunity to get a handle on what would be involved with doing this in Rails, as not too many people have done it before that I am aware of (and at the time no-one had done it with Rails 3).
- mcantor 16y agoThanks! It sounds like you definitely blazed a couple of trails. Nicely done! I shall certainly peruse all of this; I appreciate the thorough response.
- aarongough 16y agoNo worries! I'm always happy to answer questions via email as well if need be.