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

Cache and reuse NamedPipeServerStream instances #46473

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 6, 2023

NamedPipeServerStream instances can be reused between connections:

// End connection
_stream.Disconnect();

// Start new connection
await _stream.WaitForConnectionAsync();

This PR adds a cache to the connection listener, allowing streams to be reused between connections.

A further improvement could be to completely reuse NamedPipeConnection (the implementation of ConnectionContext that wraps the stream). However, caching a connection context is harder because it has to determine whether anyone else is still using it. NamedPipeServerStream is private, making it relatively simple to detect whether it is still in use.

Before:

|    Method | ListenerQueueCount |     Mean |    Error |   StdDev |     Op/s | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------- |------------------- |---------:|---------:|---------:|---------:|------:|------:|------:|----------:|
| Plaintext |                  1 | 59.16 us | 1.130 us | 1.257 us | 16,902.9 |     - |     - |     - |     11 KB |
| Plaintext |                  2 | 59.62 us | 1.055 us | 0.935 us | 16,772.6 |     - |     - |     - |     11 KB |
| Plaintext |                  8 | 34.49 us | 0.508 us | 0.450 us | 28,997.5 |     - |     - |     - |     11 KB |
| Plaintext |                 16 | 35.30 us | 0.401 us | 0.335 us | 28,329.2 |     - |     - |     - |     11 KB |

After:

|    Method | ListenerQueueCount |     Mean |    Error |   StdDev |     Op/s | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------- |------------------- |---------:|---------:|---------:|---------:|------:|------:|------:|----------:|
| Plaintext |                  1 | 44.40 us | 0.644 us | 0.602 us | 22,522.2 |     - |     - |     - |      9 KB |
| Plaintext |                  2 | 29.90 us | 0.488 us | 0.433 us | 33,449.5 |     - |     - |     - |      9 KB |
| Plaintext |                  8 | 24.09 us | 0.219 us | 0.194 us | 41,509.1 |     - |     - |     - |      9 KB |
| Plaintext |                 16 | 23.98 us | 0.249 us | 0.221 us | 41,706.7 |     - |     - |     - |      9 KB |

(update) ObjectPool:

|    Method | ListenerQueueCount |     Mean |    Error |   StdDev |     Op/s | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------- |------------------- |---------:|---------:|---------:|---------:|------:|------:|------:|----------:|
| Plaintext |                  1 | 43.11 us | 0.714 us | 0.668 us | 23,199.0 |     - |     - |     - |      9 KB |
| Plaintext |                  2 | 29.24 us | 0.403 us | 0.377 us | 34,204.9 |     - |     - |     - |      9 KB |
| Plaintext |                  8 | 23.53 us | 0.366 us | 0.343 us | 42,503.3 |     - |     - |     - |      9 KB |
| Plaintext |                 16 | 23.74 us | 0.349 us | 0.326 us | 42,128.1 |     - |     - |     - |      9 KB |

@JamesNK JamesNK changed the title Add named pipes microbenchmark Cache and reuse NamedPipeServerStream instances Feb 6, 2023
Base automatically changed from jamesnk/namedpipes-microbenchmark to main February 7, 2023 02:39
@JamesNK JamesNK force-pushed the jamesnk/cache-namedpipeserverstream branch from ec428e0 to e78f98c Compare February 7, 2023 03:16
@JamesNK JamesNK merged commit 7b5b67e into main Feb 7, 2023
@JamesNK JamesNK deleted the jamesnk/cache-namedpipeserverstream branch February 7, 2023 07:37
@ghost ghost added this to the 8.0-preview2 milestone Feb 7, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants