连接池是在单个服务器(使用 MySQL)上运行应用程序的多个实例的最佳方式吗?
我想用 mysql 5.1 社区版(在 win server 2008 x64 上)配置 tomcat 服务器以在单台机器上运行一个大项目。我有一个 gwt 应用程序,需要在一台 HP 服务器上运行它的 300 多个实例。
每个实例使用单独的 MySQL DB(db1 到 db300)&因此需要一个单独的连接池,这是我的 db1 连接池配置的一部分(类似于其他数据库):
<Resource name="jdbc/mysql/db1" auth="Container" type="javax.sql.DataSource" initialSize="5" maxActive="100" maxIdle="20" maxWait="30000" removeAbandoned="true" removeAbandonedTimeout="5" validationQuery="select now();" .../>
对于 300 个实例,活动连接数将为 300*100 = 30000 个活动连接!
现在我想知道是否可以在一台服务器上打开如此庞大数量的300个MySQL数据库的连接。
如果否,那么解决方案是什么?如果是,那么将使用多少资源(RAM 和 CPU)?
连接池是最好的方法还是还有其他方法?
如果连接池是最佳选择,那么我的资源部分创建池的最佳设置是什么?
I want to config tomcat server with mysql 5.1 community edition (on win server 2008 x64) to run a big project on a single machine. I've a gwt application and I need to run more than 300 instances of it on a single HP server.
Each instance uses a separate MySQL DB (db1 to db300) & so need a separate connection pool, this is part of my connection pool configuration for db1 (similar to other dbs):
<Resource name="jdbc/mysql/db1" auth="Container" type="javax.sql.DataSource" initialSize="5" maxActive="100" maxIdle="20" maxWait="30000" removeAbandoned="true" removeAbandonedTimeout="5" validationQuery="select now();" .../>
For 300 instances the number of active connection would be 300*100 = 30000 active connections!
Now I want to know if it is possible to open such a huge number of connections to 300 MySQL databases on a single server.
If no, so what's the solution and if yes then how much resources (RAM and CPU) will be used?
Is connection pooling the best way or is there another way?
If connection pooling is the best choice then what could be the best setting for my resource section to create my pools?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 300 个实例中的每个实例一次需要使用 100 个,则活动连接数仅为 30000 个。如果它们空闲,则根据您的配置,它们只会使用 1500(来自initialSize)和6000(来自maxIdle)之间的某个位置。您可能需要降低这些值以处理 300 个实例。也许
initialSize="2" maxActive="10" maxIdle="5"
就足够了?如果您确实希望所有实例都使用那么多连接,那么一台服务器可能还不够。不过,几乎不可能说出您需要多少 RAM 或 CPU,这实际上取决于您正在做什么以及您期望的活动量。
The number of active connections would only be 30000 if every single one of the 300 instances needed to use 100 at a time. If they're idle they'd only be using somewhere between 1500 (from initialSize) and 6000 (from maxIdle) based on your configuration. You'll probably want to lower these values to handle 300 instances. Perhaps
initialSize="2" maxActive="10" maxIdle="5"
is sufficient?If you really expect all instances to be using that many connections then one server is probably not enough. It's nearly impossible to say how much RAM or CPU you'll need though, it really depends on what you're doing and how much activity you expect.