基于Swoole重构OpenCart启动代码后性能测试

楚天乐 163 0 条

状况

打开webbench测试,200客户端,60秒。并发只有265page/min。

[root@li1205-86 ~]# webbench -c 500 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
500 clients, running 60 sec.

Speed=265 pages/min, 82524 bytes/sec.
Requests: 265 susceed, 0 failed.

整体CPU利用率只有10%-15%。

解决

代码问题

开了8个进程,也启动了8个进程,但实际只有1个进程在干活。
一通google发现Swoole\Http\Server启动参数设置不对.

$http = new Server("127.0.0.1", 9000, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$http->set(array(
    'task_worker_num' => 8,
    'daemonize' => 1,
));

改为

$http = new Server("127.0.0.1", 9000, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$http->set(array(
    'worker_num' => 8,        # worker数量
    'max_request ' => 100,    # 一个worker最大处理请求数
    "dispatch_mode" => 1,     # 1.轮训,2.固定,3.抢占,
));

测试

[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1308 pages/min, 643527 bytes/sec.
Requests: 1308 susceed, 0 failed.

测试

试试不同worker数量情况:worker_num = 8, 16, 32

  • worker_num = 8
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1066 pages/min, 526076 bytes/sec.
Requests: 1066 susceed, 0 failed.
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1022 pages/min, 502909 bytes/sec.
Requests: 1022 susceed, 0 failed.
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=946 pages/min, 465510 bytes/sec.
Requests: 946 susceed, 0 failed.
worker_num run pages/min
8 1 1066
8 2 1022
8 3 946
  • worker_num = 16
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1647 pages/min, 809739 bytes/sec.
Requests: 1647 susceed, 0 failed.
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1641 pages/min, 807504 bytes/sec.
Requests: 1641 susceed, 0 failed.
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1580 pages/min, 777491 bytes/sec.
Requests: 1580 susceed, 0 failed.
worker_num run pages/min
16 1 1647
16 2 1641
16 3 1580
  • worker_num = 32
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1751 pages/min, 861361 bytes/sec.
Requests: 1751 susceed, 0 failed.
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1660 pages/min, 816672 bytes/sec.
Requests: 1660 susceed, 0 failed.
[root@li1205-86 ~]# webbench -c 200 -t 60 http://swoole-opencart.shyclouds.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://swoole-opencart.shyclouds.com/
200 clients, running 60 sec.

Speed=1665 pages/min, 819726 bytes/sec.
Requests: 1665 susceed, 0 failed.
worker_num run pages/min
32 1 1751
32 2 1660
32 3 1665

总结

  • worker=8表现不佳,不能充分利用系统资源
  • worker=16和32差别不大,更多需要数据库端优化。前端php服务器cpu利用率已经稳定。我们这里使用worker_num=16的数据来做对比。
worker_num run pages/min
16 1 1647
16 2 1641
16 3 1580
平均 1622.6
  • 性能指标对比 pages/min
基准 swoole优化版本 ratio
390.5(上一篇) 1622.6 4.155倍

遗留问题

  • 整理重构后的opencart代码
  • 测试可用性


发表我的评论
'
昵称 (必填)
邮箱 (必填)
网址