Does rti/FastXml, or anything like it, work with rails 3 to speed-up xml rendering?

守給你的承諾、 提交于 2020-01-03 05:58:18

问题


We have a REST api implemented in rails 3, which is using the yajl back-end for json. It is currently generating json responses significantly faster than xml when serializing more than about 20 rows.

My next thought was that there must be a similar C-library drop-in for rail 3, which would use libxml or similar for to_xml, just as we're already using libyajl for to_json.

To date, I've found only the rti/FastXml project: https://github.com/rti/FastXml
It claims to be what I want, but hasn't been updated since early 2010, and has no visible forks.

Does anyone know if FasterXml works (or not) with rails 3?

More importantly, does anyone know any other ways to get rails 3 to do a faster render :xml => @search_results?

Many thanks for any help.


回答1:


Tests of a few rails 3 config options, via ab: XmlMini_LibXML, XmlMini_Nokogiri, fast_xs.

The following request returns about 50k of search results in the form of nested ruby hashes, with the data coming from memcached, so that the time differences here are in encoding the results into xml or json.

ab -n 100 -c 5 "http://DOMAIN/PATH.(xml|json)"

SUMMARY:
Adding gem fast_xs appears to cut XML time in half, others have no effect.

  1. JSON (yajl)

                  min  mean[+/-sd] median   max
    Connect:        0    1   2.7      0      20
    Processing:   159  453 188.6    387     994
    Waiting:      155  444 188.4    380     992
    Total:        160  454 188.6    387     995
    
  2. XML (rails 3.0.3 defaults)

                  min  mean[+/-sd] median   max
    Connect:        0    1   2.6      0      10
    Processing:   377 1256 337.5   1260    2612
    Waiting:      367 1233 335.7   1230    2597
    Total:        378 1258 337.3   1260    2613
    
  3. XML (XmlMini_LibXML)

                  min  mean[+/-sd] median   max
    Connect:        0    1   2.3      0      13
    Processing:   479 1217 233.8   1251    1830
    Waiting:      473 1188 235.3   1229    1826
    Total:        479 1218 234.0   1252    1835
    
  4. XML (XmlMini_Nokogiri)

                  min  mean[+/-sd] median   max
    Connect:        0    1   1.8      0      10
    Processing:   701 1211 228.1   1259    1654
    Waiting:      695 1197 224.8   1251    1650
    Total:        701 1212 228.4   1261    1655
    
  5. XML (defaults + fast_xs)

                  min  mean[+/-sd] median   max
    Connect:        0    1   1.9      0      10
    Processing:   243  656 233.1    702    1288
    Waiting:      238  627 236.7    585    1286
    Total:        250  657 233.3    702    1289
    
  6. XML (XmlMini_LibXML + fast_xs)

                  min  mean[+/-sd] median   max
    Connect:        0    1   1.8      0      10
    Processing:   256  685 222.6    704    1138
    Waiting:      234  650 229.5    661    1132
    Total:        257  686 222.7    705    1138
    
  7. XML (XmlMini_Nokogiri + fast_xs)

                  min  mean[+/-sd] median   max
    Connect:        0    2   3.9      0      23
    Processing:   210  657 224.7    714    1118
    Waiting:      206  610 229.9    607    1094
    Total:        210  659 225.0    716    1119
    
  8. JSON (yajl + fast_xs)

                  min  mean[+/-sd] median   max
    Connect:        0    1   1.8      0      11
    Processing:   153  442 197.1    396    1129
    Waiting:      148  435 196.3    391    1124
    Total:        153  442 197.3    398    1136
    


来源:https://stackoverflow.com/questions/5891507/does-rti-fastxml-or-anything-like-it-work-with-rails-3-to-speed-up-xml-renderi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!