Tomcat可以使用Apache Portable Runtime来提供卓越的性能及可扩展性,更好地与本地服务器技术的集成。Apache Portable Runtime是一个高度可移植的库,位于Apache HTTP Server 2.x的核心。APR有许多用途,包括访问高级IO功能(如sendfile,epoll和OpenSSL),操作系统级功能(随机数生成,系统状态等)以及本地进程处理(共享内存,NT管道和Unix套接字)。

这些功能不仅仅是一个后端集中的技术,还可以让Tomcat成为通用的网络服务器,可以实现与本地的其他Web技术更好的集成,并使Java成为一个完整的网络服务器平台。

官方要求:

APR 1.2+ development headers (libapr1-dev package)
OpenSSL 1.0.2+ development headers (libssl-dev package)
JNI headers from Java compatible JDK 1.4+
GNU development environment (gcc, make)

生产环境:

CentOS Linux release 7.3.1611 (Core) x86 64
Server version: Apache Tomcat/8.5.16
java version “1.8.0_131”

Apache Tomcat/8.5.16 的安装请查看《Linux Apache Tomcat 8.5 安装与配置

1.安装相关依赖包

# yum -y install gcc gcc-c++ libtool* autoconf automake expat-devel perl perl-devel

2.下载安装包

# cd /tmp/
# wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.2.tar.gz
# wget http://mirror.bit.edu.cn/apache/apr/apr-iconv-1.2.1.tar.gz
# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.0.tar.gz
# wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz

3.安装APR

# tar zxvf apr-1.6.2.tar.gz
# cd apr-1.6.2
# vim configure

默认值:

RM='$RM'

修改为:

RM='$RM -f'
# ./configure --prefix=/usr/local/apr
# make && make install

4.安装apr-iconv

# tar zxvf apr-iconv-1.2.1.tar.gz
# cd apr-iconv-1.2.1
# ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
# make && make install

5.安装apr-util

# tar zxvf apr-util-1.6.0.tar.gz
# cd apr-util-1.6.0
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv
# make && make install

6.安装OpenSSL

# tar zxvf openssl-1.1.0f.tar.gz
# cd openssl-1.1.0f
# ./config --prefix=/usr/local/openssl
# make -j 4 && make install

7.安装tomcat-native

# cd /usr/local/tomcat/bin/
# tar zxvf tomcat-native.tar.gz
# cd tomcat-native-1.2.12-src/native
# ./configure --with-ssl=/usr/local/openssl --with-apr=/usr/bin/apr-1-config --with-java-home=/usr/java/jdk1.8.0_131
# make && make install

注意:如果以上 configure 失败,可以执行 make distclean 清除

8.添加变量内容

# vim /etc/profile.d/jdk.sh
export LD_LIBRARY_PATH=/usr/local/apr/lib:$LD_LIBRARY_PATH
# source /etc/profile.d/jdk.sh

至此APR安装成功。

9.接下来需要修改tomcat配置文件中的APR运行模式,并测试是否安装成功。

# vim /usr/local/tomcat/conf/server.xml

默认值:

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

修改为:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443" />

默认值:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

修改为:

<Connector port="8009" protocol="org.apache.coyote.ajp.AjpAprProtocol" redirectPort="8443" />

10.现在重启tomcat服务,并查看启动日志

# systemctl restart tomcat
# cat /usr/local/tomcat/logs/catalina.out
...
INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
...

注意:可以看到红色部分,提示找不到基于APR的Apache Tomcat Native库,因此无法使用APR模式启动。

解决方案:

# cp -R /usr/local/apr/lib/* /usr/lib64
# cp -R /usr/local/apr/lib/* /usr/lib

再次重启tomcat,并查看启动日志

# cat /usr/local/tomcat/logs/catalina.out
...
INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8009"]
...

可以看到已经以apr协议模式启动成功,经基于APR的技术web压力测试,Tomcat的性能飙升。

转载:Tomcat 8.5 基于 Apache Portable Runtime(APR)库性能优化 | 任我乐

