kusto now() function returns same value in single query

Viewed 355

I am trying to instrument a part of kusto function to check the execution times in different scenarios. however I couldn't find a way to print the time before and after.

print now();
<query takes few seconds>;
print now();

both the print statements are returning same value in the output. I tried running print now() as part of another function or converting tostring() or adding as another column using extend. but the value remains the same.

What are the ways to instrument query performance in kusto explorer/azure data explorer? is there any way to override the default now() behavior ?

2 Answers

This behavior is by design, as mentioned in the documentation, and cannot be overridden. You should use the .show queries command to analyze queries performance.

As @yifats mentioned in her answer, now() will return the same value in all occurrences within the same query, and this is by design.

But looking at the query duration isn't a good way to do a perf test anyway. Instead, you should run the two queries (that you want to compare) interchangeably several times, and instead of looking at the duration of the query, go to the Query Summary tab in Kusto Explorer, and look at the "Total CPU time" and "Data scanned (estimated)" - the lower the numbers, the better. Also, look at the "Parallelism" (higher parallelism is better, as same CPU time with higher parallelism will result in lower query duration).

Make sure to use constant time-window for all query runs, e.g. | where Timestamp between (datetime(2021-09-12 14:00:00) .. 1d) instead of filtering data using | where Timestamp > ago(1d), this is in order to run the query on exactly the same data - just make sure that your time-window doesn't include the last few minutes, as ingestion within this timeframe might still be in progress, so two runs might need to scan different amounts of data.

Lastly, make sure you only query data in the hot-cache (otherwise you won't get consistent results, performance-wise).

Related