Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf: Small improvements #963

Merged
merged 5 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(',', length - 1, length - 1);
Wraith2 marked this conversation as resolved.
Show resolved Hide resolved
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);
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
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.CompareOrdinal(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length) == 0)
Wraith2 marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -449,7 +449,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 @@ -459,7 +459,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