clockwork icon indicating copy to clipboard operation
clockwork copied to clipboard

How is the duration time captured for each query?

Open malhayek2014 opened this issue 10 years ago • 2 comments

I am having some performance issues with my application. When I trace the logs in my Chrome console under the Clockwork tab, I see that some queries has 1000-3000 ms for duration. But, when I execute these queries directly in SQL Server Management Studio they are executed under 1ms. I am wondering how is the duration time calculated? Is it a value returned by the SQL server or it is something that is calculated at the script level which include network latency time?

Thank you

malhayek2014 avatar Jun 14 '16 17:06 malhayek2014

Hey, assuming you are using Laravel the query time is whatever Laravel gives us.

This is where the query event including query time is fired - https://github.com/laravel/framework/blob/e8cb6173fa49826aeb1e36da738e79e93f85c1d5/src/Illuminate/Database/Connection.php#L792.

If we take a look where this is called, we'll find out how the time is computed - https://github.com/laravel/framework/blob/e8cb6173fa49826aeb1e36da738e79e93f85c1d5/src/Illuminate/Database/Connection.php#L663-L683.

Looks like included in this time is: preparation of the bindings (converting dates etc.), preparing and executing the PDO statement, fetching the results and possibly single retry if the connection was lost during the query execution.

So pretty much nothing except the query execution at the PHP level, which would include any network latency and PHP database driver overhead.

itsgoingd avatar Jun 14 '16 17:06 itsgoingd

This is good to know. I was under the impression that the value is getting returned by the database not by Laravel! Is there a way to break that time down? How much of that time is binding, how much is network latency and how much ODBC overhead?

I am trying to figure out what could be causing this big delay.

Thank you for your help

malhayek2014 avatar Jun 14 '16 18:06 malhayek2014