把webman打包成phar,性能比直接运行差,请问是什么原因导致的?

北月

直接使用php start.php start运行

ab压测结果

➜ ~ ab -n1000000 -c1000 -k http://127.0.0.1:9797/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
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)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests

Server Software: workerman
Server Hostname: 127.0.0.1
Server Port: 9797

Document Path: /
Document Length: 45 bytes

Concurrency Level: 1000
Time taken for tests: 10.320 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 166000000 bytes
HTML transferred: 45000000 bytes
Requests per second: 96901.23 [#/sec] (mean)
Time per request: 10.320 [ms] (mean)
Time per request: 0.010 [ms] (mean, across all concurrent requests)
Transfer rate: 15708.60 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 4.4 0 241
Processing: 1 10 6.5 11 241
Waiting: 0 10 6.5 11 40
Total: 1 10 7.8 11 252

Percentage of the requests served within a certain time (ms)
50% 11
66% 12
75% 12
80% 13
90% 19
95% 22
98% 24
99% 26
100% 252 (longest request)

使用打包后的phar运行并测试

ab压测结果

➜ ~ ab -n1000000 -c1000 -k http://127.0.0.1:8787/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
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)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests

Server Software: workerman
Server Hostname: 127.0.0.1
Server Port: 8787

Document Path: /
Document Length: 45 bytes

Concurrency Level: 1000
Time taken for tests: 14.667 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 166000000 bytes
HTML transferred: 45000000 bytes
Requests per second: 68179.05 [#/sec] (mean)
Time per request: 14.667 [ms] (mean)
Time per request: 0.015 [ms] (mean, across all concurrent requests)
Transfer rate: 11052.46 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 4.3 0 237
Processing: 0 14 20.3 1 237
Waiting: 0 14 20.3 1 97
Total: 0 15 20.7 1 246

Percentage of the requests served within a certain time (ms)
50% 1
66% 2
75% 40
80% 42
90% 45
95% 48
98% 52
99% 55
100% 246 (longest request)

2321 3 0
3个回答

czf

phar 用的是这个?

2548a

这个本来就对性能有影响的,phar 主要目的是方便分发,同时也可以保证数据的完整性,而不是提高性能.

  • 北月 2022-02-08

    我以为没有那么离谱,结果差这么多,发现刚才的测试没有开启opcache,加了opcache结果就差不多了

  • duo8668 2022-02-22

    打包成 phar 是准备微服务化?

北月

开启了opcache后,两者压测的结果就差不多了

➜ ~ ab -n1000000 -c1000 -k http://127.0.0.1:8787/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
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)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests

Server Software: workerman
Server Hostname: 127.0.0.1
Server Port: 8787

Document Path: /
Document Length: 45 bytes

Concurrency Level: 1000
Time taken for tests: 10.182 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 166000000 bytes
HTML transferred: 45000000 bytes
Requests per second: 98208.16 [#/sec] (mean)
Time per request: 10.182 [ms] (mean)
Time per request: 0.010 [ms] (mean, across all concurrent requests)
Transfer rate: 15920.46 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 4.3 0 240
Processing: 0 10 7.7 13 240
Waiting: 0 10 7.7 13 46
Total: 0 10 8.8 13 250

Percentage of the requests served within a certain time (ms)
50% 13
66% 13
75% 14
80% 14
90% 18
95% 23
98% 27
99% 29
100% 250 (longest request)

➜ ~ ab -n1000000 -c1000 -k http://127.0.0.1:9797/
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
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)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests

Server Software: workerman
Server Hostname: 127.0.0.1
Server Port: 9797

Document Path: /
Document Length: 45 bytes

Concurrency Level: 1000
Time taken for tests: 10.216 seconds
Complete requests: 1000000
Failed requests: 0
Keep-Alive requests: 1000000
Total transferred: 166000000 bytes
HTML transferred: 45000000 bytes
Requests per second: 97887.15 [#/sec] (mean)
Time per request: 10.216 [ms] (mean)
Time per request: 0.010 [ms] (mean, across all concurrent requests)
Transfer rate: 15868.42 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 4.4 0 239
Processing: 0 10 6.0 10 239
Waiting: 0 10 6.0 10 38
Total: 0 10 7.5 10 249

Percentage of the requests served within a certain time (ms)
50% 10
66% 11
75% 11
80% 12
90% 19
95% 21
98% 22
99% 26
100% 249 (longest request)

  • 暂无评论
年代过于久远,无法发表回答
×
🔝