【问题标题】:A simple Dart HTTP server hangs on Apache Bench一个简单的 Dart HTTP 服务器挂在 Apache Bench 上
【发布时间】:2012-07-16 16:58:30
【问题描述】:

我有这个Google Dart 测试程序:

#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 -消息。

但是,一旦我尝试使用 Apache Bench 来处理它,它就会挂起(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 的基准测试工具可供我使用(并且不会挂起)?

【问题讨论】:

    标签: http dart apachebench


    【解决方案1】:

    可能是 contentLength 的问题。您写了 4,但实际内容长度为 5。例如,如果 ab 看到 contentLength,它可能会读取 4 个字符并等待连接关闭。但是,连接可能不会关闭,因为服务器正在等待写入最后一个字符。客户端和服务器都在等待,导致死锁。

    【讨论】:

    • 这个,以及调用res.persistentConnection = false 成功了!
    猜你喜欢
    • 1970-01-01
    • 2014-08-31
    • 2011-02-12
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多