1

来自 CherryPy 邮件列表的交叉发布。

大家好,

我是cherrypy的新手,我正在尝试了解以下琐碎基准的结果。鉴于这个“hello world”应用程序:

import cherrypy

class Hello:
    @cherrypy.expose
    def index(self):
        return 'hello'

cherrypy.server.thread_pool = 50
cherrypy.quickstart(Hello())

我跑了ab -c 10 -n 1000,我得到了这些结果:

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 localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        CherryPy/3.2.4
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        5 bytes

Concurrency Level:      10
Time taken for tests:   4.494 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      143000 bytes
HTML transferred:       5000 bytes
Requests per second:    222.53 [#/sec] (mean)
Time per request:       44.938 [ms] (mean)
Time per request:       4.494 [ms] (mean, across all concurrent requests)
Transfer rate:          31.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  31.6      0     998
Processing:     2   16 183.1      5    4493
Waiting:        1   15 183.1      5    4492
Total:          2   17 185.7      5    4493

Percentage of the requests served within a certain time (ms)
  50%      5
  66%      7
  75%     11
  80%     13
  90%     18
  95%     21
  98%     24
  99%     25
 100%   4493 (longest request)

请注意,最长的请求需要超过 4 秒才能完成。鉴于我在应用程序中将线程数设置为 50,并且 ab 使用 10 个并发请求,我希望cherrypy 能够轻松处理它。我错过了什么?我尝试了不同的#threads 和并发请求,结果相似。我正在使用 CherryPy v.3.2.4

谢谢你的帮助,L。

4

1 回答 1

0

首先,您在与服务器 (localhost) 相同的机器上运行 ApacheBench。因此,它不是一个准确的基准,因为 ApacheBench 正在消耗它正在测试的同一台机器上的资源。

您的服务器受 CPU 限制吗?如果您受 CPU 限制,则 GIL(全局解释器锁)可能会咬您(CherrPy 使用多线程,而不是多处理)。这将导致您一次只使用一个 CPU 内核,并可能导致您看到的异常值。

运行基准测试时,始终检查被测服务器和负载生成机器上的资源(cpu、网络、磁盘等)。

更好的基准是:ab从具有快速网络连接到服务器的远程机器运行(确保机器在同一个 LAN 上,因此网络 I/O 不会影响太多,并运行 > 1000 个请求,这样你就可以获得测试时间超过 5 秒,让您有时间进行监控。

于 2013-10-07T21:01:14.893 回答