High waits on CLR_MANUAL_EVENT and CLR_AUTO_EVENT

Published Jan 15 2019 10:51 AM 979 Views
Microsoft
First published on MSDN on Feb 05, 2008

If you have a SQL CLR application, you may notice that waits on CLR_MANUAL_EVENT and CLR_AUTO_EVENT from sys.dm_os_wait_stats are very high.

This is normal and can be safely ignored because these waits reflect internal CLR runtime waits under normal conditions.  Since SQL as a CLR host implements synchronization mechanism, it is able to track these kinds of waits and exposes them via DMV.

The only exception when you need to pay attention to these two wait types is that you actually use unsafe assemblies and use CLR Event objects (ManualResetEvent or AutoResetEvent) yourself.  In other words, if you use ManualResetEvent and you code results in waiting on the object, the wait time will also be reflected in CLR_MANUAL_EVENT type.  The same is true for AutoResetEvent which will be reflected in CLR_AUTO_EVENT type.  But using these two objects will require explicitly creating the assembly in unsafe mode.

To summarize, if all your assemblies are created in safe mode and you see high waits on CLR_MANUAL_EVENT and CLR_AUTO_EVENT, you can safely ignore them.

Jack Li
Escalation Engineer


%3CLINGO-SUB%20id%3D%22lingo-sub-315453%22%20slang%3D%22en-US%22%3EHigh%20waits%20on%20CLR_MANUAL_EVENT%20and%20CLR_AUTO_EVENT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-315453%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Feb%2005%2C%202008%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EIf%20you%20have%20a%20SQL%20CLR%20application%2C%20you%20may%20notice%20that%20waits%20on%20CLR_MANUAL_EVENT%20and%20CLR_AUTO_EVENT%26nbsp%3Bfrom%20sys.dm_os_wait_stats%20are%20very%20high.%3C%2FP%3E%0A%20%20%3CP%3EThis%20is%20normal%20and%20can%20be%20safely%20ignored%26nbsp%3Bbecause%20these%20waits%20reflect%20internal%20CLR%20runtime%20waits%20under%20normal%20conditions.%26nbsp%3B%20Since%20SQL%20as%20a%20CLR%20host%20implements%20synchronization%20mechanism%2C%20it%20is%20able%20to%20track%20these%20kinds%20of%20waits%20and%20exposes%20them%20via%20DMV.%3C%2FP%3E%0A%20%20%3CP%3EThe%20only%20exception%20when%20you%20need%20to%20pay%20attention%20to%20these%20two%20wait%20types%20is%20that%20you%20actually%20use%20unsafe%20assemblies%20and%20use%20CLR%20Event%20objects%20(ManualResetEvent%20or%20AutoResetEvent)%26nbsp%3Byourself.%20%26nbsp%3BIn%20other%20words%2C%20if%20you%20use%20ManualResetEvent%20and%20you%20code%20results%20in%20waiting%20on%20the%20object%2C%20the%20wait%20time%20will%20also%20be%20reflected%20in%20CLR_MANUAL_EVENT%20type.%26nbsp%3B%20The%20same%20is%20true%20for%20AutoResetEvent%20which%20will%20be%20reflected%20in%20CLR_AUTO_EVENT%20type.%26nbsp%3B%20But%20using%20these%20two%20objects%20will%20require%20explicitly%20creating%20the%20assembly%20in%20unsafe%20mode.%3C%2FP%3E%0A%20%20%3CP%3ETo%20summarize%2C%20if%20all%20your%20assemblies%20are%20created%20in%20safe%20mode%20and%20you%20see%20high%20waits%20on%20CLR_MANUAL_EVENT%20and%20CLR_AUTO_EVENT%2C%20you%20can%20safely%20ignore%20them.%3C%2FP%3E%0A%20%20%3CP%3EJack%20Li%20%3CBR%20%2F%3EEscalation%20Engineer%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-315453%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Feb%2005%2C%202008%20If%20you%20have%20a%20SQL%20CLR%20application%2C%20you%20may%20notice%20that%20waits%20on%20CLR_MANUAL_EVENT%20and%20CLR_AUTO_EVENT%26nbsp%3Bfrom%20sys.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-315453%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQL%20CLR%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2019 10:51 AM
Updated by: