Rails 4 how to speed up json processing

I have 1,500 small rendering objects for a web service inside a rails 4 application. I use json as a format with jbuilder for templates. I already changed the json engine to oj in the application initializer:

require 'oj_mimic_json' #MultiJson.use :yajl Oj.mimic_JSON # jbuilder json templates Jbuilder.key_format camelize: :lower 

one processed json object is as follows:

 center: {lat: 45.962153536249, lon: 7.68207088549831} lat: 45.962153536249 lon: 7.68207088549831 n: "Zermatt-Cervinia" st: 80 sy: 0 Rendered json_partials/_snow_in_resort.json.jbuilder (0.5ms) Rendered json_partials/_snow_in_resort.json.jbuilder (0.5ms) .... Rendered resorts/find.json.jbuilder (4213.4ms) Completed 200 OK in 4351ms (Views: 3924.3ms | ActiveRecord: 306.8ms | Solr: 0.0ms) 

But still I need 150 ms for 101 kb on my local host, which is too slow for the task that I want to perform in the user interface. What do I need to do to accelerate here? What things should I check? I appreciate the help. Best Philip

Update

I optimized my active record requests to ActiveRecord: 77.8ms, but rendering rendering is still too slow

+8
performance json ruby-on-rails-4 rendering jbuilder
source share
1 answer

You can explore the use of HTTP caching using Varnish. Here's a great article describing various caching techniques (fragment caching, HTTP caching, etc.) in Rails 4. It has a good explanation when caching JSON responses.

Rails 4 and Caching

http://www.slatestudio.com/blog/p/caching-in-rails-4-applications

Here is another one of Rails and Varnish

http://www.hward.com/scale-rails-with-varnish-http-caching-layer/

lacquer popular pearl with insert support for lacquer caching in rails

If you want to learn more about what HTTP caching is, here is a really good entry.

https://www.mnot.net/cache_docs/

Ryan Bates has a great Rails Cast tutorial, but this is Pro Episode

http://railscasts.com/episodes/321-http-caching

 UPDATE 

Geocoder gem

Based on some of the comments below, I would suggest exploring the use of the Geocoder gem. It has been a while and is very well optimized for searching by interests, like what you are trying to do. It is also much more.

Spatial Index If you have already tried this and are not satisfied, can you post some information about which optimizations you use in your database to speed up the query? Can you speed up a POI query significantly using spatial indexes in a table?

Here's a good article on spatial indexes:

http://daniel-azuma.com/articles/georails/part-6

Some performance testing ideas

You might be able to check if this is really a rendering that slows you down by coming up with a good test case. Try querying things at the top, middle, and bottom of the point table. Also for a different number of response objects in your JSON and a different number of properties in your JSON. Right now I see that lat, lon is redundant. Try to remove them and compare the time for a huge amount of results, if it is really a rendering that slows you down, fewer properties, faster answers you should see.

Also, if your properties, (name, st, sy, etc.) come from relationships instead of the same table as dots, try de-normalizing your database to see if you have a faster rendering view .

+6
source share

All Articles