连接过多,AWS EC2上的tomcat7 [英] Too many connections , tomcat7 on AWS EC2

查看:53
本文介绍了连接过多,AWS EC2上的tomcat7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册了一个新的AWS免费帐户,并且试图通过JNDI Pool连接将Tomcat连接到RDS数据库. Beanstalk上部署的战争是默认战争(没有任何数据库连接或查询)

I signed up for a new AWS free account, and I am trying to to connect the Tomcat to the RDS database through JNDI Pool connection. The war deployed on the Beanstalk is the default one (which does not have any database connection or queries)

这是我的context.xml的样子

Here is how my context.xml looks like

<Context>

<WatchedResource>WEB-INF/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<Manager pathname="" />

<!-- Uncomment this to enable Comet connection tacking (provides events
     on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Resource name="jdbc/web"
      auth="Container"
      type="javax.sql.DataSource"
      factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
      testWhileIdle="true"
      testOnBorrow="true"
      testOnReturn="false"
      validationQuery="SELECT 1"
      timeBetweenEvictionRunsMillis="30000"
      maxActive="10"
      maxIdle="5"
      minIdle="1"
      removeAbandonedTimeout="60"
      removeAbandoned="false"
      logAbandoned="true"
      minEvictableIdleTimeMillis="30000"
      closeMethod="close"
      jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
      username="root"
      password="password"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://aamhszwo5p1rrw.cf7vbk9ataaz.us-west-2.rds.amazonaws.com:3306/broadleaf"/>
<Resource name="jdbc/storage"
          auth="Container"
          type="javax.sql.DataSource"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          testWhileIdle="true"
          testOnBorrow="true"
          testOnReturn="false"
          validationQuery="SELECT 1"
          timeBetweenEvictionRunsMillis="30000"
          maxActive="10"
          maxIdle="5"
          minIdle="1"
          removeAbandonedTimeout="60"
          removeAbandoned="false"
          logAbandoned="true"
          minEvictableIdleTimeMillis="30000"
          closeMethod="close"
          jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
          username="root"
          password="password"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://aamhszwo5p1rrw.cf7vbk9ataaz.us-west-2.rds.amazonaws.com:3306/broadleaf"/>
<Resource name="jdbc/secure"
          auth="Container"
          type="javax.sql.DataSource"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          testWhileIdle="true"
          testOnBorrow="true"
          testOnReturn="false"
          validationQuery="SELECT 1"
          timeBetweenEvictionRunsMillis="30000"
          closeMethod="close"
          maxActive="10"
          maxIdle="5"
          minIdle="1"
          removeAbandonedTimeout="60"
          removeAbandoned="false"
          logAbandoned="true"
          minEvictableIdleTimeMillis="30000"
          jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
          username="root"
          password="password"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://aamhszwo5p1rrw.cf7vbk9ataaz.us-west-2.rds.amazonaws.com:3306/broadleaf"/>
<Resource name="jdbc/event"
          auth="Container"
          type="javax.sql.DataSource"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          testWhileIdle="true"
          testOnBorrow="true"
          testOnReturn="false"
          validationQuery="SELECT 1"
          timeBetweenEvictionRunsMillis="30000"
          closeMethod="close"
          maxActive="10"
          maxIdle="5"
          minIdle="1"
          removeAbandonedTimeout="60"
          removeAbandoned="false"
          logAbandoned="true"
          minEvictableIdleTimeMillis="30000"
          jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
          username="root"
          password="password"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://aamhszwo5p1rrw.cf7vbk9ataaz.us-west-2.rds.amazonaws.com:3306/broadleaf"/>

</Context>

当我重新启动tomcat时,我收到以下异常.

When I restart my tomcat I receive the following exception.

SEVERE: Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)

我不确定在没有让我的web应用程序触发任何查询甚至连接到数据库的情况下,如何最大化连接

I am not sure how the connections are getting maxed out without having my webapp fire any query or even connect to database

推荐答案

您正面临到AWS数据库中允许的连接配额.通过建立4个数据源(每10个连接到该数据库中),您将超过该限制.

You're facing a quota of allowed connections into your AWS database. By setting up 4 datasources with each 10 connections into that database, you exceed that limit.

通过将maxActive降低到更低的水平(例如... 3?),您应该会很好(暂时)

By reducing the maxActive to something lower (say... 3?) you should be good to go (for now)

关于性能方面的考虑:只要您的任何一个池都没有太活跃,这就可以正常工作.

As for performance considerations: This will work fine as long as none of your pools gets too active.

从长远来看,我建议其中的一个或多个:

In the long term I'd recommend one or more of those:

  • 在AWS中的数据库上获得更大的连接配额
  • 获得更多具有不同权限的用户以反映您的期望使用情况
  • 减少池的数量-如果它们位于同一个db上并且做类似的事情,那么最好分配一个池并分配所有配额.因此,您可以在当时最需要的地方分配连接.

这篇关于连接过多,AWS EC2上的tomcat7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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