在负载测试期间,服务器响应时间变得非常慢



我正在使用Jmeter(Oracle,Tomcat,Spring)分析我的web应用程序的性能。

Number of threads :20
Ramp up: 2
Loop: 500

我只模拟一个简单的登录到网站与Jmeter。

当我在上面的这些设置中启动时。前3分钟,它开始非常快(av响应时间为500ms),但它开始迅速变慢,到15分钟时,响应时间降至5秒。完成一个请求需要几分钟。

我不确定这是正常的还是问题是Tomcat或实际上我的c3po池设置不正确。

这是我的设置c3po:

    <property name="testConnectionOnCheckout" value="false" />  <!-- do not test connection isValid on checkout as it has bad performance result -->
    <property name="testConnectionOnCheckin" value="true" />    <!-- test connection isValid on checkin -->
    <property name="idleConnectionTestPeriod" value="60" />     <!-- test every 60 seconds -->
    <property name="checkoutTimeout" value="5000" />            <!-- The number of milliseconds a client calling getConnection() will wait for a Connection to be checked-in or acquired when the pool is exhausted. -->
    <property name="acquireRetryAttempts" value="30" />         <!-- Defines how many times c3p0 will try to acquire a new Connection from the database before giving up. -->
    <property name="acquireRetryDelay" value="1000" />          <!-- Milliseconds, time c3p0 will wait between acquire attempts. -->
    <property name="breakAfterAcquireFailure" value="true" />   <!-- If true, a pooled DataSource will declare itself broken and be permanently closed if a Connection cannot be obtained from the database after making acquireRetryAttempts to acquire one. -->
    <property name="maxIdleTime" value="180" />                 <!-- 3 minutes, then die -->
    <property name="maxConnectionAge" value="300" />            <!-- 5 minutes, then die -->
    <property name="minPoolSize" value="1" />
    <property name="initialPoolSize" value="2" />
    <property name="maxPoolSize" value="25" />
    <property name="acquireIncrement" value="1" />              <!-- ramp up the pool with 1 connection if all others are in use -->
    <property name="unreturnedConnectionTimeout" value="360" /> <!-- in seconds (6 minutes), actually this should be necessary if connections are not closed properly and thus are leaked -->
    <property name="numHelperThreads" value="10" />
    <property name="maxStatementsPerConnection" value="5" />

我还安装了VisualVm来监控Tomcat,但不确定如何分析它,我应该检查内存池或堆或Perm gen..?

你知道为什么它会变慢或者我怎么检查它吗?

Ps旧代内存池大小图峰值时,响应时间开始变慢可能是任何关系?我的Cm连接设置为

 -Xmx1024m -XX:MaxPermSize=512M

您可能会耗尽DB连接池,因为它只设置为最大25个。一旦达到最大值,您的服务器将在几分钟内存储所有这些连接请求,然后将它们释放回JMeter(而JMeter永远不会停止发出请求)

你可以尝试增加连接池的大小,或者缩短连接池被释放回客户端的时间。

你还应该调查为什么要花这么长时间才能得到登录请求的响应。

编辑:在

下面添加示例

我不认为这里的问题是在Tomcat内部(我假设Tomcat只是处理请求并充当客户机和数据库之间的代理),它可能是在你如何测试自己。

如果JMeter重复发出相同的登录请求,它可能会备份数据库,因为它可能会在登录处理期间锁定该记录。由于这种可能性,您不应该在负载测试时使用相同的用户(无论如何,这不是一个现实的情况)。一个更好的测试是创建许多用户,并在负载测试期间循环使用它们。

它听起来像是你创建了许多线程来执行登录,它导致数据库上的排队,这导致tomcat上的连接排队,这使得问题随着时间的推移变得更糟。

我会遵循@Quinnlv的声明。实现一个模拟登录,看看它是如何执行的。

最新更新