-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Minor stress improvement #57715
Minor stress improvement #57715
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue Details
None of this is critical and can be scratched. I'm just pushing changes that I've done for my own testing.
|
/azp run runtime-libraries stress-http |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-libraries stress-ssl |
Azure Pipelines successfully started running 1 pipeline(s). |
string s = sb.ToString(); | ||
sb.Clear(); | ||
Interlocked.Exchange(ref _cachedStringBuilder, sb); | ||
await _messagesChannel.Writer.WriteAsync(s, _stopProcessing.Token); | ||
await _messagesChannel.Writer.WriteAsync(sb.ToString(), _stopProcessing.Token); | ||
_stringBuilderPool.Return(sb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does StringBuilderPooledObjectPolicy
clear the StringBuilder
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, taken from this blog post: https://docs.microsoft.com/en-us/aspnet/core/performance/objectpool?view=aspnetcore-5.0
And confirmed by this:
https://source.dot.net/#Microsoft.Extensions.ObjectPool/StringBuilderPooledObjectPolicy.cs,30f83640ea3a7033,references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff, thanks! One suggestion.
private int _lastLogNumber = 0; | ||
private FileStream _log; | ||
private Channel<string> _messagesChannel = Channel.CreateUnbounded<string>(); | ||
private Task _processMessages; | ||
private CancellationTokenSource _stopProcessing = new CancellationTokenSource(); | ||
private const string LogDirectory = "./clientlog"; | ||
private ObjectPool<StringBuilder> _stringBuilderPool = new DefaultObjectPool<StringBuilder>(new StringBuilderPooledObjectPolicy()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: since we don't really need the abstraction, we can use the specific type & devirtualize the method calls:
private ObjectPool<StringBuilder> _stringBuilderPool = new DefaultObjectPool<StringBuilder>(new StringBuilderPooledObjectPolicy()); | |
private DefaultObjectPool<StringBuilder> _stringBuilderPool = new DefaultObjectPool<StringBuilder>(new StringBuilderPooledObjectPolicy()); |
Unrelated to the PR, but since we are in runtime/src/libraries/System.Net.Http/tests/StressTests/HttpStress/LogHttpEventListener.cs Lines 125 to 135 in 3ead32c
Will public override void Dispose()
{
base.Dispose();
_log.Flush();
_stopProcessing.Cancel();
// Try to wait for the task to finish before disposing
_processMessages.Wait(TimeSpan.FromSeconds(30));
_log.Dispose();
} |
Ha ha the |
/azp run runtime-libraries stress-http |
Azure Pipelines successfully started running 1 pipeline(s). |
Fudge, win docker copy is borked 😢 |
/azp run runtime-libraries stress-http |
Azure Pipelines successfully started running 1 pipeline(s). |
84697ff
to
f4dfff7
Compare
f4dfff7
to
4801fd1
Compare
/azp run runtime-libraries stress-http |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-libraries stress-ssl |
Azure Pipelines successfully started running 1 pipeline(s). |
None of this is critical and can be scratched. I'm just pushing changes that I've done for my own testing.