mysqlspringazureperformanceappinsights

A weird query observed in Azure appinsight


Lately, my company have decided to migrate our Spring application to Microsoft's Azure.
Azure gave us the possibility to monitor our DB (MySQL) queries and their runtime using appinsight.

A clarification - we investigate the traffic between our app (Azure cloud) and our DB (on-prem MySQL).

Upon investigation of the logs (telemetry logs) we have found that before most of the queries, a single query is being ran, the query:

SELECT ?;

This query takes up to 300 ms each time, then after that, the "real" query gets ran, which takes anywhere between few micro seconds to few hundreds of milliseconds.
We are trying to understand this lone query and where does it come from, to see if we can improve SQL queries runtime.

So far what we have done:

  1. I have altered my local logback.xml so that MySQL queries gets logged in a log file.
  2. I have integrated my local Spring instance to use p6spy so that I am able to see the queries that gets sent to the DB.

Conclusions I have came to:

Have you encountered anything similar? What can I do next to find the origin of that SELECT ? query.

Any help will be great.


Solution

  • Since you have confirmed that you are using spring.datasource.validationQuery=SELECT 1 property. You need to have a look at the other properties in your datasource configuration. The properties like 'test-on-borrow' and 'validation-interval' does make a difference. In your situation the validation query is being executed every time before connecting to the database