简体   繁体   中英

large json data return issue

I have a controller action which returns a json structure.

render :json => hash_data

It works for a small dataset in both production and development modes. However, for a large dataset, this only works in development mode. In production mode, only part of json string is returned. Rails version is 3.0.9. In production mode: it goes from a load balancer to nginx; in development mode: I use webrick.

Production Mode Http Response Header:

Cache-Control   max-age=0, private, must-revalidate                                                                                                                                                  
Connection      close                                                                                                                                                                                
Etag            "a7b077a364f849a57ffe582525c98ea1"                                                                                                                                                   
Server          nginx/1.0.10 + Phusion Passenger 3.0.11 (mod_rails/mod_rack)                                                                                                                         
Status          304                                                                                                                                                                                  
X-Powered-By    Phusion Passenger (mod_rails/mod_rack) 3.0.11                                                                                                                                        
X-Runtime       8.462971                                                                                                                                                                             
X-UA-Compatible IE=Edge,chrome=1

Development Mode Http Response Header:

Cache-Control max-age=0, private, must-revalidate                                                                                                                                                    
Connection Keep-Alive                                                                                                                                                                                
Content-Length 144561                                                                                                                                                                                
Content-Type application/json; charset=utf-8                                                                                                                                                         
Date Tue, 20 Mar 2012 08:37:30 GMT                                                                                                                                                                   
Etag "b6b9cdb7811577280320f7a3f50bd937"                                                                                                                                                              
Server WEBrick/1.3.1 (Ruby/1.9.2/2010-08-18)                                                                                                                                                         
X-Runtime 12.832829                                                                                                                                                                                  
X-UA-Compatible IE=Edge 

Even more strange, Chrome works fine for both production and development mode with large dataset. But all other browsers don't work. Any help will be greatly appreciated.

Try thin . You can proxy requests to a Thin backend and still use nginx.

AFAIK from your post and experience with Facebook ETag, you are receiving "304 Not modified" because:

  1. You are sending "HTTP_IF_NONE_MATCH" header from your request in production server
  2. and your record has not been changed.

Your request only gets 200 response if server-side etag does not match to the etag value in Http-If-None-Match. If matches, you will get "304 Not modified"

I guess the production env. turned on etag, and develop env, did not.

You may take a look at this, http://archives.ryandaigle.com/articles/2008/8/14/what-s-new-in-edge-rails-simpler-conditional-get-support-etags

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM