2012-07-16 116 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