Open mmbednarz opened 3 years ago
The session is only meant to monitor SQLWATCH objects that run for longer than 1 second. I am surprised that the session even evaluates your UDF at all based on the criteria. Does the session log anything? Is the CPU purely caused by evaluation criteria? You can safely disable this session.
The session is logging no data, all SQL WATCH jobs are disabled for the test. In my opinion, the CPU load is caused by evaluating the conditions.
In that case, how does the SQLWATCH_long_queries]
behave? I would expect similar evaluation and similar cpu increase?
There is no problem with that one.
The main difference is that health
one uses sqlserver.sql_text
and the long_queries
not.
Edit:
The query_problems
use sqlserver.sql_text
but it is enabled and there is no perf issue..
Edit2:
But not for statement_completed
so maybe the problem is evaluating sqlserver.sql_text
on statement_completed
.
Yeah, I wonder if there is a bug in SQL 2019. I will do some more research. Thank you for raising this.
I tested on SQL Server version: Microsoft SQL Server 2016 (SP2-CU17) (KB5001092) - 13.0.5888.11 (X64) Mar 19 2021 19:41:38 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows Server 2012 R2 Datacenter 6.3 <X64> (Build 9600: ) (Hypervisor)
The problem also occurs.
Thank you for letting me know.
Have you thought about filtering on database name as well.
see attached. SQLWatch Health2 XES.txt
I checked and the above XE causes only a twofold extension of the UDF function execution time. Better but still unacceptable with my workload.
Might have messed up with the brackets. This might work better.
You can give that last version a try but I am not seeing any improvement over the previous version. I guess twice as slow is better than ten times slower for the original XE. I am also seeing it twice as slow when the SQLWATCH_long_queries XE session is enabled as well. Hopefully, someone can advance this further.
Thank you both for your input. I will seek improvements. You can disable both sessions as they are not required to run, you will just miss the long queries graphs but likely not a big deal since your queries seem to be in milliseconds rather than seconds.
Hi @mmbednarz, can you show me baseline time stats with all SQLWATCH XE sessions disabled please?
Yep,
All XE disabled (for 1000 function execs):
SQL Server parse and compile time:
CPU time = 11 ms, elapsed time = 11 ms.
SQL Server Execution Times:
CPU time = 15 ms, elapsed time = 38 ms.
Completion time: 2021-07-28T11:51:28.8599997+02:00
Hi @marcingminski , you should set the numeric filters at the top. This will reduce the impact of the Extended Events session for workloads with many small CPU intensive queries.
If you change the definition like this, the impact nearly disappears:
CREATE EVENT SESSION [SQLWATCH_health] ON SERVER ADD EVENT sqlserver.error_reported( ACTION(sqlserver.sql_text) WHERE [sqlserver].like_i_sql_unicode_string AND (NOT [sqlserver].like_i_sql_unicode_string)),
ADD EVENT sqlserver.sp_statement_completed(SET collect_statement=(1) ACTION(sqlserver.sql_text) WHERE ( --log any sqlwatch procedure running for longer than 1 second (there will be genuine exceptions) [package0].greater_than_int64 AND [sqlserver].like_i_sql_unicode_string AND (NOT [sqlserver].like_i_sql_unicode_string)) OR (
-- log performnace logger if it runs for over 500ms - it should take approx 100ms on average.
[package0].[greater_than_int64]([duration],(500000))
AND [sqlserver].[like_i_sql_unicode_string]([sqlserver].[sql_text],N'%usp_sqlwatch_logger_performance%')
))
ADD TARGET package0.event_file(SET filename=N'SQLWATCH_internal_performance',max_file_size=(50),max_rollover_files=(1)) WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF); GO
HTH,
Best regards, Oliver
Without Extended Events Session: CPU time = 31 ms, elapsed time = 47 ms.
With default Extended Events Session: CPU time = 735 ms, elapsed time = 754 ms.
With optimized Extended Events Session: CPU time = 63 ms, elapsed time = 61 ms.
Thanks, @OliverUweHahn I thought that was already the case. I will take a look at it. You are more than welcome to submit PR to change it.
OK. I will learn how to do that. :-)
The problem has been noticed for sql instances hosting system databases where many queries use scalar UDF functions. After installing SQLWATCH, the CPU load increased approximately 10 times. After excluding sql_statement_completed from SQL_WATCH_health extended events, the problem was resolved. The easiest way to replicate the problem:
Results for:
XE SQLWATCH_health disabled
XE SQLWATCH_health enabled:
Function definition:
SQL Server and OS version:
SQLWATCH Version: https://github.com/marcingminski/sqlwatch/releases/download/4.2/SQLWATCH.4.2.0.37410.20210518204739.zip