2012-02-12 9 views
12

मैं रूबी (1.9.3-पी 0) में समेकन के साथ खेल रहा हूं, और एक बहुत ही सरल, I/O-भारी प्रॉक्सी कार्य बनाया है। सबसे पहले, मैंने गैर-अवरुद्ध दृष्टिकोण की कोशिश की:रूबी समरूपता: गैर-अवरुद्ध I/O बनाम धागे

require 'rack' 
require 'rack/fiber_pool' 
require 'em-http' 
require 'em-synchrony' 
require 'em-synchrony/em-http' 

proxy = lambda {|*| 
    result = EM::Synchrony.sync EventMachine::HttpRequest.new('http://google.com').get 
    [200, {}, [result.response]] 
} 

use Rack::FiberPool, :size => 1000 
run proxy 

=begin 
$ thin -p 3000 -e production -R rack-synchrony.ru start 
>> Thin web server (v1.3.1 codename Triple Espresso) 

$ ab -c100 -n100 http://localhost:3000/ 
Concurrency Level:  100 
Time taken for tests: 5.602 seconds 
HTML transferred:  21900 bytes 
Requests per second: 17.85 [#/sec] (mean) 
Time per request:  5602.174 [ms] (mean) 
=end 

हम्म, मैंने सोचा कि मुझे कुछ गलत करना होगा। एक कार्य के लिए 5.6 का औसत अनुरोध समय जहां हम अधिकतर I/O की प्रतीक्षा कर रहे हैं? मैंने एक और कोशिश की:

require 'sinatra' 
require 'sinatra/synchrony' 
require 'em-synchrony/em-http' 

get '/' do 
    EM::HttpRequest.new("http://google.com").get.response 
end 

=begin 
$ ruby sinatra-synchrony.rb -p 3000 -e production 
== Sinatra/1.3.1 has taken the stage on 3000 for production with backup from Thin 
>> Thin web server (v1.3.1 codename Triple Espresso) 

$ ab -c100 -n100 http://localhost:3000/ 
Concurrency Level:  100 
Time taken for tests: 5.476 seconds 
HTML transferred:  21900 bytes 
Requests per second: 18.26 [#/sec] (mean) 
Time per request:  5475.756 [ms] (mean) 
=end 

हम्म, थोड़ा बेहतर, लेकिन मैं सफलता नहीं कहूंगा। आखिरकार, मैंने थ्रेडेड कार्यान्वयन की कोशिश की:

require 'rack' 
require 'excon' 

proxy = lambda {|*| 
    result = Excon.get('http://google.com') 
    [200, {}, [result.body]] 
}  
run proxy 

=begin 
$ thin -p 3000 -e production -R rack-threaded.ru --threaded --no-epoll start 
>> Thin web server (v1.3.1 codename Triple Espresso) 

$ ab -c100 -n100 http://localhost:3000/ 
Concurrency Level:  100 
Time taken for tests: 2.014 seconds 
HTML transferred:  21900 bytes 
Requests per second: 49.65 [#/sec] (mean) 
Time per request:  2014.005 [ms] (mean) 
=end 

वास्तव में, वास्तव में आश्चर्यजनक था। क्या मुझसे कोई चूक हो रही है? ईएम इतनी बुरी तरह प्रदर्शन क्यों कर रहा है? क्या मुझे कुछ ट्यूनिंग करने की ज़रूरत है? मैंने विभिन्न संयोजनों (यूनिकॉर्न, कई इंद्रधनुष विन्यास, इत्यादि) की कोशिश की, लेकिन उनमें से कोई भी सरल, पुराने I/O-blocking थ्रेडिंग के करीब भी नहीं आया।

विचार, टिप्पणियां और - जाहिर है - बेहतर कार्यान्वयन के लिए सुझावों का बहुत स्वागत है।

+1

आप परीक्षण के लिए एक दूर के सर्वर का उपयोग नहीं करना चाहिए, विलंबता भिन्न हो सकते हैं। आपको कम फाइबर के साथ एसिंक टेस्ट फिर से प्रयास करना चाहिए, 20 फाइबर के साथ मुझे 300 एमएस/अनुरोध बनाम 1s/1000 सटीक एबी लाइन का उपयोग करके 1000 फाइबर के साथ अनुरोध मिलता है। आपका थ्रेडेड सर्वर डिफ़ॉल्ट इवेंटमैचिन थ्रेड पूल का उपयोग कर रहा है जो डिफ़ॉल्ट रूप से 20 धागे हैं। – Schmurfy

+0

सुनिश्चित नहीं है, फाइबर पूल आकार को 20 तक सेट करना वास्तव में मेरे बॉक्स पर प्रदर्शन को कम करता है। – BSM

+0

शायद 20 नहीं, लेकिन 1000 वास्तव में उच्च है, मैंने स्थानीय सर्वर के साथ परीक्षण किया ताकि प्रतिक्रिया समय वास्तव में कम हो। – Schmurfy

उत्तर

2

देखें कि आपका "समय प्रति अनुरोध" कुल "परीक्षण के लिए समय" के बराबर है? यह आपके अनुरोध गणना (-एन) के कारण आपके समवर्ती स्तर (-सी) के बराबर होने के कारण अंकगणितीय आर्टिफैक्ट की रिपोर्टिंग है। औसत समय कुल समय * समरूपता/संख्या-अनुरोध है। तो रिपोर्ट का मतलब है कि -n == -c सबसे लंबे अनुरोध का समय होगा। आपको उचित उपायों के लिए कई कारकों से -n> -c के साथ अपना एबी रन चलाना चाहिए।

आप अपेक्षाकृत वर्तमान रिपोर्ट के रूप में अब के पुराने संस्करण का उपयोग कर रहे हैं डिफ़ॉल्ट रूप से कहीं अधिक विस्तृत परिणाम। Google के खिलाफ सीधे चल रहा है मैं इसी तरह के कुल-समय == औसत समय दिखाता हूं जब -n == -c, और -n> -c पर अधिक उचित संख्याएं प्राप्त करें। आप वास्तव में सभी समवर्ती अनुरोधों के बीच req/sec, और बेहतर समझने के लिए अंतिम सेवा स्तर के टूटने को देखना चाहते हैं।

$ ab -c50 -n50 http://google.com/ 
This is ApacheBench, Version 2.3 <$Revision: 655654 $> 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ 
Licensed to The Apache Software Foundation, http://www.apache.org/ 

Benchmarking google.com (be patient).....done 


Server Software:  gws 
Server Hostname:  google.com 
Server Port:   80 

Document Path:  /
Document Length:  219 bytes 

Concurrency Level:  50 
Time taken for tests: 0.023 seconds   <<== note same as below 
Complete requests:  50 
Failed requests:  0 
Write errors:   0 
Non-2xx responses:  50 
Total transferred:  27000 bytes 
HTML transferred:  10950 bytes 
Requests per second: 2220.05 [#/sec] (mean) 
Time per request:  22.522 [ms] (mean)  <<== note same as above 
Time per request:  0.450 [ms] (mean, across all concurrent requests) 
Transfer rate:   1170.73 [Kbytes/sec] received 

Connection Times (ms) 
       min mean[+/-sd] median max 
Connect:  1 2 0.6  3  3 
Processing:  8 9 2.1  9  19 
Waiting:  8 9 2.1  9  19 
Total:   11 12 2.1  11  22 
WARNING: The median and mean for the initial connection time are not within a normal deviation 
     These results are probably not that reliable. 

Percentage of the requests served within a certain time (ms) 
    50%  11 
    66%  12 
    75%  12 
    80%  12 
    90%  12 
    95%  12 
    98%  22 
    99%  22 
100%  22 (longest request)  <<== note same as total and mean above 


$ ab -c50 -n500 http://google.com/ 
This is ApacheBench, Version 2.3 <$Revision: 655654 $> 
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ 
Licensed to The Apache Software Foundation, http://www.apache.org/ 

Benchmarking google.com (be patient) 
Completed 100 requests 
Completed 200 requests 
Completed 300 requests 
Completed 400 requests 
Completed 500 requests 
Finished 500 requests 


Server Software:  gws 
Server Hostname:  google.com 
Server Port:   80 

Document Path:  /
Document Length:  219 bytes 

Concurrency Level:  50 
Time taken for tests: 0.110 seconds 
Complete requests:  500 
Failed requests:  0 
Write errors:   0 
Non-2xx responses:  500 
Total transferred:  270000 bytes 
HTML transferred:  109500 bytes 
Requests per second: 4554.31 [#/sec] (mean) 
Time per request:  10.979 [ms] (mean) 
Time per request:  0.220 [ms] (mean, across all concurrent requests) 
Transfer rate:   2401.69 [Kbytes/sec] received 

Connection Times (ms) 
       min mean[+/-sd] median max 
Connect:  1 1 0.7  1  3 
Processing:  8 9 0.7  9  13 
Waiting:  8 9 0.7  9  13 
Total:   9 10 1.3  10  16 

Percentage of the requests served within a certain time (ms) 
    50%  10 
    66%  11 
    75%  11 
    80%  12 
    90%  12 
    95%  13 
    98%  14 
    99%  15 
100%  16 (longest request) 
संबंधित मुद्दे