MySqlConnector
MySqlConnector copied to clipboard
ServerSession.VerifyConnected() takes a lot of CPU TIME
Software versions MySqlConnector version: 2.1.0 Server type (MySQL, MariaDB, Aurora, etc.) and version: GCP/mysql8 .NET version: 6.0 ORM NuGet packages and versions: NHibernate/5.3
Describe the bug When profiling a high-cpu background processing server I am seeing a lot of threads waiting on VerifyConnected(). I am not sure why this is happening as VerifyConnected should not block often, from reading the source code, but it does for me.
Exception Full exception message and call stack (if applicable)
Example trace from one of the threads via dotnet stack report -p1
Thread (0xC66):
CPU_TIME
ManagedModule!MySqlConnector.Core.ServerSession.VerifyConnected()
ManagedModule!MySqlConnector.Core.ServerSession.ReceiveReplyAsync(value class MySqlConnector.Protocol.Serialization.IOBehavior,value class System.Threading.CancellationToken)
ManagedModule!MySqlConnector.Core.ResultSet+<ReadResultSetHeaderAsync>d__2.MoveNext()
ManagedModule!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start(!!0&)
ManagedModule!MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(value class MySqlConnector.Protocol.Serialization.IOBehavior)
ManagedModule!MySqlConnector.MySqlDataReader+<CreateAsync>d__110.MoveNext()
ManagedModule!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start(!!0&)
ManagedModule!MySqlConnector.MySqlDataReader.CreateAsync(value class MySqlConnector.Core.CommandListPosition,class MySqlConnector.Core.ICommandPayloadCreator,class System.Collections.Generic.IDictionary`2<class System.String,class MySqlConnector.Core.CachedProcedure>,class MySqlConnector.Core.IMySqlCommand,value class System.Data.CommandBehavior,class System.Diagnostics.Activity,value class MySqlConnector.Protocol.Serialization.IOBehavior,value class System.Threading.CancellationToken)
ManagedModule!MySqlConnector.Core.CommandExecutor+<ExecuteReaderAsync>d__0.MoveNext()
ManagedModule!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start(!!0&)
ManagedModule!MySqlConnector.MySqlCommand.ExecuteReaderNoResetTimeoutAsync(value class System.Data.CommandBehavior,value class MySqlConnector.Protocol.Serialization.IOBehavior,value class System.Threading.CancellationToken)
ManagedModule!MySqlConnector.MySqlCommand+<ExecuteReaderAsync>d__84.MoveNext()
ManagedModule!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start(!!0&)
ManagedModule!MySqlConnector.MySqlCommand.ExecuteReaderAsync(value class System.Data.CommandBehavior,value class MySqlConnector.Protocol.Serialization.IOBehavior,value class System.Threading.CancellationToken)
ManagedModule!MySqlConnector.MySqlCommand+<ExecuteDbDataReaderAsync>d__83.MoveNext()
ManagedModule!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start(!!0&)
ManagedModule!MySqlConnector.MySqlCommand.ExecuteDbDataReaderAsync(value class System.Data.CommandBehavior,value class System.Threading.CancellationToken)
ManagedModule!NHibernate.AdoNet.AbstractBatcher+<DoExecuteReaderAsync>d__76.MoveNext()
Expected behavior It should not spend a lot of time in VerifyConnected
Additional context I am not sure what is at fault here, maybe profiler is showing incorrect data or NHibernate is doing something funny with ADO.NET connections (i.e. why is there contention in VeryConnected at all?!)
Need pointers how to debug this further.
BTW, thanks for the software!