【发布时间】:2017-07-20 02:00:48
【问题描述】:
现状
我在 web 和 rest api 服务器上使用 Jmeter 进行压力负载测试,但是一些事务的响应时间延迟了很多,所以我使用 Spring Aspect 来获取方法处理时间。我无法设置的是某些过程调用需要太多时间,因此尝试通过使用特定事务写入日志来检查 DB 进程时间(获取 con、释放 con、纯 db 进程时间)。 JMX 不是一个选项,因为我无法使用它跟踪事务。我只想将 ThreadContext 标记为打开的 DB 池状态,以便我可以同时检查慢事务和 DB 池状态。
这里不考虑使用来自 Tomcat 的 DB 数据源,因为不想在项目文件中进行 DB 设置。
我目前不考虑在 Spring 项目中使用数据源。
当前设置
Spring 项目的事务管理器使用 Tomcat DBCP 池和 Oracle 数据源(oracle.jdbc.OracleDriver with javax.sql.DataSource)
applicationContext.xml - 数据库设置
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/comp/env/jdbc/svc"/>
<property name="resourceRef" value="true"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="mapperLocations" value="classpath*:../sql/**.xml"/>
<property name="dataSource"><ref bean="dataSource"/></property>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory"/>
</bean>
<bean id="oracleTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" />
<bean id="transactionManager" class="com.xxx.xxx.api.transaction.TransactionManager">
<property name="transactionManagers">
<list>
<ref bean="oracleTransactionManager"/>
</list>
</property>
</bean>
正在尝试...记录数据库池状态
每当调用某个 dao 类中的函数时,我都会尝试使用 Spring Aspect 编写日志。 我要写的日志就像 DB Pool status 之类的
- 活动连接数
- 空闲连接计数
- 最大活动连接设置
- 最大空闲连接设置
等等。
问题
是否可以从 spring 项目中访问 Tomcat 的数据库池? 下面会有类似的方法。
- getNumIdle()
- getWaitCount()
- getNumActive()
【问题讨论】: