gpt4 book ai didi

apache2 - Tomcat 当前线程数

转载 作者:行者123 更新时间:2023-12-02 02:07:44 24 4
gpt4 key购买 nike

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?

最佳答案

当前线程由apache动态管理。

来自apache源代码中的worker.c:线程根据需要启动。以下是启动工作线程的主要流程。

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);

当空闲线程> max_spare_threads时,apache会尝试通过杀死子进程/线程来减少空闲线程,以减少空闲线程数。

if (idle_thread_count > max_spare_threads) {
/* Kill off one child */
ap_worker_pod_signal(pod, TRUE);
retained->idle_spawn_rate = 1;
}

apache内部管理这些子进程,并使用信号与子进程通信以根据需要调整线程。所有线程均在 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

关于apache2 - Tomcat 当前线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13653147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com