zoukankan      html  css  js  c++  java
  • AJP与HTTP比较和分析

    系统环境:
    OS:Ubuntu 10.10 (2G)
    Servlet Container:tomcat-tomcat-7.0.23  (最大内存:default 256M  maxThreads:500)
    Web server: apache2.2 (maxClient:250)
    设置apache最大连接数

    Java代码  收藏代码
    1. 在/usr/local/etc/apache22/httpd.conf中加载MPM配置(去掉前面的注释):  
    2. # Server-pool management (MPM specific)  
    3. Include etc/apache22/extra/httpd-mpm.conf  
    4.   
    5. 修改d-mpm.conf中对应module如下  
    6. <IfModule mpm_prefork_module>  
    7.                 StartServers                      5  
    8.                 MinSpareServers                   5  
    9.                 MaxSpareServers                  10  
    10.                 ServerLimit                     3000  
    11.                 MaxClients                      2000  
    12.                 MaxRequestsPerChild               0  
    13. </IfModule>]  



    一、benchmark测试方法
    ./ab -n 100000 -c 100 http://localhost/test
    使用ab进行测试,当并发较高时,会出现以下错误
    错误1:apr_socket_recv: Connection reset by peer (104)

    Java代码  收藏代码
    1. apache2.2及以下版本  
    2. 修改support下面的ab.c源代码, 大概在  
    3. line 1369, 修改成  
    4. 1368                 return;  
    5. 1369             } else {  
    6. 1370                 //apr_err("apr_socket_recv", status);  
    7. 1371                 bad++;  
    8. 1372                 close_connection(c);  
    9. 1373                 return;  
    10. 1374             }  
    11. 然后编译安装  


    错误2:Too many open files (24)

    (PS;使用AJP协议和HTTP协议,多次进行测试,取测试结果较好的一次进行比较)

    二、使用AJP后的benchmark

    Java代码  收藏代码
    1. Benchmarking localhost (be patient)  
    2. Completed 10000 requests  
    3. Completed 20000 requests  
    4. Completed 30000 requests  
    5. Completed 40000 requests  
    6. Completed 50000 requests  
    7. Completed 60000 requests  
    8. Completed 70000 requests  
    9. Completed 80000 requests  
    10. Completed 90000 requests  
    11. Completed 100000 requests  
    12. Finished 100000 requests  
    13.   
    14.   
    15. Server Software:          
    16. Server Hostname:        localhost  
    17. Server Port:            80  
    18.   
    19. Document Path:          /test  
    20. Document Length:        347 bytes  
    21.   
    22. Concurrency Level:      100  
    23. Time taken for tests:   50.270 seconds  
    24. Complete requests:      100000  
    25. Failed requests:        0  
    26. Write errors:           0  
    27. Total transferred:      48712175 bytes  
    28. HTML transferred:       34708675 bytes  
    29. Requests per second:    1989.24 [#/sec] (mean)  
    30. Time per request:       50.270 [ms] (mean)  
    31. Time per request:       0.503 [ms] (mean, across all concurrent requests)  
    32. Transfer rate:          946.29 [Kbytes/sec] received  
    33.   
    34. Connection Times (ms)  
    35.               min  mean[+/-sd] median   max  
    36. Connect:        0   23  15.3     21     714  
    37. Processing:     2   27  19.8     24     724  
    38. Waiting:        1   22  15.4     20     714  
    39. Total:          9   50  25.3     44     747  
    40.   
    41. Percentage of the requests served within a certain time (ms)  
    42.   50%     44  
    43.   66%     49  
    44.   75%     53  
    45.   80%     55  
    46.   90%     64  
    47.   95%     73  
    48.   98%     87  
    49.   99%    101  
    50.  100%    747 (longest request)  



    三、使用HTTP 后的benchmark

    Java代码  收藏代码
    1. Benchmarking localhost (be patient)  
    2. Completed 10000 requests  
    3. Completed 20000 requests  
    4. Completed 30000 requests  
    5. Completed 40000 requests  
    6. Completed 50000 requests  
    7. Completed 60000 requests  
    8. Completed 70000 requests  
    9. Completed 80000 requests  
    10. Completed 90000 requests  
    11. Completed 100000 requests  
    12. Finished 100000 requests  
    13.   
    14.   
    15. Server Software:        Apache-Coyote/1.1  
    16. Server Hostname:        localhost  
    17. Server Port:            80  
    18.   
    19. Document Path:          /test  
    20. Document Length:        347 bytes  
    21.   
    22. Concurrency Level:      100  
    23. Time taken for tests:   55.392 seconds  
    24. Complete requests:      100000  
    25. Failed requests:        0  
    26. Write errors:           0  
    27. Total transferred:      51415934 bytes  
    28. HTML transferred:       34710757 bytes  
    29. Requests per second:    1805.32 [#/sec] (mean)  
    30. Time per request:       55.392 [ms] (mean)  
    31. Time per request:       0.554 [ms] (mean, across all concurrent requests)  
    32. Transfer rate:          906.47 [Kbytes/sec] received  
    33.   
    34. Connection Times (ms)  
    35.               min  mean[+/-sd] median   max  
    36. Connect:        0   24  10.1     24     185  
    37. Processing:     8   31  10.7     28     215  
    38. Waiting:        1   26  10.0     24     198  
    39. Total:         13   55  12.3     51     247  
    40.   
    41. Percentage of the requests served within a certain time (ms)  
    42.   50%     51  
    43.   66%     54  
    44.   75%     58  
    45.   80%     60  
    46.   90%     66  
    47.   95%     74  
    48.   98%     86  
    49.   99%     99  
    50.  100%    247 (longest request)  



    四、结论
    If integration with the native webserver is needed for any reason, an AJP connector will provide faster performance than proxied HTTP.
    前端apache,后端tomcat,通过ajp协议访问性能优于http协议,随着并发量的提升,效果会更加趋于明显。可以从吞吐率和总时间开销上观察。
    (吞吐率:单位时间内计算机的处理请求来描述其并发处理能力)

    可以参考下ajp协议的设计 http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html

    原因总结如下:
    1、ajp使用长连接保持webServer和servlet Container的通信,减少了建立tcp连接的开销。可以通过观察tomcat/manager 下serverStatus,ajp建立的连接都处于keepalive的状态。
    2、ajp使用一定的协议格式,减少了传递的报文数据大小,节省了带宽。可以通过观察ajp和http 的benchmark报告重看到,Total transferred 一项有明显的区别。

  • 相关阅读:
    【工具类】Stream流构建指定长度的时间集合
    【Java】 Java中的浅拷贝和深拷贝
    【网络协议】 TCP三次握手的流程
    【工具库】Java实体映射工具MapStruct
    【并发编程】Java中的锁有哪些?
    【ORM】Mybatis与JPA的区别
    【并发编程】ThreadLocal
    【SpringBoot】SpringBoot 处理后端返回的小数(全局配置 + 定制化配置)
    实战开发三步走
    项目:jSon和Ajax登录功能
  • 原文地址:https://www.cnblogs.com/itcomputer/p/4873699.html
Copyright © 2011-2022 走看看