Tomcat集群环境中的JDBC连接池 [英] JDBC Connection Pooling in a Tomcat Cluster Environment

查看:211
本文介绍了Tomcat集群环境中的JDBC连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此我还比较陌生,但是我设置了一个Tomcat群集(使用httpd中的mod_proxy)和会话复制(单独的Redis服务器)以实现容错功能.

I'm relatively very new to this, but I have a Tomcat cluster set up (using mod_proxy from httpd) with session replication (separate redis server) for fault-tolerance.

关于此设置,我有几个问题:

I have a couple of questions about this setup:

  1. 我的应用程序(spring/hibernate)的每个用户的数据库都不同.因此,这里的问题是数据源(使用spring和hibernate进行持久化)是在Tomcat级别创建的.因此,无论我做什么连接池,都将在服务器级别进行.

  1. My application (spring/hibernate) has a different database per user. So the problem here is that the data source (using spring along with hibernate for persistence) is created at Tomcat level. Thus, whatever connection pooling I do will be at server level.

根据集群配置,Tomcat实例将创建自己的连接池.

As per the cluster configuration the Tomcat instances will create their own Connection Pool.

我想知道是否可以使用Tomcat在群集级别进行连接池,即是否可以确保群集中的所有服务器都使用共享连接池?

I'd like to know if connection pooling is possible at a cluster level using Tomcat i.e. is there a way to make sure that all the servers in the cluster are using the shared Connection Pool?

由于性能问题,我不想在每个Tomcat实例上配置DataSource.在群集设置之前,将应用程序部署在单个服务器上,并配置DataSource使得每个DataSource的连接池中仅允许几(50)个连接.

I do not want to configure a DataSource on every Tomcat instance because of performance issues. Before the cluster setup, the application was deployed on a single server and the DataSource was configured such that it allowed only a few (50) connections in a connection pool per DataSource.

现在,在集群环境中,我无力在每个Tomcat上创建或拆分那么多的连接,而且节点的动态注册会带来更多问题.我还想知道,如果无法实现连接池或效率低下,是否可以通过其他方法解决此问题?

Now in a clustered environment, I cannot afford to create or split those number of connections on every Tomcat, and also dynamic registration of nodes will create further problems. I'd also like to know is there some alternative solution to this problem if connection pooling is not possible or inefficient?

推荐答案

由于第二个问题更简单,我将以相反的顺序处理您的问题.

I'm going to handle your questions in reverse order, since the second one is more simple.

无法在群集范围内配置Tomcat中的数据库连接池:您必须为群集中的每个节点配置一个单独的池.但这并不一定是坏消息……将一个节点配置为在每个节点的连接池中具有5个,10个或100个连接没有错.

Database connection pooling in Tomcat cannot be configured cluster-wide: you have to configure a separate pool for each node in the cluster. But this doesn't have to be bad news... there's nothing wrong with configuring a node to have 5 or 10 or 100 connections in the connection pool on each node.

是的,您可能最终遇到这样的情况:一次有太多用户连接到数据库,这使您的数据库不堪重负,但是单个节点也可能发生这种情况.多节点在概念上没有什么不同,单节点也不是正确的.

It's true, you might end up with a situation where you have too many users connecting to the database at a single time which overwhelms your database, but that could also happen with a single node as well. There isn't anything conceptually different about multiple-nodes that wouldn't also be true for a single node.

关键是要确保您的集群适当地平衡用户,以使您没有限制,例如每个节点5个数据库连接,但是100个用户最终在一个节点上,而其他节点每个节点只有5个用户.在这种情况下,受欢迎的节点(100个用户)将必须共享这5个连接,而在其他节点上,每个用户都将自己获得一个连接.

the key is to make sure that your cluster balances users appropriately so that you don't have a limit of e.g. 5 database connections per node, but 100 users end up on one node while the other nodes only have 5 users per node. In that case, the popular node (100 users) will have to share those 5 connections while on the other nodes, each user gets a connection all to themselves.

回到您的第一个项目,这比较复杂.如果每个用户都有一个单独的数据库,那么连接池是不可能完成的事情,因为您绝对必须每次都为每个用户建立一个新连接.这些连接不是可合并的,至少在没有十分小心的情况下是不可合并的.听起来您有一个体系结构问题,可能需要解决,然后才能确定该问题的技术解决方案.

Back to your first item, which is more complicated. If you have a separate database per user, then connection-pooling is an impossible thing to accomplish because you will absolutely have to establish a new connection for every user every time. Those connections aren't poolable, at least not without being quite careful about it. It sounds like you have an architectural issue that you might have to solve before you can identify a technical solution to that issue.

这篇关于Tomcat集群环境中的JDBC连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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