简体   繁体   English

扩展事件捕获最少的事件以获得更好的性能

[英]Extended events capture bare minimum events for better performance

We are having legacy application, where there are so many users connecting to our legacy system.我们有遗留应用程序,有很多用户连接到我们的遗留系统。 We know about our jobs and our DB maintenance activities.我们了解我们的工作和数据库维护活动。 But, we see so many different users also accessing the production system.但是,我们看到很多不同的用户也在访问生产系统。 We want to capture bare minimal extended events, to see what are the different third party users and what queries are being run by them.我们希望捕获最少量的扩展事件,以查看不同的第三方用户是什么以及他们正在运行哪些查询。

Our Extended Events Session Current Configuration:我们的扩展事件 Session 当前配置:

We added below events.我们添加了以下事件。 We have applied filters for our databases in server.我们在服务器中为我们的数据库应用了过滤器。 We are writing to disk file target with 5 GB limit and recycling the files, to avoid file system bloating.我们正在写入限制为 5 GB 的磁盘文件目标并回收文件,以避免文件系统膨胀。

  • module_end ( additional event field: statement) module_end(附加事件字段:语句)
  • rpc_completed (additional event field: statement) rpc_completed(附加事件字段:语句)
  • sql_batch_completed (additional event field: batch text) sql_batch_completed(附加事件字段:批处理文本)

We are capturing below Global fields.我们正在捕获以下全局字段。

  • client_app_name客户端应用程序名称
  • database_id database_id
  • nt_username nt_username
  • sql text sql 文字
  • username用户名

But, even the above one is overwhelming for the production system.但是,即使是上面的一个,对于生产系统来说也是压倒性的。 So, We are trying to reduce the amount of capture.所以,我们正在努力减少捕获量。

Our Planned Changes for minimal extended events capture:我们针对最小扩展事件的计划变更捕获:

  • Apply filter for removing the known users from the events capture, in addition to database filters除数据库过滤器外,应用过滤器以从事件捕获中删除已知用户
  • Just capture rpc_completed, sql_batch_completed events只需捕获 rpc_completed、sql_batch_completed 事件
  • Just capture client_app_name, database_id, username global fields, as we can get sql statement from event field: statement只需捕获client_app_name,database_id,username全局字段,因为我们可以从事件字段中获取sql语句:语句

Our Question: Please suggest, whether we have configured our extended events session in the minimal configuration mode.我们的问题:请建议,我们是否在最小配置模式下配置了我们的扩展事件session。 Or do you suggest more changes to the event session.或者您是否建议对事件 session 进行更多更改。

Thanks for your help.谢谢你的帮助。

UPDATE: Our modification script for reference更新:我们的修改脚本供参考

ALTER EVENT SESSION [Audit_UserActivities] ON SERVER 
DROP EVENT sqlserver.module_end, DROP EVENT sqlserver.rpc_completed, DROP EVENT sqlserver.sql_batch_completed
ALTER EVENT SESSION [Audit_UserActivities] ON SERVER 
ADD EVENT sqlserver.rpc_completed(
    ACTION(sqlserver.client_app_name,sqlserver.database_id,sqlserver.username)
    WHERE (([sqlserver].[like_i_sql_unicode_string]([sqlserver].[database_name],N'DBPrefix%')) OR (([sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],N'DBName')) AND ([sqlserver].[username]<>N'DBSysadminUser')))), ADD EVENT sqlserver.sql_batch_completed(SET collect_batch_text=(1)
    ACTION(sqlserver.client_app_name,sqlserver.database_id,sqlserver.username)
    WHERE (([sqlserver].[like_i_sql_unicode_string]([sqlserver].[database_name],N'DBPrefix%')) OR (([sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],N'DBName')) AND ([sqlserver].[username]<>N'DBSysadminUser'))))
GO

I would not expect the Extended Events session in your question, with a file target, to generally be impactful on a healthy server.我不希望您的问题中带有文件目标的扩展事件 session 通常会对健康的服务器产生影响。 There are additional considerations you should consider to mitigate impact, though.不过,您还应该考虑其他一些因素来减轻影响。

There is a known issue capturing TVP RPC events that's fixed in SQL Server 2016+ , including Azure SQL Database.捕获 TVP RPC 事件的已知问题已在 SQL Server 2016+ 中修复,包括 Azure SQL 数据库。 I believe the problem still exists in older versions and is very costly with large TVPs.我相信这个问题在旧版本中仍然存在,并且对于大型 TVP 来说非常昂贵。 Your recourse in SQL Server 2012 is to exclude TVP RPC events with a filter.您在 SQL Server 2012 中的补救措施是使用过滤器排除 TVP RPC 事件。

Consider specifying a larger buffer size (eg MAX_MEMORY=100MB , depending on your instance memory).考虑指定更大的缓冲区大小(例如MAX_MEMORY=100MB ,具体取决于您的实例内存)。 Also specify ALLOW_MULTIPLE_EVENT_LOSS , to mitigate impact of tracing on your workload for high-frequency events since some event loss is acceptable for this tracing scenario.还要指定ALLOW_MULTIPLE_EVENT_LOSS ,以减轻跟踪对高频事件的工作负载的影响,因为这种跟踪场景可以接受一些事件丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM