springboot使用tomcat apr模式
因需项目对并发要求比较高、提高Tomcat效率、使用tomcat apr模式、今天在这记录下使用过程、apr全称为apache portable runtime、这里套用下wiki对apr的解释。
The Apache Portable Runtime (APR) is asupporting library fortheApache web server. It provides asetofAPIs that map totheunderlying operating system(OS).[] Where theOS does notsupport aparticular function, APRwillprovideanemulation. ThusprogrammerscanusetheAPRtomakeaprogramtrulyportableacrossplatforms.APR originally formed apart ofApache HTTP Server, but theApache Software Foundation spun itoff intoaseparate project. Other applications can use ittoachieve platformindependence.
很好理解就是为apache server准备的一套基于操作系统底层的类库。
APR原理
APR的整体模式还是非阻塞IO,实现的线程模型也是按照NIO的标准模型实现的,从官方文档(http://apr.apache.org/docs/apr/1.6/modules.html)可以看到APR根据不同操作系统,分别用c重写了大部分IO和系统线程操作模块,这就是为什么APR在不改动代码的情况下能够提升。
下面这些就是APR重写的模块:
Memory allocation andmemorypool functionality
Atomic operations
Dynamic library handling
File I/O
Command-argument parsing
Locking
Hash tables andarrays
Mmap functionalityNetwork sockets andprotocols
Thread, process andmutex functionality
Shared memory functionality
Time routinesUser andgroup ID services
spring boot 开启APR模式
在Springboot中内嵌的Tomcat默认启动开启的是NIO模式,这里如果我们要在linux内核的系统上使用APR模式,那么需要安装一些lib库,可以通过rpm -q | grep apr来查看是否安装了apr,如果安装了则不再需要安装,如果未安装则需要安装下列库:
)openssl,需要版本大于1.0.2,如果不使用https openssl也可以不安装,就是在启动的时候会报openssl的错误,直接忽视就可以了;
)apr,可以去官网下载1..X最新版进行下载http://apr.apache.org/download.cgiapr-util,在同一个页面进行下载,最新版本为1.6.X版本tomcat-native,在tomcat中自带了安装包,可以在tomcat的bin目录下找到tomcat-native.tar;
下载最新&解压安装包apr
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gzwget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz tar -zxvf apr-1.6..tar.gztar -zxvf apr-util-1.6..tar.gz
安装APR
# cd apr-1.6. 检查是否符合安装条件并配置安装参数,检查是否缺失类库,一般来说如果安装的不是精简版系统都是能顺利通过的# ./configure --prefix=/usr/local/apr# make & make install 如果不设置安装路径,那么系统默认的安装路径为/usr/local/apr/lib
安装apr-util
# cd apr-util-1.6. 安装apr-util需要配置apr路径和jvm路径,否则会报错找不到apr ./configure --with-apr=/usr/local/apr --prefix=/usr/local/apr-utils --with-java-home=/usr/java/jdk1.8.0_ && make && make install
安装tomcat-native
# cd tomcat/bin # tar -zxvf tomcat-native.tar.gz#cdtomcat-native-1.2.-src/native/ # ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.8.0_ --with-ssl=/usr/local/include/node/openssl --with-ssl=yes && make && make install
配置Apr
vi /etc/profile 在profile最前面加上 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib source /etc/profile
新增APRConfig类
网上大部分讲解配置tomcat apr的文章,都只是讲了如何在独立tomcat服务上如何配置apr,只需要修改server.xml中的connnector 的protocol就可以了,对于springboot会稍微复杂些,需要增加一个apr配置类在启动的时候修改Embed的tomcat connector网络接入协议。
packagecom.ochain.data2chain.gateway.config; importorg.apache.catalina.LifecycleListener;
importorg.apache.catalina.core.AprLifecycleListener;
importorg.springframework.beans.factory.annotation.Value;
importorg.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
importorg.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.Configuration;
/**
*
* @authoryueli
* @date: 2018年9月10日下午4:44:08
*/@ConfigurationpublicclassAPRConfig{
@Value("${tomcat.apr:false}")privateboolean enabled; @BeanpublicEmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
if(enabled) {
LifecycleListener arpLifecycle = new AprLifecycleListener();
container.setProtocol("org.apache.coyote.http11.Http11AprProtocol");
container.addContextLifecycleListeners(arpLifecycle);
}
returncontainer;
}
}
启动springboot
启动成功后回发现日志输出如下的信息
2018-09-1015:31:19,032-InitializingProtocolHandler["http-apr-8081"]
2018-09-1015:31:19,051-StartingProtocolHandler["http-apr-8081"]
2018-09-1015:31:19,080-Tomcatstartedonport(s): 8081(http)
问题:
1:启动springboot 报如下错误
org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException: Connector configured tolisten onport 8081 failed tostart
...
***************************
APPLICATION FAILED TOSTART
*************************** Description: The Tomcat connector configured tolisten onport 8081 failed tostart. Theport may already be inuse orthe connector may be misconfigured. Caused by: org.apache.catalina.LifecycleException: The configured protocol [org.apache.coyote.http11.Http11AprProtocol] requires the APR/native library which is notavailable
从上面错误来看真正的原因是系统找不到apr的lib库
解决方法:
在启动命令添加制定par库
java -Djava.library.path=/usr/apr/lib -jar xxxx-0.0.1-SNAPSHOT.jar
2:apr-util致命错误:expat.h:没有那个文件或目录
xml/apr_xml.c:35:19: 致命错误:expat.h:
没有那个文件或目录#include<expat.h>^
编译中断。make[1]: *** [xml/apr_xml.lo] 错误1make[1]:
离开目录“/home/apr/apr-util-1.6.1”缺少expat库
解决方法:
安装 expat-devel 库
yum install -y expat-devel
安装后再次编辑
springboot使用tomcat apr模式的更多相关文章
- tomcat运行模式APR安装
centos6.2下,Tomcat运行模式apr安装过程,如下: 一.安装apr [root@vmT227-m5 /]# cd /usr/local/ [root@vmT227-m5 local]# ...
- Tomcat 8.5 apr 模式配置
tomcat APR模式配置 一.环境 操作系统:Ubutnu 14 ubuntu@ubuntu:~$ uname -a Linux ubuntu 4.4.0-31-generic #50~14.04 ...
- 基于APR模式的Tomcat8环境部署
1.版本信息 组件名 版本号 jdk 1.8.111 tomcat 8.5.9 apr 1.6.3 apr-iconv 1.2.2 apr-util 1.6.2 tomcat-native 1.2.1 ...
- SpringBoot内嵌Tomcat开启APR模式(运行环境为Centos7)
网上查到的一些springboot内嵌的tomcat开启apr的文章,好像使用的springboot版本较老,在SpringBoot 2.0.4.RELEASE中已经行不通了.自己整理了一下,供参考. ...
- tomcat bio nio apr 模式性能测试
转自:tomcat bio nio apr 模式性能测试与个人看法 11.11活动当天,服务器负载过大,导致部分页面出现了不可访问的状态.那后来主管就要求调优了,下面是tomcat bio.nio.a ...
- Tomcat在Linux服务器上的BIO、NIO、APR模式设置
一.BIO.NIO.AIO 先了解四个概念: 同步 : 自己亲自出马持银行卡到银行取钱(使用同步IO时,Java自己处理IO读写). 异步 : 委托一小弟拿银行卡到银行取钱,然后给你(使用异步IO时, ...
- liunx tomcat 运行模式apr
tomcat运行模式一共三种:bio.nio.apr 网上对这三种运行模式的解释外: bio运行模式:阻塞式I/O操作,表示Tomcat使用的是传统的Java I/O操作(即java.io包及其子包) ...
- 配置Tomcat apr运行模式
tomcat中一共有三种运行模式,分别是:bio,nio,apr bio是阻塞式IO操作,使用的是传统的java i/o处理方式,对于每一个请求都要创建一个线程来进行处理,所以开销较大不适合处理高并发 ...
- TOMCAT开启APR模式
Tomcat支持三种接收请求的处理方式:BIO.NIO.ARP. BIO模式:阻塞式I/O操作,表示Tomcat使用传统Java I/O操作.默认情况下,Tomcat7以下版本使用BIO模式运行,由于 ...
随机推荐
- mongdb 慢查询
查看mongodb慢查询 赶紧打开服务器爸爸,开慢查询,看下耗时500ms以上的都是些啥: db.setProfilingLevel(2,500) 看下最近的10条具体的慢查询指令: db.syste ...
- 【BZOJ】1691: [Usaco2007 Dec]挑剔的美食家(set+贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1691 懒得打平衡树了.... 而且multiset是很快的... 排到了rank1 T_T 贪心就是 ...
- 配置sudo su
买了UCloud的机器默认给的是root权限,从安全考虑,这个得改改,那就添加一个普通用户吧.. 可是那群民工又有话说了,得有root权限才能启动那些服务进程,每次都要输入root密码才能切换到roo ...
- 基于struts2框架文件的上传与下载
在开发一些社交网站时,需要有允许用户上传自己本地文件的功能,则需要文件的上传下载代码. 首先考虑的是文件的储存位置,这里不考虑存在数据库,因为通过数据库查询获取十分消耗资源与时间,故需将数据存储在服务 ...
- js后台常用树形菜单
来源:http://www.sucaihuo.com/js/1093.html demo: http://www.sucaihuo.com/jquery/10/1093/demo/
- hdu 1257 最少拦截系统(动态规划 / 贪心)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- linux_shell_find命令
使用find查找文件 基本格式:find path expression 1.按照文件名查找 (1)find / -name httpd.conf #在根目录下查找文件httpd.conf,表示在整个 ...
- 如何在ChemDraw中缩短双键长度
双键是化学绘图软件ChemDraw在绘制化学图形的过程中会遇到各种各样的化学结构.而双键就是一种常见的化学基础结构,有的用户希望自己绘制的图形更加的美观,希望可以调整双键的长度并且不影响到其他的结构. ...
- 修改CFileDialog的标题
CFileDialog f(TRUE); f.m_ofn.lpstrTitle = "我的标题"; f.DoModal(); 设置标题! CFileDialog ...
- UNMET PEER DEPENDENCY @angular/common@2.3.1
install of angular-cli results in unmeet peer dependencies. OSX 10.11.6node v6.9.1npm v3.10.8 [sudo] ...