免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2029 | 回复: 1
打印 上一主题 下一主题

pypy 有这么差吗?? 原因在哪? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-04 00:47 |只看该作者 |倒序浏览
这是用webpy 写的helloworld ,用siege做压力测试
import web

urls = ("/.*","hello")

app = web.application(urls, globals())



class hello():
    def GET(self):
        return "Hello World!!"


if __name__ == "__main__":
    app.run()


siege -c 200 -t 10s http://127.0.0.1:8080/

#python  index2.py
Lifting the server siege...      done.
Transactions:                        3388 hits
Availability:                      100.00 %
Elapsed time:                        9.51 secs
Data transferred:                0.04 MB
Response time:                        0.07 secs
Transaction rate:              356.26 trans/sec
Throughput:                        0.00 MB/sec
Concurrency:                       25.07
Successful transactions:        3388
Failed transactions:                   0
Longest transaction:                2.74
Shortest transaction:                0.00

#pypy index2.py
Lifting the server siege...      done.
Transactions:                        1170 hits
Availability:                       99.41 %
Elapsed time:                        9.24 secs
Data transferred:                0.05 MB
Response time:                        0.63 secs
Transaction rate:              126.62 trans/sec
Throughput:                        0.01 MB/sec
Concurrency:                       80.19
Successful transactions:        1170
Failed transactions:                   7
Longest transaction:                7.35
Shortest transaction:                0.00


siege -c 200 -t 20s http://127.0.0.1:8080/

#python index2.py
Lifting the server siege...      done.
Transactions:                        6222 hits
Availability:                       99.27 %
Elapsed time:                       19.12 secs
Data transferred:                0.08 MB
Response time:                        0.07 secs
Transaction rate:              325.42 trans/sec
Throughput:                        0.00 MB/sec
Concurrency:                       23.18
Successful transactions:        6222
Failed transactions:                  46
Longest transaction:                5.45
Shortest transaction:                0.00


#pypy index2.py
Lifting the server siege...      done.
Transactions:                        2426 hits
Availability:                       98.66 %
Elapsed time:                       19.62 secs
Data transferred:                0.08 MB
Response time:                        0.89 secs
Transaction rate:              123.65 trans/sec
Throughput:                        0.00 MB/sec
Concurrency:                      109.63
Successful transactions:        2426
Failed transactions:                  33
Longest transaction:               17.71
Shortest transaction:                0.00


siege -c 400 -t 10s http://127.0.0.1:8080/

#python index2.py
Lifting the server siege...      done.
Transactions:                        2935 hits
Availability:                      100.00 %
Elapsed time:                        9.13 secs
Data transferred:                0.04 MB
Response time:                        0.59 secs
Transaction rate:              321.47 trans/sec
Throughput:                        0.00 MB/sec
Concurrency:                      188.88
Successful transactions:        2935
Failed transactions:                   0
Longest transaction:                8.37
Shortest transaction:                0.00

#pypy  index2.py
Lifting the server siege...      done.
Transactions:                        1246 hits
Availability:                       96.07 %
Elapsed time:                        9.51 secs
Data transferred:                0.02 MB
Response time:                        1.74 secs
Transaction rate:              131.02 trans/sec
Throughput:                        0.00 MB/sec
Concurrency:                      227.38
Successful transactions:        1246
Failed transactions:                  51
Longest transaction:                8.67
Shortest transaction:                0.01


结果现实pypy 速度至多是python(我的是2.7.3的) 一半,甚至一般也不到

而我在另一个测试中pypy 差不多是python 的50倍了
另一个测试,代码:
#  filename : t.py
import os,  sys,    string

def hello(n=1):
    a = 0

    print 'Hello World!!'
    while(n):
        a += 1
        n -= 1

    print  a


if __name__ == '__main__':
    try:
        hello(string.atoi(sys.argv[1]))
    except  IndexError:
        hello()


# time python t.py 99999999
Hello World!!
99999999

real        0m10.707s
user        0m10.681s
sys        0m0.008s
# time pypy t.py 99999999
Hello World!!
99999999

real        0m0.225s
user        0m0.212s
sys        0m0.012s

在webpy 里慢,原因在哪里??