Tomcat 8.5 基于 Apache Portable Runtime(APR)库性能优化的更多相关文章

  1. [转]SVN安装问题The Apache Portable Runtime (APR) library cannot be found

    http://blog.csdn.net/ckwer2008/article/details/47972601 Linux很多地方编译的时候都会用到apr 如果找不到apr就会报错 configure ...

  2. CentOS 7 Tomcat 8 9 基于APR库性能优化

    Tomcat可以使用Apache Portable Runtime来提供卓越的性能及可扩展性,更好地与本地服务器技术的集成.Apache Portable Runtime是一个高度可移植的库,位于Ap ...

  3. Centos下Tomcat 安装Apache Portable Runtime

    APR(Apache Portable Runtime)是一个高可移植库,它是Apache HTTP Server 2.x的核心. APR有很多用途,包括访问高级IO功能(例如sendfile,epo ...

  4. Tair LDB基于Prefixkey中期范围内查找性能优化项目总结

    "Tair LDB基于Prefixkey该范围内查找性能优化"该项目是仅一个月.这个月主要是熟悉项目..以下从几个方面总结下个人在该项目上所做的工作及自己的个人所得所感. 项目工作 ...

  5. 基于SSD固态硬盘的数据库性能优化

    基于SSD固态硬盘的数据库性能优化 2010-11-08 00:0051cto佚名   关键字:固态硬盘 数据库管理 SSD 企业软件热点文章 Java内存结构与模型结构分析 Oracle触发器的语法 ...

  6. [apr] Apache Portable Runtime

    接手新项目,前任大量的使用了APR,虽然不影响理解主逻辑,但是看见一行不知道干嘛的代码,总是特别炸眼. 况且,虽然我从来不跨平台.但是APR如此优秀,学习理解它都不是浪费时间. 可是让人崩溃的是,竟然 ...

  7. Eclipse启动Tomcat报错,系统缺少本地apr库

    Eclipse启动Tomcat报错,系统缺少本地apr库. Tomcat中service.xml中的设置情况. 默认情况是HTTP协议的值:protocol="HTTP/1.1" ...

  8. Tair LDB基于Prefixkey找到如何提取一系列性能优化项目key的prefix_size

    眼下项目已快截止,编码任务也基本完毕.如今主要是性能測试. 项目是依照"Tair LDB基于Prefixkey的范围查找性能优化项目提议方案"的步骤一步步完毕的,首先先介绍第一个关 ...

  9. 基于mongoDB的capped collection的性能优化

    MonitorLogging改造(消息接入) 改造前架构: 可以看出原来的流程中,大量业务分析,业务接入耦合在web服务层.大量操作,导致线程线性的挂起线程. 改造后: 将业务通讯抽象成为Monito ...

随机推荐

  1. 零售企业ERP系统慢

    数据库优化案例 https://www.cnblogs.com/double-K/p/9210982.html 写在前面 记得在自己学习数据库知识的时候特别喜欢看案例,因为优化的手段是容易掌握的,但是 ...

  2. sso(single sign on)

    sso系统使用 https://www.cnblogs.com/shuai-server/p/8987070.html 一:什么是sso(single sign on) ? sso(单点登录系统)简单 ...

  3. CentOS查看线程、硬盘、内存、cpu、网卡

    1.查看硬盘 [mushme@investide ~]$ df -ah 2.查看内存 [mushme@investide ~]$ free -m 3.监控系统的负载 w    查看当前系统的负载,详细 ...

  4. mxnet导入图像数据

    图像的标签在一个json文件中. %matplotlib inline import json import gluonbook as gb import mxnet as mx from mxnet ...

  5. win7下添加库文件出现“file is not regcognized”问题

    最近几天需要画电路图,所以安装了protel se99,安装后在添加库文件的时候出现“file is not regcognized”的问题 百度查了一下,说win7基本上都会出现这个问题. 实际上, ...

  6. springboot自定义异常页面

    废话不多,直接开始. 项目目录: 说明:springboot 静态文件放在static目录中,如images中放的图片:templates目录下error中存放的是错误页面,如500.html代表50 ...

  7. DQL-排序查询

    三:排序查询 语法: select  列名 from    表名 where  筛选条件 order by  需要排序的列名   asc/desc 特点:不写升序还是降序,默认升序 排序列表 可以是 ...

  8. oracle 数据库密码生产同步模拟环境 ,随记常用命令

    1.查看当前open用户 select username,account_status,expiry_date,profile from dba_users; 2.查看目前的密码过期策略 select ...

  9. 自己花了2天时间,重新整理了个全面的vue2的模板

    自己花了2天时间,重新整理了个全面的vue2的模板,基本vue中需要的部分都整理封装好了,希望大家喜欢^ ^.欢迎大家star或者fork呀~,https://github.com/qianxiaon ...

  10. Spring注解配置(1)——@Autowired

    @Autowired 注释,它可以对类成员变量.方法及构造函数进行标注,完成自动装配的工作. 通过 @Autowired的使用来消除 set ,get方法.在使用@Autowired之前,我们对一个b ...