High load RESTful API in Ruby (sync / async implementation)

I am struggling with implementing a RESTful API that should return a JSON response and must support a very high load. The largest load will be generated by the "read" part of the API, and the very small load will be generated by the "write" part of the API. My first attempt was to write an entire API using nodejs. I almost did this, but came across a very large duplication of models and logic between javascript and ruby, because the API is part of a larger system. I tried moving all the logic to the backend (mySql), but this idea turned out to be even more ugly. My second attempt is to write an API in the Ruby ecosystem to share models / logic and tests between all parts of the system.

I tried to use Cramp and Goliath myself, but all these asynchronous things really complicated the implementation of the API. I only need 2 reads of asynchronous URLs, because they generate the highest load and, going to async completely, I was forced to implement the rest of the API in asynchronous mode, which did not add any value.

My current attempt is to go for a hybrid: use the Slim / Sinatra / Handbag cocktail. I create a Thin rack descriptor directly in the Ruby code and use the rack designer. I share the API between Sinatra, which performs synchronization, and Cramp, which implements 2 URLs in an asynchronous way.

Is this a good way to go? Or using Sinatra and Cramp on the same web server (Thin) for some reason I get even more trouble?

update: I am trying to solve with a single Sinatra mixed with rack / fiber_pool and em_mysql2. I seem to be killing two targets - creating an asynchronous API with a synchronization implementation. But I suffer from a mistake that I think will be fixed soon enough.

Have there been any problems with this path?

+4
source share
2 answers

I don’t think it’s nice to have synchronization (sinatra) and asynchronous applications in the same subtle process. If the synchronization part is relatively simple, I would suggest implementing this in Cramp. A bit biased here when I created Cramp :)

In case you did not know, Cramp has box support for AR / fiber pool - https://github.com/lifo/cramp/blob/master/examples/fibers/long_ar_query.ru

If you decide to use Cramp, I will be happy to help with any problems, since recently I worked a lot on cramp and pretty much pumped up! Just drop me a letter!

+6
source

I'm curious what kind of asynchronous things did you encounter with Goliath? In general, there should be no asynchronous code visible to the end developer.

Is there something we can do better to make it less visible to the end user?

0
source

All Articles