0

Sometimes queries that normally take almost no time to run at all suddenly start to take as much as 2 seconds to run. (The query is select count(*) from calendars, which returns the number 10). This only happens when running queries through our application, and not when running the query directly against the database server. When we restart our application server software (Tomcat), suddenly performance is back to normal. Normally I would blame the network, but it doesn't make any sense to me that restarting the application server would make it suddenly behave much faster.

My suspicion falls on the connection pool, but I've tried all sorts of different settings and multiple different connection pools and I still have the same result. I'm currently using HikariCP.

Does anyone know what could be causing something like this, or how I might go about diagnosing the problem?

4

2 回答 2

2

您使用存储过程还是临时查询?在运行查询时获得不同执行的原因让我们说在管理工作室与在应用程序中使用存储过程可能是低效的缓存执行计划,这可能是由于参数嗅探而生成的。您可以在此处阅读更多相关信息,并且可以尝试多种解决方案(例如用局部变量替换参数)。如果您重新启动整个计算机(并且 SQL Server 也在其上运行),那么这可以解释为什么您在重新启动后开始时会获得快速查询 - 因为执行计划在重新启动后被清除。

于 2014-09-16T19:39:06.833 回答
1

事实证明,我们有一个流氓进程,它一次抓取 64 个与数据库的连接,并将所有这些连接用于紧张而低效的工作。我们能够使用jstack来诊断这个问题。当我们注意到系统速度变慢了很多时,我们运行了 jstack,它向我们展示了应用程序正在做什么。我们在同一个流氓进程中看到了 64 个堆栈跟踪,我们得到了答案!

于 2014-10-17T15:37:50.453 回答