论坛徽章:
0
2 [报告]
发表于 2012-06-04 17:49 |只看该作者
下面是我用strace 跟踪系统调用情况
#strace  -c pypy  index2.py

time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
83.62    0.237730           3     73523     14917 futex
16.32    0.046412          63       739           poll
  0.05    0.000129           6        22           munmap
  0.01    0.000030           0      2912           fcntl
  0.00    0.000013           0       727           accept
  0.00    0.000000           0       804           read
  0.00    0.000000           0        32           write
  0.00    0.000000           0       259        30 open
  0.00    0.000000           0       232           close
  0.00    0.000000           0      2050      1673 stat
  0.00    0.000000           0        20           fstat
  0.00    0.000000           0        14           lstat
  0.00    0.000000           0        19           lseek
  0.00    0.000000           0       122           mmap
  0.00    0.000000           0        40           mprotect
  0.00    0.000000           0        21           brk
  0.00    0.000000           0         5           rt_sigaction
  0.00    0.000000           0         1           rt_sigprocmask
  0.00    0.000000           0         2           ioctl
  0.00    0.000000           0        16        16 access
  0.00    0.000000           0         1           pipe
  0.00    0.000000           0         1           socket
  0.00    0.000000           0         1           bind
  0.00    0.000000           0         1           listen
  0.00    0.000000           0         2           setsockopt
  0.00    0.000000           0        11           clone
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         1           wait4
  0.00    0.000000           0         1           uname
  0.00    0.000000           0         2           getdents
  0.00    0.000000           0         2           getcwd
  0.00    0.000000           0        16        15 mkdir
  0.00    0.000000           0        15        15 unlink
  0.00    0.000000           0         2           readlink
  0.00    0.000000           0         3           getrlimit
  0.00    0.000000           0         1           getuid
  0.00    0.000000           0         1           getgid
  0.00    0.000000           0         1           geteuid
  0.00    0.000000           0         1           getegid
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         1           set_tid_address
  0.00    0.000000           0         1           openat
  0.00    0.000000           0         1           set_robust_list
------ ----------- ----------- --------- --------- ----------------
100.00    0.284314                 81628     16666 total


#strace  -c python  index2.py

time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
70.22    0.584668         621       942           poll
27.65    0.230245           9     24266      4572 futex
  1.31    0.010904           3      3743           fcntl
  0.82    0.006806           7       931           accept
  0.00    0.000020           0       429           read
  0.00    0.000020           0       428       342 stat
  0.00    0.000000           0        89           write
  0.00    0.000000           0      1313      1095 open
  0.00    0.000000           0       220           close
  0.00    0.000000           0       333           fstat
  0.00    0.000000           0         9           lstat
  0.00    0.000000           0        34           lseek
  0.00    0.000000           0       184           mmap
  0.00    0.000000           0        34           mprotect
  0.00    0.000000           0       134           munmap
  0.00    0.000000           0        32           brk
  0.00    0.000000           0        67           rt_sigaction
  0.00    0.000000           0         1           rt_sigprocmask
  0.00    0.000000           0         5         1 ioctl
  0.00    0.000000           0        11        11 access
  0.00    0.000000           0         1           socket
  0.00    0.000000           0         1           bind
  0.00    0.000000           0         1           listen
  0.00    0.000000           0         2           setsockopt
  0.00    0.000000           0        10           clone
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         4           getdents
  0.00    0.000000           0         2           getcwd
  0.00    0.000000           0        15        15 unlink
  0.00    0.000000           0         4         2 readlink
  0.00    0.000000           0         2           getrlimit
  0.00    0.000000           0         1           getuid
  0.00    0.000000           0         1           getgid
  0.00    0.000000           0         1           geteuid
  0.00    0.000000           0         1           getegid
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         1           set_tid_address
  0.00    0.000000           0         2           openat
  0.00    0.000000           0         1           set_robust_list
------ ----------- ----------- --------- --------- ----------------
100.00    0.832663                 33257      6038 total

在使用pypy时
time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
83.62    0.237730           3     73523     14917 futex
16.32    0.046412          63       739           poll
使用python时
time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
70.22    0.584668         621       942           poll
27.65    0.230245           9     24266      4572 futex

明显futex调用占用时间太长,是不是因为调用错误太多了?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP