tomcat参数 acceptCount maxConnections maxThreads
所属分类 tomcat
浏览量 1654
tomcat8.5
org/apache/tomcat/util/net/NioEndpoint.java
ServerSocketChannel serverSock = ServerSocketChannel.open();
socketProperties.setProperties(serverSock.socket());
InetSocketAddress addr = (getAddress()!=null?new InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort()));
serverSock.socket().bind(addr,getAcceptCount());
public void bind(SocketAddress endpoint, int backlog) throws IOException
backlog
requested maximum length of the queue of incoming connections.
accept队列长度 默认 100
accept队列中连接的个数达到acceptCount时, 进来的请求会被拒绝
maxConnections
接收和处理的最大连接数 ,处理连接数达到maxConnections时,Acceptor线程不会读取accept队列中的连接 ,
这时会一直阻塞,直到处理的连接数小于maxConnections ,设置为-1,连接数不受限制。
默认值与协议有关
NIO 10000
APR/native 8192
BIO 默认值为maxThreads(配置了Executor 为 Executor的maxThreads)
protected class Acceptor extends AbstractEndpoint.Acceptor {
state = AcceptorState.RUNNING;
try {
//if we have reached max connections, wait
countUpOrAwaitConnection();
SocketChannel socket = null;
try {
// Accept the next incoming connection from the server
// socket
socket = serverSock.accept();
} catch (IOException ioe) {
// We didn't get a socket
countDownConnection();
if (running) {
// Introduce delay if necessary
errorDelay = handleExceptionWithDelay(errorDelay);
// re-throw
throw ioe;
} else {
break;
}
}
// if we have reached max connections, wait
countUpOrAwaitConnection();
protected void countUpOrAwaitConnection() throws InterruptedException {
if (maxConnections==-1) return;
LimitLatch latch = connectionLimitLatch;
if (latch!=null) latch.countUpOrAwait();
}
connectionLimitLatch = new LimitLatch(getMaxConnections());
maxThreads
请求处理最大线程数 ,默认值 200
如果Connector绑定了Executor ,则使用 Executor 的配置
可处理的连接数 maxConnections,可同时接收的连接数 maxConnections+acceptCount
acceptCount 过大 请求等待时间会很长 ,过小 容易 返回 connection refused
线程池Executor
maxIdleTime 线程最大空闲时间 ms 默认 60000(1分钟)
org.apache.tomcat.util.threads.ThreadPoolExecutor
org.apache.catalina.core.StandardThreadExecutor
taskqueue = new TaskQueue(maxQueueSize);
TaskThreadFactory tf = new TaskThreadFactory(namePrefix,daemon,getThreadPriority());
executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf);
executor.setThreadRenewalDelay(threadRenewalDelay);
NioEndpoint
public void createExecutor() {
internalExecutor = true;
TaskQueue taskqueue = new TaskQueue();
TaskThreadFactory tf = new TaskThreadFactory(getName() + "-exec-", daemon, getThreadPriority());
executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), 60, TimeUnit.SECONDS,taskqueue, tf);
taskqueue.setParent( (ThreadPoolExecutor) executor);
}
上一篇
下一篇
java线程池实例
tomcat线程池要点
java线程池系列文章汇总
Java中的整数缓存IntegerCache
JMX之ObjectName
tomcat之JMXProxyServlet