系统环境:
OS:Ubuntu 10.10 (2G)

Servlet Container:tomcat-tomcat-7.0.23  (最大内存:default 256M  maxThreads:500)

Web server: apache2.2 (maxClient:250)

设置apache最大连接数

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

一、benchmark测试方法

./ab -n 100000 -c 100 http://localhost/test

使用ab进行测试,当并发较高时,会出现以下错误

错误1:apr_socket_recv: Connection reset by peer (104)

  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

  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. Server Software:
  14. Server Hostname:        localhost
  15. Server Port:            80
  16. Document Path:          /test
  17. Document Length:        347 bytes
  18. Concurrency Level:      100
  19. Time taken for tests:   50.270 seconds
  20. Complete requests:      100000
  21. Failed requests:        0
  22. Write errors:           0
  23. Total transferred:      48712175 bytes
  24. HTML transferred:       34708675 bytes
  25. Requests per second:    1989.24 [#/sec] (mean)
  26. Time per request:       50.270 [ms] (mean)
  27. Time per request:       0.503 [ms] (mean, across all concurrent requests)
  28. Transfer rate:          946.29 [Kbytes/sec] received
  29. Connection Times (ms)
  30. min  mean[+/-sd] median   max
  31. Connect:        0   23  15.3     21     714
  32. Processing:     2   27  19.8     24     724
  33. Waiting:        1   22  15.4     20     714
  34. Total:          9   50  25.3     44     747
  35. Percentage of the requests served within a certain time (ms)
  36. 50%     44
  37. 66%     49
  38. 75%     53
  39. 80%     55
  40. 90%     64
  41. 95%     73
  42. 98%     87
  43. 99%    101
  44. 100%    747 (longest request)

三、使用HTTP 后的benchmark

  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. Server Software:        Apache-Coyote/1.1
  14. Server Hostname:        localhost
  15. Server Port:            80
  16. Document Path:          /test
  17. Document Length:        347 bytes
  18. Concurrency Level:      100
  19. Time taken for tests:   55.392 seconds
  20. Complete requests:      100000
  21. Failed requests:        0
  22. Write errors:           0
  23. Total transferred:      51415934 bytes
  24. HTML transferred:       34710757 bytes
  25. Requests per second:    1805.32 [#/sec] (mean)
  26. Time per request:       55.392 [ms] (mean)
  27. Time per request:       0.554 [ms] (mean, across all concurrent requests)
  28. Transfer rate:          906.47 [Kbytes/sec] received
  29. Connection Times (ms)
  30. min  mean[+/-sd] median   max
  31. Connect:        0   24  10.1     24     185
  32. Processing:     8   31  10.7     28     215
  33. Waiting:        1   26  10.0     24     198
  34. Total:         13   55  12.3     51     247
  35. Percentage of the requests served within a certain time (ms)
  36. 50%     51
  37. 66%     54
  38. 75%     58
  39. 80%     60
  40. 90%     66
  41. 95%     74
  42. 98%     86
  43. 99%     99
  44. 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 一项有明显的区别。

AJP与HTTP比较和分析的更多相关文章

  1. Tomcat AJP 文件包含漏洞复现(CVE-2020-1938)

    漏洞原理 Tomcat配置了两个Connecto,它们分别是HTTP和AJP. HTTP默认端口为8080,处理http请求:AJP默认端口8009,用于处理 AJP 协议的请求. AJP比http更 ...

  2. Tomcat配置(三):tomcat处理连接的详细过程

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  3. Tomcat(三):tomcat处理连接的详细过程

    Tomcat系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html tomcat可以处理静态资源的请求,也可以通过servlet处理动态资源的请求 ...

  4. AJP协议总结与分析

    Tomcat服务器通过Connector连接器组件与客户程序建立连接,Connector组件负责接收客户的请求,以及把Tomcat服务器的响应结果发送给客户.默认情况下,Tomcat在server.x ...

  5. tomcat源码分析(三)一次http请求的旅行-从Socket说起

    p { margin-bottom: 0.25cm; line-height: 120% } tomcat源码分析(三)一次http请求的旅行 在http请求旅行之前,我们先来准备下我们所需要的工具. ...

  6. tomcat源码分析(一)从tomcat架构说起

    p { margin-bottom: 0.25cm; line-height: 120% }

  7. Tomcat源码分析

    前言: 本文是我阅读了TOMCAT源码后的一些心得. 主要是讲解TOMCAT的系统框架, 以及启动流程.若有错漏之处,敬请批评指教! 建议: 毕竟TOMCAT的框架还是比较复杂的, 单是从文字上理解, ...

  8. Tomcat处理HTTP请求源码分析(上)(转)

    转载自:http://www.infoq.com/cn/articles/zh-tomcat-http-request-1 很多开源应用服务器都是集成tomcat作为web container的,而且 ...

  9. 服务器程序源代码分析之三:gunicorn

    服务器程序源代码分析之三:gunicorn 时间:2014-05-09 11:33:54 类别:网站架构 访问: 641 次 gunicorn是一个python web 服务部署工具,类似flup,完 ...

随机推荐

  1. BZOJ3712 PA2014Fiolki(kruskal重构树)

    对合并过程建树.然后只需要按照时间顺序考虑每个反应就行了,时间顺序根据lca的深度确定. #include<iostream> #include<cstdio> #includ ...

  2. C++解析(18):C++标准库与字符串类

    0.目录 1.C++标准库 2.字符串类 3.数组操作符的重载 4.小结 1.C++标准库 有趣的重载--操作符 << 的原生意义是按位左移,例:1 << 2;,其意义是将整数 ...

  3. 洛谷 P3391 【模板】文艺平衡树(Splay)

    题目背景 这是一道经典的Splay模板题——文艺平衡树. 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1, ...

  4. 原子性、内存可见性和重排序——重新认识synchronized和volatile

    一.原子性 原子性操作指相应的操作是单一不可分割的操作.例如,对int变量count执行count++d操作就不是原子性操作.因为count++实际上可以分解为3个操作:(1)读取变量count的当前 ...

  5. LiveCD及Casper调研

    1.LiveCD原理 LiveCD本质上是ISO 9660/El Torito格式的CD-ROM. 下面对LiveCD涉及的各种技术做了简单的调研. 1.1. CD-ROM CD-ROM是一种光盘存储 ...

  6. [AT2369] [agc013_c] Ants on a Circle

    题目链接 AtCoder:https://agc013.contest.atcoder.jp/tasks/agc013_c 洛谷:https://www.luogu.org/problemnew/sh ...

  7. Android 通过浏览器打开应用

    在很多应用的web站,其实都有这样一个功能,就是直接在网页中打开应用,接下来的就来探讨一下这个功能的实现,有些地方也我还没弄明白,还请懂的大神指点. 首先,得说一点不好消息,在微信中,这样的方式是行不 ...

  8. PID控制算法的C语言实现二 PID算法的离散化

    上一节中,我论述了PID算法的基本形式,并对其控制过程的实现有了一个简要的说明,通过上一节的总结,基本已经可以明白PID控制的过程.这一节中先继续上一节内容补充说明一下. 1.说明一下反馈控制的原理, ...

  9. bnuoj53075 外挂使用拒绝

    题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=53075 第一次给校赛出题,来为自己的题目写一发题解吧. 其实我原本的题意非常简洁: 结果被另一位 ...

  10. jetbrains phpstorm插件开发环境搭建

    2018.04.14 重要更新: 使用 gradle 进行构建可以免去下面大部分步骤,使用 gradle 我们仅需下载安装 JDK.Idea. 使用 gradle 的方法是,新建 Project,然后 ...