Tomcat连接池的maxActive和maxIdle之间的区别是什么? [英] What is the difference between maxActive vs. maxIdle for Tomcat connection pools?

查看:3793
本文介绍了Tomcat连接池的maxActive和maxIdle之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tomcat连接池有一个名为maxActive的设置和一个名为maxIdle的设置我的问题。

The tomcat connection pool has a setting called maxActive and a setting called maxIdle my questions are.


  1. 这两个设置有什么区别?

  2. 什么是真实世界示例场景,您可能有一个不同的maxActive值,而不是maxIdle?

由于某些原因,文档对我没有意义。根据
http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

For some reason the docs are not making sense to me. maxActive and maxIdle exist on both the apache dbcp and the tomact 7 jdbc-pool according to the docs at http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html


maxActive(int)可以同时从此池分配的活动连接数量
的最大数量。默认值为100

maxActive (int) The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100

maxIdle(int)应始终保留池中的
的最大连接数。默认值为maxActive:100 Idle
定期检查连接(如果启用),并且
空闲时间超过minEvictableIdleTimeMillis的连接将被释放。
(另见testWhileIdle)

maxIdle (int) The maximum number of connections that should be kept in the pool at all times. Default value is maxActive:100 Idle connections are checked periodically (if enabled) and connections that been idle for longer than minEvictableIdleTimeMillis will be released. (also see testWhileIdle)


推荐答案

maxActive是直接的。 maxIdle可以这样解释 - 假设你有100个最大活动连接,并说你设置maxIdle为80.假设没有请求去数据库,只有80连接将被测试(通过验证查询),并将保持活动。其他20将关闭。因此,在任何时候,您只能有80个空闲连接。

您可能希望将其设置为不同的数字,以防止连接到数据库的其他(不必要的)连接。 Cos每个由数据库服务的连接都消耗资源(如内存)。

但是,假设您已将maxActive大小设置为100,并且所有100几乎都在使用,则此设置显然不会

maxActive is straight forward. maxIdle can be explained in this way - say you have 100 max Active connections and say you set maxIdle to 80. Assuming there are no requests going to the database, only 80 connections will be tested (via the validationquery) and will stay active. The other 20 will be closed. So at any point you can only have 80 idle connections.
You might want to set this to be a different number to prevent additional (unnecessary) connections going out to the database. Cos every connection that is served by the database consumes resources (like memory).
But, assuming you have set the maxActive size to 100 and all 100 are in use almost all the time, this setting will obviously not matter.

这篇关于Tomcat连接池的maxActive和maxIdle之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