Jython + Django 不适合生产环境?

11

最近我在Jython平台上尝试使用Django,并想要测试它在“生产”环境下的性能表现。我测试的网站只是一个简单的return HttpResponse("Time %.2f" % time.time())视图,没有涉及到数据库。

我尝试了以下两种组合(使用ab -c15 -n500 -k <url>进行测量,所有操作都在VirtualBox上运行的Ubuntu Server 10.10中):

  • J2EE应用服务器(Tomcat/Glassfish),部署WAR文件

    我得到了如下结果:

    Requests per second:    143.50 [#/sec] (mean)
    [...]
    Percentage of the requests served within a certain time (ms)
      50%     16
      66%     16
      75%     16
      80%     16
      90%     31
      95%     31
      98%    641
      99%   3219
     100%   3219 (longest request)
    

    显然,服务器偶尔会挂起几秒钟,这是不可接受的。我猜这与重新加载Jython有关,因为启动jython shell也需要大约3秒钟。

    使用修补过的flup包进行AJP服务(+ Apache作为前端)

    注意:flup是manage.py runfcgi使用的包,我不得不对其进行修补,因为flup的线程/分支支持似乎在Jython上无法工作(-> AJP是唯一可行的方法)。

    这里几乎有相同的结果,但有时最后100个请求甚至根本没有得到回答(但服务器进程仍然存活)。

    我在 SO 上提出这个问题(而不是 serverfault),因为这非常特定于 Django/Jython。有没有人在 Jython 上部署 Django 网站的经验?也许有其他更快的方法来提供网站?或者在 Java 平台上使用 Django 还为时过早?


2
永远不要在虚拟机上进行基准测试,尤其是延迟基准测试。 - Gintautas Miliauskas
1个回答

17

因为没有人回答,所以我进行了更深入的调查,似乎我的问题可能与VirtualBox有关。使用不同的服务器操作系统(Debian Squeeze、Ubuntu Server),我遇到了类似的问题。例如,在Debian上使用Apache Web服务器进行简单的静态文件服务时,我得到了以下结果:

> ab -c50 -n1000 http://ip.of.my.vm/some/static/file.css

Requests per second:    91.95 [#/sec] (mean)    <--- quite impossible for static serving
[...]
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2  22.1      0     688
Processing:     0  206 991.4     31    9188
Waiting:        0   96 401.2     16    3031
Total:          0  208 991.7     31    9203

Percentage of the requests served within a certain time (ms)
  50%     31
  66%     47
  75%     63
  80%     78
  90%    156
  95%    781
  98%    844
  99%   9141                            <--- !!!!!!
 100%   9203 (longest request)

这导致了一个结论,即(我没有结论,但是)我认为Java重新加载可能不是问题的原因,而是虚拟化。我将在真实的主机上尝试并暂不回答此问题。


后续

现在,我成功地测试了一个基本的Django站点(仅是欢迎页面),使用Jython + AJP通过TCP / mod_proxy_ajp在Apache上(再次使用修补过的flup软件包)。这次在一个真实的主机上(i7 920,6 GB RAM)。结果证明了我的假设是正确的,并且我真的不应该再在虚拟主机上进行基准测试。以下是欢迎页面的结果:

Document Path:          /jython-test/
Document Length:        2059 bytes

Concurrency Level:      40
Time taken for tests:   24.688 seconds
Complete requests:      20000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      43640000 bytes
HTML transferred:       41180000 bytes
Requests per second:    810.11 [#/sec] (mean)
Time per request:       49.376 [ms] (mean)
Time per request:       1.234 [ms] (mean, across all concurrent requests)
Transfer rate:          1726.23 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.5      0      20
Processing:     2   49  16.5     44     255
Waiting:        0   48  16.5     44     255
Total:          2   49  16.5     45     256

Percentage of the requests served within a certain time (ms)
  50%     45
  66%     48
  75%     51
  80%     53
  90%     69
  95%     80
  98%     90
  99%     97
 100%    256 (longest request)   # <-- no multiple seconds of waiting anymore

非常有前途,我会这样说。唯一的缺点是平均请求时间大于40毫秒,而开发服务器的平均值小于3毫秒。


@AndiDog,请问虚拟机的硬件配置是什么?(CPU数量,内存大小等) - Chedy2149
但是,为什么?如果为虚拟机分配了资源,它不应该造成如此大的差异。而且,大多数应用服务器都运行在虚拟机上,而不是裸机上。 - kravemir
注意这些基准测试是来自2011年,并且仅使用VirtualBox进行了测试,而不是其中的替代方案。可能今天差异要小得多。如果有人能提供更近期的基准测试将会很有趣。 - AndiDog

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接