WSO2 API 管理器对并行请求抛出异常

WSO2 API Manager Throws Exceptions for Paralle Requests

我正在使用 WSO2 API Manger 1.8.0。我为我的一个 REST API 启用了基于 SAML2BearerAssertion 配置文件的 OAuth 授权检查。

当我从 JMeter 发送并行 API 请求时。我在正确收到的 console.But 响应中看到了这些日志。

[2015-03-05 05:08:32,497]  WARN - APIKeyValidationServiceImpl Invalid session id for thrift authenticator.
[2015-03-05 05:08:32,495]  WARN - APIKeyValidationServiceImpl Invalid session id for thrift authenticator.
[2015-03-05 05:08:33,342]  WARN - ThriftKeyValidatorClientPool Login failed.. Authenticating again..
[2015-03-05 05:08:33,342]  WARN - ThriftKeyValidatorClientPool Login failed.. Authenticating again..
[2015-03-05 05:08:32,493]  INFO - CarbonAuthenticationUtil 'admin@carbon.super [-1234]' logged in at [2015-03-05 05:08:32,492+0000] from IP address

当我进一步增加并行负载时。就我而言,有 125 个以上的客户。它给出了这些例外。也没有收到回复。

2015-03-05 05:10:05,795]  WARN - SourceHandler Connection time out after request is read: http-incoming-634
[2015-03-05 05:10:06,752]  WARN - SourceHandler Connection time out after request is read: http-incoming-625
[2015-03-05 05:10:06,753]  WARN - SourceHandler Connection time out after request is read: http-incoming-690
[2015-03-05 05:10:06,796]  WARN - SourceHandler Connection time out after request is read: http-incoming-684
[2015-03-05 05:10:06,797]  WARN - SourceHandler Connection time out after request is read: http-incoming-648
[2015-03-05 05:10:06,797]  WARN - SourceHandler Connection time out after request is read: http-incoming-500
[2015-03-05 05:10:06,797]  WARN - SourceHandler Connection time out after request is read: http-incoming-645
[2015-03-05 05:10:08,025] ERROR - ApiMgtDAO Error when executing the SQL 
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [pool-41-thread-640] Timeout: Pool empty. Unable to fetch a connection in 60 seconds, none available[size:50; busy:50; idle:0; lastwait:60000].
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:674)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
    at org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil.getConnection(APIMgtDBUtil.java:138)
    at org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO.validateKey(ApiMgtDAO.java:710)
    at org.wso2.carbon.apimgt.keymgt.service.APIKeyValidationService.validateKey(APIKeyValidationService.java:148)
    at org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.validateKey(APIKeyValidationServiceImpl.java:131)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:274)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:262)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
[2015-03-05 05:10:08,026] ERROR - ApiMgtDAO Error when executing the SQL 
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [pool-41-thread-613] Timeout: Pool empty. Unable to fetch a connection in 60 seconds, none available[size:50; busy:50; idle:0; lastwait:60000].
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:674)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
    at org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil.getConnection(APIMgtDBUtil.java:138)
    at org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO.validateKey(ApiMgtDAO.java:710)
    at org.wso2.carbon.apimgt.keymgt.service.APIKeyValidationService.validateKey(APIKeyValidationService.java:148)
    at org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.validateKey(APIKeyValidationServiceImpl.java:131)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:274)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:262)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
[2015-03-05 05:10:08,027] ERROR - APIKeyValidationServiceImpl Error in invoking validate key via thrift..
[2015-03-05 05:10:08,027] ERROR - APIKeyValidationServiceImpl Error in invoking validate key via thrift..
[2015-03-05 05:10:08,043] ERROR - ApiMgtDAO Error when executing the SQL 
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [pool-41-thread-628] Timeout: Pool empty. Unable to fetch a connection in 60 seconds, none available[size:50; busy:50; idle:0; lastwait:60000].
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:674)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
    at org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil.getConnection(APIMgtDBUtil.java:138)
    at org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO.validateKey(ApiMgtDAO.java:710)
    at org.wso2.carbon.apimgt.keymgt.service.APIKeyValidationService.validateKey(APIKeyValidationService.java:148)
    at org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.validateKey(APIKeyValidationServiceImpl.java:131)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:274)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:262)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
[2015-03-05 05:10:08,043] ERROR - JDBCPersistenceManager Error when getting a database connection object from the Identity data source.
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [pool-41-thread-656] Timeout: Pool empty. Unable to fetch a connection in 60 seconds, none available[size:50; busy:50; idle:0; lastwait:60000].
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:674)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
    at org.wso2.carbon.identity.core.persistence.JDBCPersistenceManager.getDBConnection(JDBCPersistenceManager.java:136)
    at org.wso2.carbon.identity.thrift.authentication.dao.ThriftSessionDAO.updateLastAccessTime(ThriftSessionDAO.java:188)
    at org.wso2.carbon.identity.thrift.authentication.ThriftAuthenticatorServiceImpl.isAuthenticated(ThriftAuthenticatorServiceImpl.java:186)
    at org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.validateKey(APIKeyValidationServiceImpl.java:103)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:274)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:262)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
[2015-03-05 05:10:08,043] ERROR - APIKeyValidationServiceImpl Error in invoking validate key via thrift..
[2015-03-05 05:10:08,044] ERROR - ThriftSessionDAO Error when getting an Identity Persistence Store instance.
org.wso2.carbon.identity.base.IdentityException: Error when getting a database connection object from the Identity data source.
    at org.wso2.carbon.identity.core.persistence.JDBCPersistenceManager.getDBConnection(JDBCPersistenceManager.java:143)
    at org.wso2.carbon.identity.thrift.authentication.dao.ThriftSessionDAO.updateLastAccessTime(ThriftSessionDAO.java:188)
    at org.wso2.carbon.identity.thrift.authentication.ThriftAuthenticatorServiceImpl.isAuthenticated(ThriftAuthenticatorServiceImpl.java:186)
    at org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.validateKey(APIKeyValidationServiceImpl.java:103)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:274)
    at org.wso2.carbon.apimgt.impl.generated.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:262)
    at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.tomcat.jdbc.pool.PoolExhaustedException: [pool-41-thread-656] Timeout: Pool empty. Unable to fetch a connection in 60 seconds, none available[size:50; busy:50; idle:0; lastwait:60000].
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:674)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
    at org.wso2.carbon.identity.core.persistence.JDBCPersistenceManager.getDBConnection(JDBCPersistenceManager.java:136)
    ... 11 more

这是单个 APIM 节点的限制吗?或者我可以再做一些调整吗?

您可以看到消息“无法在 60 秒内获取连接”,这是因为线程等待 60 秒才能获取数据库连接并且无法获取连接。

在 master-datasource.xml 文件中,您可以找到每个数据源的以下元素。

<maxActive>50</maxActive>
<maxWait>60000</maxWait>

在哪里 MaxActive:一次使用的最大数据库连接数。 如果在 MaxActive 其他连接正在使用时请求连接,APIM 将等待 MaxWait 毫秒以返回连接,然后如果没有可用连接将抛出异常。

因此您可以增加 maxActive 或 maxWait 。当 运行 更多并行时。

从 WSO2 APIM 3.0.0 开始,这需要在您的 deployment.toml 文件中进行更改,因为-

[database.apim_db]
type = "h2"
url = "jdbc:h2:./repository/database/WSO2AM_DB;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE"
username = "wso2carbon"
password = "wso2carbon"
pool_options.maxActive=300

pool_options.maxActive 的默认值为 50,可以被该文件覆盖。可以对 shared_db 等进行类似的更改