2012-07-16 114 views
1

掛我有這個Google Dart測試程序:一個簡單的飛鏢HTTP服務器上的Apache臺

#import('dart:io'); 

main() { 
    var s = new HttpServer(); 

    s.defaultRequestHandler = (HttpRequest req, HttpResponse res) { 
    res.statusCode = 200; 
    res.contentLength = 4; 
    res.outputStream.writeString("sup!!"); 
    res.outputStream.close(); 
    }; 

    s.listen('127.0.0.1', 80); 
    print('its up!'); 
} 

它適用於Chrome和Firefox罰款,我得到的SUP -messages。

然而,當我嘗試阿帕奇工作臺反對它,它掛起(ab掛起):

Z:\www>ab -n 1 -c 1 "http://127.0.0.1/" 
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 127.0.0.1 (be patient)...apr_poll: The timeout specified has expired (70007) 

您可以通過安裝Apache HTTP服務器找到ab,它會在bin文件夾下的定位。

在旁註:是否有一些其他基準測試工具類似ab,我可能會使用(並不掛)?

回答

3

這可能是contentLength的問題。你寫了4,但實際的內容長度是5.例如,如果ab看到contentLength,它可能會讀取4個字符並等待連接關閉。但是,連接可能不會關閉,因爲服務器正在等待寫入最後一個字符。客戶端和服務器都在等待某個東西,導致死鎖。

+0

這個,也調用'res.persistentConnection = false'這個技巧! – Tower 2012-07-16 18:58:39