- 论坛徽章:
- 0
|
回复 14# py
非常感谢您的回复,澄清了我关于阻塞操作的片面看法。但是应该怎样去分析一个操作是否阻塞呢?
另外,我想进一步分析一下如何对程序中有阻塞操作的情况进行调优,文档介绍过,如果有阻塞操作,最好的方法就是增加workers减少clients,意思就是多fork几个workers并降低每个worker能处理的并行请求,这是我的测试结果:
1. prefork 2 workers, 允许每个worker接受2 并行请求- perl myapp.pl prefork -w 2 -c 2
复制代码 1.1 阻塞操作发送4个并行请求- Jacks-MacBook-Pro:Project jzhangkun$ ab -n 4 -c 4 127.0.0.1:3000/worker1
- 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 127.0.0.1 (be patient).....done
- Server Software: Mojolicious
- Server Hostname: 127.0.0.1
- Server Port: 3000
- Document Path: /worker1
- Document Length: 23 bytes
- Concurrency Level: 4
- Time taken for tests: 10.008 seconds
- Complete requests: 4
- Failed requests: 0
- Write errors: 0
- Total transferred: 740 bytes
- HTML transferred: 92 bytes
- Requests per second: 0.40 [#/sec] (mean)
- Time per request: 10008.165 [ms] (mean)
- Time per request: 2502.041 [ms] (mean, across all concurrent requests)
- Transfer rate: 0.07 [Kbytes/sec] received
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.1 0 0
- Processing: 5004 7506 2889.0 10008 10008
- Waiting: 5004 7506 2889.0 10008 10008
- Total: 5004 7506 2889.0 10008 10008
- Percentage of the requests served within a certain time (ms)
- 50% 10008
- 66% 10008
- 75% 10008
- 80% 10008
- 90% 10008
- 95% 10008
- 98% 10008
- 99% 10008
- 100% 10008 (longest request)
复制代码 设想mojo处理请求的流程是将两个请求分给两个workers,因为操作是阻塞的,所以每个worker在处理两个请求时是阻塞进行的,因此每个都需要10s。
1.2 非阻塞操作发送4个并行请求- Jacks-MacBook-Pro:Project jzhangkun$ ab -n 4 -c 4 127.0.0.1:3000/worker2
- 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 127.0.0.1 (be patient).....done
- Server Software: Mojolicious
- Server Hostname: 127.0.0.1
- Server Port: 3000
- Document Path: /worker2
- Document Length: 23 bytes
- Concurrency Level: 4
- Time taken for tests: 5.059 seconds
- Complete requests: 4
- Failed requests: 0
- Write errors: 0
- Total transferred: 740 bytes
- HTML transferred: 92 bytes
- Requests per second: 0.79 [#/sec] (mean)
- Time per request: 5058.597 [ms] (mean)
- Time per request: 1264.649 [ms] (mean, across all concurrent requests)
- Transfer rate: 0.14 [Kbytes/sec] received
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.1 0 0
- Processing: 5004 5024 25.8 5030 5058
- Waiting: 5004 5024 25.9 5030 5058
- Total: 5004 5024 25.8 5030 5058
- Percentage of the requests served within a certain time (ms)
- 50% 5030
- 66% 5030
- 75% 5058
- 80% 5058
- 90% 5058
- 95% 5058
- 98% 5058
- 99% 5058
- 100% 5058 (longest request)
复制代码 设想mojo也是让每个worker处理两个请求,因为是非阻塞处理,所以是5s内能全部处理完
2. prefork 4 worker, 允许每个worker接受1个并行请求- perl myapp.pl prefork -w 4 -c 1
复制代码 2.1 阻塞操作,4个并行请求- Jacks-MacBook-Pro:Project jzhangkun$ ab -n 4 -c 4 127.0.0.1:3000/worker1
- 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 127.0.0.1 (be patient).....done
- Server Software: Mojolicious
- Server Hostname: 127.0.0.1
- Server Port: 3000
- Document Path: /worker1
- Document Length: 23 bytes
- Concurrency Level: 4
- Time taken for tests: 5.024 seconds
- Complete requests: 4
- Failed requests: 0
- Write errors: 0
- Total transferred: 740 bytes
- HTML transferred: 92 bytes
- Requests per second: 0.80 [#/sec] (mean)
- Time per request: 5024.368 [ms] (mean)
- Time per request: 1256.092 [ms] (mean, across all concurrent requests)
- Transfer rate: 0.14 [Kbytes/sec] received
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.0 0 0
- Processing: 5018 5022 2.9 5024 5024
- Waiting: 5018 5022 2.9 5024 5024
- Total: 5018 5022 2.9 5024 5024
- Percentage of the requests served within a certain time (ms)
- 50% 5024
- 66% 5024
- 75% 5024
- 80% 5024
- 90% 5024
- 95% 5024
- 98% 5024
- 99% 5024
- 100% 5024 (longest request)
复制代码 设想是每个worker处理一个请求,5s内能处理完
2.2 非阻塞操作,4个并行请求- Jacks-MacBook-Pro:Project jzhangkun$ ab -n 4 -c 4 127.0.0.1:3000/worker2
- 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 127.0.0.1 (be patient).....done
- Server Software: Mojolicious
- Server Hostname: 127.0.0.1
- Server Port: 3000
- Document Path: /worker2
- Document Length: 23 bytes
- Concurrency Level: 4
- Time taken for tests: 5.007 seconds
- Complete requests: 4
- Failed requests: 0
- Write errors: 0
- Total transferred: 740 bytes
- HTML transferred: 92 bytes
- Requests per second: 0.80 [#/sec] (mean)
- Time per request: 5007.428 [ms] (mean)
- Time per request: 1251.857 [ms] (mean, across all concurrent requests)
- Transfer rate: 0.14 [Kbytes/sec] received
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.0 0 0
- Processing: 5005 5006 1.0 5006 5007
- Waiting: 5005 5006 1.1 5006 5007
- Total: 5005 5006 1.0 5006 5007
- Percentage of the requests served within a certain time (ms)
- 50% 5006
- 66% 5006
- 75% 5007
- 80% 5007
- 90% 5007
- 95% 5007
- 98% 5007
- 99% 5007
- 100% 5007 (longest request)
复制代码 非阻塞更是没悬念,5s内处理完。
纵观前面的测试结果,增加worker数量确实可以帮助分散并行请求给不同的worker去处理阻塞的操作。但是我不确定降低并行数是否有效,因此我又做了下一个测试
3. prefork 4 workers, 允许每个worker接受两个请求- perl myapp.pl prefork -w 4 -c 2
复制代码 3.1 阻塞操作,4个并请求- Jacks-MacBook-Pro:Project jzhangkun$ ab -n 4 -c 4 127.0.0.1:3000/worker1
- 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 127.0.0.1 (be patient).....done
- Server Software: Mojolicious
- Server Hostname: 127.0.0.1
- Server Port: 3000
- Document Path: /worker1
- Document Length: 23 bytes
- Concurrency Level: 4
- Time taken for tests: 5.006 seconds
- Complete requests: 4
- Failed requests: 0
- Write errors: 0
- Total transferred: 740 bytes
- HTML transferred: 92 bytes
- Requests per second: 0.80 [#/sec] (mean)
- Time per request: 5006.107 [ms] (mean)
- Time per request: 1251.527 [ms] (mean, across all concurrent requests)
- Transfer rate: 0.14 [Kbytes/sec] received
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.0 0 0
- Processing: 5005 5005 0.6 5006 5006
- Waiting: 5004 5005 0.7 5006 5006
- Total: 5005 5006 0.6 5006 5006
- WARNING: The median and mean for the processing time are not within a normal deviation
- These results are probably not that reliable.
- WARNING: The median and mean for the waiting time are not within a normal deviation
- These results are probably not that reliable.
- Percentage of the requests served within a certain time (ms)
- 50% 5006
- 66% 5006
- 75% 5006
- 80% 5006
- 90% 5006
- 95% 5006
- 98% 5006
- 99% 5006
- 100% 5006 (longest request)
复制代码 从这个结果来看,mojo还是将4个请求平均分散给4个worker,而不是分两个给两个worker,那么降低每个worker并行处理数量的意义何在?
不知道各位对这一系列处理行为有什么特殊看法?另外,mojo是如何去检测阻塞的worker并分配并行请求的,是否有文档呢?谢谢!
|
|