- 浏览: 851779 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zjhzwx1212:
为什么用threadLocal后,输出值是从20开始的,而定义 ...
j2ee的线程安全--threadlocal -
aeoluspu:
不错 mysql 测试部分感觉不详细
用sysbench(或者super-smack)测试mysql性能 -
nanPrivate:
有没有例子,只理论,实践起来还是不会啊
JMS可靠消息传送 -
lwclover:
一个网络工程师 装什么b
postfix 如何删除队列中的邮件 -
maimode:
我也欠缺不少啊
理想的计算机科学知识体系
Optimal mod_jk configuration
There are many potential problems associated with the default configuration of mod_jk. Let's say it is perfectly adequate for a very low traffic website, but when pushing any moderate to high load to mod_jk, there will be connection problems. This is not due to any bug in mod_jk whatsoever, however, it is because the default configuration makes no assumption about your existing hardware or potential load, so, therefore, it is not tuned accordingly.
Note that the configuration recommendations here are optimal as a base configuration to avoid many of the common problems users experience with mod_jk. There exist many other useful optimizations, but these depend on the environment and web application in use. See http://tomcat.apache.org/connectors-doc/reference/workers.html for details on all available mod_jk properties.
Let's take a look at a typical default configuration for Apache/Tomcat/mod_jk:
workers.properties
<!-- [CodeBlockStart:84aa8fdd-7b1b-4971-8aec-d53af5015459]-->worker.list=loadbalancer,status
worker.node1.port=8009
worker.node1.host=node1.mydomain.com
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node2.port=8009
worker.node2.host= node2.mydomain.com
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.status.type=status
<!-- [CodeBlockEnd:84aa8fdd-7b1b-4971-8aec-d53af5015459]-->
JBoss Web's (Tomcat) server.xml AJP snippet:
<!-- [CodeBlockStart:2f49fc30-1b77-473e-b910-364743db78d4]--><Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" ></Connector>
<!-- [CodeBlockEnd:2f49fc30-1b77-473e-b910-364743db78d4]-->
Apache's httpd.conf:
<!-- [CodeBlockStart:f1cd1a59-04c4-4911-897f-2073799eea4d]--><IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
<!-- [CodeBlockEnd:f1cd1a59-04c4-4911-897f-2073799eea4d]-->
The above configuration, under load, may cause mod_jk to be very slow and unresponsive, cause http errors, and cause half-closed connections. These problems can arise because there are no connection timeouts specified to take care of orphaned connections, no error handling properties defined in workers.properties, and no connection limits set in Apache and Tomcat.
First off, lets take care of Tomcat:
Configuring server.xml:
The main concern with server.xml is setting the connectionTimeout which
sets the SO_TIMEOUT of the underlying socket. So when a connection in
Tomcat hasn't had a request in the amount of time specified by
connectionTimeout, then the connection dies off. This is necessary because if the connection hasn't been used for a certain period of
time then there is the chance that it is half-close on the mod_jk end.
If the connection isn't closed there will be an inflation of threads
which can over time hit the maxThreads count in Tomcat then Tomcat will
not be able to accept any new connections. A connectionTimeout of 600000 (10 minutes) is a good number to start out with. There may be a situation where the connections are not being recycled fast enough, in this instance the connectionTimeout could be lowered to 60000 or 1 minute.
When setting connectionTimeout in Tomcat, mod_jk should also have
connect_timeout/prepost_timeout set, which allows detection that the
Tomcat connection has been closed and preventing a retry request.
The recommended value of maxThreads is 200 per CPU, so here we assume the server is a single core machine. If it has been quad core, we could push that value to 800, and more depending on RAM and other machine specs.
<!-- [CodeBlockStart:3d26bf05-3da7-471e-8f6c-2e52c6c6ac0e]-->
<Connector port="8009"
address="${jboss.bind.address}"
emptySessionPath="true"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3"
maxThreads="200"
connectionTimeout="600000"></Connector>
<!-- [CodeBlockEnd:3d26bf05-3da7-471e-8f6c-2e52c6c6ac0e]-->
Configuring workers.properties:
See comments inline.
<!-- [CodeBlockStart:51c2d9e7-89b1-4a63-81d8-9581852df5d9]-->
worker.list=loadbalancer,status
worker.template.port=8009
worker.template.type=ajp13
worker.template.lbfactor=1
#ping_timeout was introduced in 1.2.27
worker.template.ping_timeout=1000
#ping_mode was introduced in 1.2.27, if not using 1.2.27 please specify connect_timeout=10000 and prepost_timeout=10000 as an alternative
worker.template.ping_mode=A
worker.template.socket_timeout=10
#It is not necessary to specify connection_pool_timeout if you are running the worker mpm
worker.template.connection_pool_timeout=600
#Referencing the template worker properties makes the workers.properties shorter and more concise
worker.node1.reference=worker.template
worker.node1.host=192.168.1.2
worker.node2.reference=worker.template
worker.node2.host=192.168.1.3
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=True
worker.status.type=status
<!-- [CodeBlockEnd:51c2d9e7-89b1-4a63-81d8-9581852df5d9]-->
The key points in the above workers.properties is we've added limits for the connections mod_jk makes. With the base configuration, socket timeouts default to infinite. The other important properties are ping_mode and ping_timeout which handle probing a connection for errors and connection_pool_timeout which must be set to equal server.xml's connectionTimeout when using the prefork mpm. When these two values are the same, after a connection has been inactive for x amount of time, the connection in mod_jk and Tomcat will be closed at the same time, preventing a half-closed connection.
Configuring Apache
Make note that maxThreads for the AJP connection should coincide with
the MaxClients set in Apache's httpd.conf. MaxClients needs to be set
in the correct module in Apache.
This can be determined by running httpd -V:
<!-- [CodeBlockStart:cdfc802a-455d-450b-9852-7fc2778f9580]-->
# httpd -V
Server version: Apache/2.2.3
Server built: Sep 11 2006 09:43:05
Server's Module Magic Number: 20051115:3
Server loaded: APR 1.2.7, APR-Util 1.2.8
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture: 32-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="logs/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
<!-- [CodeBlockEnd:cdfc802a-455d-450b-9852-7fc2778f9580]-->
Which tells me the Server MPM is Prefork. This is not always 100% accurate so you should also view the output of /etc/sysconfig/httpd to see if the following line is there: HTTPD=/usr/sbin/httpd.worker. If it is commented out you are running prefork, otherwise if uncommented worker.
httpd.conf:
<!-- [CodeBlockStart:552105f6-40da-4988-918d-280bdf9f1964]--><IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
MaxClients 200
MaxRequestsPerChild 0
</IfModule>
<!-- [CodeBlockEnd:552105f6-40da-4988-918d-280bdf9f1964]-->
<!-- [CodeBlockStart:de29d684-d586-4465-888e-10c422b50f80]-->
Or if Apache is using worker, it is
<IfModule worker.c>
StartServers 2
MaxClients 200
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
<!-- [CodeBlockEnd:de29d684-d586-4465-888e-10c422b50f80]-->
MaxRequestsPerChild is 0, this is the recommended value when using
mod_jk as mod_jk keeps open persistent connections. The key values in
the above configuration are MaxClients and MaxRequestsPerChild, the rest
of the values are left as default. Note that MaxRequestsPerChild is
recommended to be 0 however the value may need to be greater than 0
depending on if Apache is used for other modules also, especially in the
case of resource leakage.
Advanced worker-mpm Configuration
To get the most out of your mod_jk setup you should be using Apache's worker mpm which provides a definite performance improvement over the prefork mpm. The following section will detail how to configure Apache/mod_jk/Tomcat with the worker mpm and the math behind the configuration.
Let's start out with the worker mpm configuration
<!-- [CodeBlockStart:b59d229c-4b25-4383-a97c-3801800ca4ae]--><IfModule mpm_worker_module>
ThreadLimit 100
StartServers 5
MaxClients 1000
MinSpareThreads 100
MaxSpareThreads 1000
ThreadsPerChild 100
MaxRequestsPerChild 0
</IfModule>
<!-- [CodeBlockEnd:b59d229c-4b25-4383-a97c-3801800ca4ae]-->
The optimal configuration completely depends on the hardware being used and the load requirements. But a general rule of thumb, keep processes low and thread count high. To determine the number of processes Apache will use simply divide MaxClients by ThreadPerChild. So in this case MaxClients (1000) / ThreadsPerChild (100) = Processes (10), so Apache will allocate a maximum of 100 threads per each 10 child processes resulting in a total of 1000 possible clients.
Now to translate this to mod_jk, mod_jk maintains a connection pool for each worker defined in workers.properties. By default with Apache mod_jk sets connection_pool_size to ThreadsPerChild, so in the above case that would translate to 100, giving 1000 possible connections to JBoss. This may or may not be desired.
Let's take a common example, there will be 3 JBoss servers that combined needed to be able to handle 900 concurrent connections
<!-- [CodeBlockStart:c9515c2c-9a77-482e-a381-1d8bd8c2a364]-->
worker.list=loadbalancer,status
worker.template.type=ajp13
worker.template.port=8009
worker.template.ping_mode=A
worker.template.connection_pool_size=30
worker.template.socket_timeout=10
worker.template.retries=20
worker.node1.reference=worker.template
worker.node1.host=192.168.0.101
worker.node2.reference=worker.template
worker.node2.host=192.168.0.102
worker.node3.reference=worker.template
worker.node3.host=192.168.0.103
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2, node3
worker.loadbalancer.sticky_session=True
worker.status.type=status
<!-- [CodeBlockEnd:c9515c2c-9a77-482e-a381-1d8bd8c2a364]-->
The above configuration tells mod_jk to multiplex 30 connections to the available Apache processes, which is 10 processes. So that means 30 connections multiplexed over 10 processes gives 300 possible connections to each backend worker. Furthermore, the total connections able to be used in this configuration from Apache is 900 which means 100 connections will be left over for static content or whatnot.
Next configure maxThreads in each ajp connector to match the above.
Node 1 ajp connector:
<!-- [CodeBlockStart:9df0286a-40b8-4a27-bcec-d34167c3fb7a]--><Connector port="8009"
address="${jboss.bind.address}"
emptySessionPath="true"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3"
maxThreads="300"
connectionTimeout="600000"></Connector>
<!-- [CodeBlockEnd:9df0286a-40b8-4a27-bcec-d34167c3fb7a]-->
Node 2 ajp connector:
<!-- [CodeBlockStart:a163f379-21b4-464c-9e63-1108802a7cc6]--><Connector port="8009"
address="${jboss.bind.address}"
emptySessionPath="true"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3"
maxThreads="300"
connectionTimeout="600000"></Connector>
<!-- [CodeBlockEnd:a163f379-21b4-464c-9e63-1108802a7cc6]-->
Node 3 ajp connector:
<!-- [CodeBlockStart:b3c45388-5ba2-4c0d-a35c-8706df30bd87]--><Connector port="8009"
address="${jboss.bind.address}"
emptySessionPath="true"
enableLookups="false"
redirectPort="8443"
protocol="AJP/1.3"
maxThreads="300"
connectionTimeout="600000"></Connector>
<!-- [CodeBlockEnd:b3c45388-5ba2-4c0d-a35c-8706df30bd87]-->
Remember when using connectionTimeout which is always recommended, prepost_timeout and connect_timeout also need to be set, which is done. I'm not showing sticky session configuration, but that covered in the main mod_jk article in using mod_jk with JBoss.
发表评论
-
sysctl.conf
2011-07-06 14:54 1756fs.file-max=51200 net.core.net ... -
top的替代工具
2011-06-28 15:06 1472dstat -cgilpymn collectl and ... -
有用的小工具
2010-12-23 11:51 1351pv stream nessus Nikto ski ... -
调优linux i/o 行为
2010-11-25 11:27 2920http://www.westnet.com/~gsmith/ ... -
服务器部署工具
2010-11-12 16:32 2062http://www.linuxlinks.com/artic ... -
开源的配置管理工具
2010-11-12 16:24 1474最佳开源配置管理工具: Puppet / 提名:OpenQ ... -
优化ext3的mount选项
2010-11-12 10:24 1351defaults,commit=600,noatime,nod ... -
恢复r710biso 出厂设置
2010-11-10 10:30 1224ALT+E/F/B -
每进程io监控工具
2010-11-02 14:14 1662iodump iotop iopp pidstat b ... -
Intel Xeon 5500/5600系列 CPU服务器内存设置
2010-11-01 21:29 4850http://www.xasun.com/article/2a ... -
zabbix短信报警脚本文件
2010-10-21 14:28 2791附件 -
天外飞仙级别的Linux Shell命令
2010-10-16 09:59 1448本文编译自commandlinefu.com ( 应该是 Ca ... -
lenny+r710+lvm 重启问题解决方案
2010-10-15 14:22 1129ro rootdelay=10 quiet -
fai,debian 自动安装工具
2010-10-15 13:36 1118http://sys.firnow.com/linux/x80 ... -
十个服务器监控工具
2010-09-26 11:44 1836一位国外的技术博主在 ... -
restrict authorized_keys
2010-09-06 09:45 1265command="/home/someuser/rs ... -
sysctl优化设置
2010-09-05 11:25 1143sysctl 是一个用来在系统运作中查看及调整系统参数的工 ... -
proc文件系统
2010-09-05 11:22 1259什么是proc文件系统? proc文件系统是一个伪 ... -
nfs使用
2010-09-02 17:01 1156http://www.linuxhomenetworking. ... -
lsof example
2010-08-23 12:40 12741、查看文件系统阻塞 ...
相关推荐
3. **配置Apache**:在Apache的配置文件(如httpd.conf)中加载`mod_jk`模块,并指定模块路径。例如,添加`LoadModule jk_module /path/to/mod_jk.so`。 4. **配置`mod_jk`**:创建一个名为`workers.properties`的...
2. **配置httpd.conf**:编辑Apache的主配置文件`httpd.conf`,添加`LoadModule`指令来加载mod_jk模块,如: ``` LoadModule jk_module modules/mod_jk.so ``` 3. **设置JKMount**:定义哪些URL由mod_jk处理。...
3. **配置Apache**:将mod_jk.so移动到Apache的模块目录,例如`/usr/lib/apache2/modules/`,然后在Apache的配置文件`httpd.conf`中添加以下行来加载模块: ``` LoadModule jk_module /usr/lib/apache2/modules/...
然后,将mod_jk.so文件添加到Apache服务器的模块目录,并在httpd.conf配置文件中加载该模块。 接着,配置mod_jk。这通常涉及编辑mod_jk.conf或者通过Include指令将其包含在httpd.conf中。你需要定义worker....
Apache Tomcat与mod_jk的整合是企业级Web应用部署中常见的架构模式,通过mod_jk,可以有效地管理和优化Apache与Tomcat之间的通信,提高系统的稳定性和性能。正确地选择和配置mod_jk版本,以及理解其工作原理和配置...
总之,通过Apache2的mod_jk模块,我们可以实现Web服务器和应用服务器的无缝集成,优化资源分配,提升网站性能。配置过程虽然涉及多个步骤,但只要按照上述指导操作,就能顺利完成。在实际部署中,还需要根据具体环境...
`mod_jk`使用`worker.properties`配置文件来定义和管理与Tomcat实例的连接信息,包括IP地址、端口、最大连接数等。 ### 3. 配置`mod_jk` 在Apache中启用`mod_jk`,需要在`httpd.conf`配置文件中加载模块,并设置...
本教程将详细阐述如何在Windows环境下配置基于Jboss7、Apache 2.2.25和mod_jk的集群,实现负载均衡。首先,确保您已经下载了所需的所有软件,包括Jboss7、Apache HTTP Server 2.2.25和mod_jk模块。 1. **安装与准备...
**Apache mod_jk模块详解** Apache mod_jk是Apache HTTP...了解和熟练掌握mod_jk的配置和使用,对于管理和优化Java Web应用的部署至关重要。同时,源代码的提供使得开发者有机会深入研究其内部机制,进一步优化性能。
标题 "mod_jk-1.2.42-win32-VC15" 指的是 Apache Tomcat 与 Apache HTTP Server 之间的连接模块 mod_jk 的一个特定版本,适用于 ...在实际操作中,还需要关注版本兼容性、安全性更新以及优化配置以满足特定需求。
这个连接器的主要作用是通过mod_jk.so模块在Apache和Tomcat之间建立通信,实现负载均衡、故障转移等功能,从而优化Java应用的性能和可扩展性。 标签“mod_jk”,“mod_jk.so”,“httpd-2.2.x”分别指代了Apache的...
2. **配置httpd.conf**:在Apache的配置文件httpd.conf中加载mod_jk模块,并指定mod_jk的工作模式(例如,worker.properties文件的位置)。 3. **创建worker.properties**:在worker.properties文件中定义Tomcat...
3. **编辑httpd.conf**:打开Apache的配置文件httpd.conf,添加LoadModule指令来加载mod_jk模块。例如: ``` LoadModule jk_module modules/mod_jk.so ``` 4. **配置worker.properties**:创建或编辑名为worker....
`mod_jk.so 1.2.40 for Windows`是专为Windows平台设计的一个特定版本,旨在优化在Windows环境下运行的Apache和Tomcat之间的交互。 ### 1. mod_jk模块介绍 mod_jk是Apache的负载均衡和反向代理模块,它负责将HTTP...
【Apache2.2 with mod_jk】:这个标题指出我们关注的是Apache HTTP Server 2.2版本,并且它已经配置了mod_jk模块。Apache HTTP Server是世界上最流行的Web服务器软件,而mod_jk是Apache的一个模块,专门用于连接...
5. **配置mod_jk**: - 下载mod_jk模块的源代码,例如:`wget https://downloads.apache.org/tomcat/tomcat-connectors/jk/source/jk-1.2.46-src.tar.gz` - 解压:`tar -zxvf jk-1.2.46-src.tar.gz` - 进入源码...
7. **优化和监控**:根据实际需求,可以进一步调整`mod_jk.conf`中的参数,如连接池大小、超时设置等,以实现最佳性能。同时,可以使用mod_jk的日志功能来监控和分析系统状态。 在Windows环境下使用Apache2.2+mod_...
**标题:“mod_jk-1.2.41-win64”** **描述解析:** “mod_jk”是Apache HTTP服务器与Tomcat应用服务器之间的集成模块,它允许...10. **更新与安全**:及时更新mod_jk至最新版本,以获取最新的安全修复和性能优化。
2. **配置Apache**:在Apache的配置文件`httpd.conf`中,通过`LoadModule`指令加载mod_jk模块,并配置`JkWorkersFile`指定worker.properties的位置,`JkMount`则用于定义哪些URL由mod_jk处理。 3. **配置Tomcat**:...
Apache mod_jk是构建高效、可扩展Web应用的关键组件,通过它可以实现Apache与Tomcat的无缝集成,优化性能并实现集群部署。正确配置mod_jk和Tomcat集群,能够为大型网站提供稳定、高性能的服务。在实际使用中,需根据...