Skip to content

Commit

Permalink
Perf: Small improvements (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored Mar 18, 2021
1 parent 3943647 commit 9ebafbd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -757,29 +757,37 @@ internal static Version GetAssemblyVersion()
// This method assumes dataSource parameter is in TCP connection string format.
internal static bool IsAzureSqlServerEndpoint(string dataSource)
{
int length = dataSource.Length;
// remove server port
int i = dataSource.LastIndexOf(',');
if (i >= 0)
int foundIndex = dataSource.LastIndexOf(',');
if (foundIndex >= 0)
{
dataSource = dataSource.Substring(0, i);
length = foundIndex;
}

// check for the instance name
i = dataSource.LastIndexOf('\\');
if (i >= 0)
foundIndex = dataSource.LastIndexOf('\\', length - 1, length - 1);
if (foundIndex > 0)
{
dataSource = dataSource.Substring(0, i);
length = foundIndex;
}

// trim redundant whitespace
dataSource = dataSource.Trim();
// trim trailing whitespace
while (length > 0 && char.IsWhiteSpace(dataSource[length - 1]))
{
length -= 1;
}

// check if servername end with any azure endpoints
for (i = 0; i < AzureSqlServerEndpoints.Length; i++)
for (int index = 0; index < AzureSqlServerEndpoints.Length; index++)
{
if (dataSource.EndsWith(AzureSqlServerEndpoints[i], StringComparison.OrdinalIgnoreCase))
string endpoint = AzureSqlServerEndpoints[index];
if (length > endpoint.Length)
{
return true;
if (string.Compare(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length, StringComparison.OrdinalIgnoreCase) == 0)
{
return true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public TimeoutState(int value)
private volatile int _timeoutIdentityValue;
internal volatile bool _attentionSent; // true if we sent an Attention to the server
internal volatile bool _attentionSending;
private readonly TimerCallback _onTimeoutAsync;

// Below 2 properties are used to enforce timeout delays in code to
// reproduce issues related to theadpool starvation and timeout delay.
Expand Down Expand Up @@ -293,6 +294,7 @@ internal TdsParserStateObject(TdsParser parser)
// Construct a physical connection
Debug.Assert(null != parser, "no parser?");
_parser = parser;
_onTimeoutAsync = OnTimeoutAsync;

// For physical connection, initialize to default login packet size.
SetPacketSize(TdsEnums.DEFAULT_LOGIN_PACKET_SIZE);
Expand All @@ -309,6 +311,7 @@ internal TdsParserStateObject(TdsParser parser, TdsParserStateObject physicalCon
// Construct a MARS session
Debug.Assert(null != parser, "no parser?");
_parser = parser;
_onTimeoutAsync = OnTimeoutAsync;
SniContext = SniContext.Snix_GetMarsSession;

Debug.Assert(null != _parser._physicalStateObj, "no physical session?");
Expand Down Expand Up @@ -2474,7 +2477,7 @@ internal void ReadSni(TaskCompletionSource<object> completion)
_networkPacketTimeout?.Dispose();

_networkPacketTimeout = ADP.UnsafeCreateTimer(
new TimerCallback(OnTimeoutAsync),
_onTimeoutAsync,
new TimeoutState(_timeoutIdentityValue),
Timeout.Infinite,
Timeout.Infinite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ internal void TryScopeLeaveEvent(long scopeId)

#region Execution Trace
[NonEvent]
internal void TryBeginExecuteEvent(int objectId, object connectionId, string commandText, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
internal void TryBeginExecuteEvent(int objectId, Guid? connectionId, string commandText, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
{
if (Log.IsExecutionTraceEnabled())
{
Expand All @@ -518,7 +518,7 @@ internal void TryBeginExecuteEvent(int objectId, object connectionId, string com
}

[NonEvent]
internal void TryEndExecuteEvent(int objectId, object connectionId, int compositeState, int sqlExceptionNumber, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
internal void TryEndExecuteEvent(int objectId, Guid? connectionId, int compositeState, int sqlExceptionNumber, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
{
if (Log.IsExecutionTraceEnabled())
{
Expand Down

0 comments on commit 9ebafbd

Please sign in to comment.