Friday 15 July 2011

nginx - Delay in Rails send_data() procedure -



nginx - Delay in Rails send_data() procedure -

i have next piece of code in controller generates kml file:

def generate_kml links = link.all.where('status = 1') links_hash = {} links.each |link| if links_hash["#{link.siteid1}-#{link.siteid2}".to_sym] links_hash["#{link.siteid1}-#{link.siteid2}".to_sym][:count] += 1 links_hash["#{link.siteid1}-#{link.siteid2}".to_sym][:links] << link else links_hash["#{link.siteid1}-#{link.siteid2}".to_sym] = {} links_hash["#{link.siteid1}-#{link.siteid2}".to_sym][:count] = 1 links_hash["#{link.siteid1}-#{link.siteid2}".to_sym][:links] = [link] end end links.clear sites = {} links_hash.each_value |linklist| siteid1 = linklist[:links].first.siteid1 siteid2 = linklist[:links].first.siteid2 longitude1 = linklist[:links].first.longitude1 latitude1 = linklist[:links].first.latitude1 longitude2 = linklist[:links].first.longitude2 latitude2 = linklist[:links].first.latitude2 kml_string << "\n\n<folder>" kml_string << "\n<name> #{siteid1} - #{siteid2}</name>" if sites[siteid1] != true sites[siteid1] = true #place first point kml_string << "\n<placemark>\n<styleurl>#site_icon</styleurl>" kml_string << "\n <name> #{siteid1}</name>" #kml_string << "\n <description>#{site_properties link, 1}</description>" kml_string << "\n <visibility>1</visibility>" kml_string << "\n <point>" kml_string << "\n <coordinates>#{longitude1},#{latitude1}</coordinates>" kml_string << "\n </point>" kml_string << "\n</placemark>" end if sites[siteid2] != true sites[siteid2] = true #place sec point kml_string << "\n<placemark>\n<styleurl>#site_icon</styleurl>" kml_string << "\n <name> #{siteid2}</name>" #kml_string << "\n <description>#{site_properties link, 2}</description>" kml_string << "\n <visibility>1</visibility>" kml_string << "\n <point>" kml_string << "\n <coordinates>#{longitude2},#{latitude2}</coordinates>" kml_string << "\n </point>" kml_string << "\n</placemark>" end points = generate_points(latitude1, longitude1, latitude2, longitude2, linklist[:links].size) line_count=0 linklist[:links].each |link| #draw line kml_string << "\n<placemark>" kml_string << "\n <name> #{siteid1} - #{siteid2}</name>" kml_string << "\n <description>#{link_properties link}</description>" kml_string << "<styleurl> #working_link_line#{line_count+1}</styleurl>" kml_string << "\n <linestring>" kml_string << "\n <altitudemode>clamptoground</altitudemode>" kml_string << "\n <coordinates>#{points[line_count][0]},#{points[line_count][1]} #{points[line_count+1][0]},#{points[line_count+1][1]},0</coordinates>" kml_string << "\n </linestring>" kml_string << "\n</placemark>" line_count += 1 end kml_string << "\n</folder>" end links_hash.clear send_data kml_string, :type => 'charset=utf-8; text/xml', :disposition => "attachment; filename=kmlfile.kml" end

the size of file 2.87 mb.

the problem: when invoke generate_kml procedure clicking link action in controller, nil happens. can't see progress in status bar, or indication file download has been started. after 10 seconds, file downloaded instantly. happens when run application locally on mac.

but when deploy application on 1 of our (powerful) local servers (on lan ubuntu server + nginx + phusion passenger), delay takes more longer time (about 60 seconds) before same kml (of same size) downloaded instantly.

does have thought going on , possible workaround?

never mind, solved problem. want share in case encounters similar problem.

the bottleneck our proxy. added ip address of rails application server (where application resides) list of exceptions (bypass-proxy list) browser, , worked charm, took 5 seconds generate , download file.

ruby-on-rails-4 nginx passenger

No comments:

Post a Comment