ruby-on-railsnginxhigh-load

Highload rails server with backgrounder architecture


Here is my task. Every second backgrounder task should generate json based on some data. This operation is not cpu intensive ( mostly network) and it generates JSON content (5-10KB). Operations take about 200ms.

Also I have about 1000 clients asking for this content once every few seconds. Let's say it's about 200 requests/sec.

Server should just output current actual json.

Currently i already have rails 4+nginx+passenger+debian sever doing other jobs, related to this work.

Being a student I want to make my server in a most cost-effective way having an ability to easy-scale in this ways:

  1. Adding few more backgrounder jobs, generating more json's
  2. Increasing number of requests to 10 000 per second

Currently I have linode 2048 ssd with 2 CPU Cores. My questions are:

  1. What gem/solution should I use for my backgrounder tasks ( the are currently written in ruby )
  2. How to effectivly store actual json and pass it from backgrounder(s) to rails/nginx.
  3. How to make serving json as fast as possible.

Solution

  • you mentioned "Server should just output current actual json", I guess the JSON generation may not become a bottleneck as you can cache it to Memcache and serve Memcache directly:

    1) Periodically background process -> dump data to Memcache (even gzip to speed it up)

    2) User -> Nginx -> Memcache

    See the Nginx memcache built in module http://nginx.org/en/docs/http/ngx_http_memcached_module.html

    The bottleneck is any backend with blocking mechanism, GIL, IO locks etc, try to avoid these type of problems by split request/response cycle with intermediate Memcache data point.