Tomcat和appache2通过AJP连接。我有tomcat和apache的这些配置:
<Connector port="8009" protocol="AJP/1.3"
URIEncoding="UTF-8"
redirectPort="8443"
connectionTimeout="20000"
maxThreads="512" />
<IfModule mpm_event_module>
StartServers 5
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
ServerLimit 1024
MaxClients 512
MaxRequestsPerChild 0
</IfModule>
当我去tomcat经理时,我看到了:
"ajp-bio-8009"
Max threads: 512 Current thread count: 256 Current thread busy: 231
当前线程忙有时达到256.为什么当前线程数不是设置为512?
答案 0 :(得分:2)
当前线程由apache动态管理。
来自work.c的apache源代码: 线程根据需要启动。以下是启动工作线程的主要流程。
static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
startup_children(remaining_children_to_start); //server/mpm/worker/worker.c
if (make_child(ap_server_conf, i) < 0) { //server/mpm/worker/worker.c
child_main(slot); //server/mpm/worker/worker.c
rv = apr_thread_create(&start_thread_id, thread_attr, start_threads
rv = apr_thread_create(&threads[i], thread_attr, worker_thread, my_info, pchild);
当空闲线程&gt; max_spare_threads,apache会尝试通过kill子进程/线程来减少备用线程,以减少空闲线程数。
if (idle_thread_count > max_spare_threads) {
/* Kill off one child */
ap_worker_pod_signal(pod, TRUE);
retained->idle_spawn_rate = 1;
}
内部apache管理这些子进程,并使用signal与子进程通信以根据需要调整线程。
所有主题都在ap_scoreboard_image->servers[i][j];
apache将监视线程数,并使用套接字发送让infoCollector知道。 大致通过以下代码(不相关的行被删除)
./httpd/modules/cluster/mod_heartbeat.c
for (i = 0; i < ctx->server_limit; i++) {
....
for (j = 0; j < ctx->thread_limit; j++) {
ws = &ap_scoreboard_image->servers[i][j];
if (res == SERVER_READY && ps->generation == mpm_generation) {
ready++;
}
}
}
len = apr_snprintf(buf, sizeof(buf), "v=%u&ready=%u&busy=%u", MSG_VERSION, ready, busy);
...
rv = apr_socket_sendto(sock, ctx->mcast_addr, 0, buf, &len);
在Tomcat中: 这些线程信息收到: ./tomcat/java/org/apache/catalina/ha/backend/CollectedInfo.java 并显示: /Users/twer/lab/tomcat/java/org/apache/catalina/manager/StatusTransformer.java
writer.write(" currentThreadCount=\"" + mBeanServer.getAttribute(tpName, "currentThreadCount") + "\"");
这里显示的大部分代码都是主流,不相关的行被删除。下载源代码以了解更多信息。 下载apache src:http://www.apache.org/dist/httpd/?C=S;O=A 下载tomcat src:http://tomcat.apache.org/download-70.cgi