Skip to content

Commit

Permalink
Use System.IO.Pipelines for sending (#303)
Browse files Browse the repository at this point in the history
* pipelines experiment

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* convert commands

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* bug fixes

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* handle entire buffer

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* reduce allocs

Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>

* use NullLogger in perf test

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* consolidate multiple small memory segments

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* optimize publish ValueTask

Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>

* use control line buffer

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* inline writing ctrl line on pub

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* handle exceptions in CommandWriter

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* precise ping enqueue

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* support command timeout

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* mark WaitUntilSent and ErrorHandler as obsolete

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* revert perf test

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* make PingCommand internal

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* organize imports

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* change InFlightCommands from List to Queue

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* replace missing DoubleAck option in JS test

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* fix race in svc sub

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* format

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* PR comments

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* trim protocol lengths

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* remove redundatant queued command canceled status

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* fix trimming

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* don't consider CommandTimeout on ConnectAsync; PingCommand struct

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* format

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* comment out failing test from #323

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

* comment out the correct test

Signed-off-by: Caleb Lloyd <caleb@synadia.com>

---------

Signed-off-by: Caleb Lloyd <caleb@synadia.com>
Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>
  • Loading branch information
caleblloyd authored Jan 10, 2024
1 parent 55e9532 commit 421463c
Show file tree
Hide file tree
Showing 63 changed files with 1,347 additions and 3,365 deletions.
7 changes: 0 additions & 7 deletions NATS.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "sandbox\Conso
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NATS.Client.Core.Tests", "tests\NATS.Client.Core.Tests\NATS.Client.Core.Tests.csproj", "{D60B2ADF-450D-4F8F-A3C5-7803D36FE06B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NatsBenchmark", "sandbox\NatsBenchmark\NatsBenchmark.csproj", "{FDBED61E-DA84-46E4-B4AE-1E4ACFDAE21C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicroBenchmark", "sandbox\MicroBenchmark\MicroBenchmark.csproj", "{A10F0D89-13F3-49B3-ACF7-66E45DC95225}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "files", "files", "{899BE3EA-C5CA-4394-9B62-C45CBFF3AF4E}"
Expand Down Expand Up @@ -119,10 +117,6 @@ Global
{D60B2ADF-450D-4F8F-A3C5-7803D36FE06B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D60B2ADF-450D-4F8F-A3C5-7803D36FE06B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D60B2ADF-450D-4F8F-A3C5-7803D36FE06B}.Release|Any CPU.Build.0 = Release|Any CPU
{FDBED61E-DA84-46E4-B4AE-1E4ACFDAE21C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDBED61E-DA84-46E4-B4AE-1E4ACFDAE21C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDBED61E-DA84-46E4-B4AE-1E4ACFDAE21C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDBED61E-DA84-46E4-B4AE-1E4ACFDAE21C}.Release|Any CPU.Build.0 = Release|Any CPU
{A10F0D89-13F3-49B3-ACF7-66E45DC95225}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A10F0D89-13F3-49B3-ACF7-66E45DC95225}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A10F0D89-13F3-49B3-ACF7-66E45DC95225}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -275,7 +269,6 @@ Global
{702B4B02-7FEC-42A1-A399-6F39D4E2CA29} = {4827B3EC-73D8-436D-AE2A-5E29AC95FD0C}
{7FE6D43B-181E-485E-8C14-35EAA0EBF09A} = {95A69671-16CA-4133-981C-CC381B7AAA30}
{D60B2ADF-450D-4F8F-A3C5-7803D36FE06B} = {C526E8AB-739A-48D7-8FC4-048978C9B650}
{FDBED61E-DA84-46E4-B4AE-1E4ACFDAE21C} = {95A69671-16CA-4133-981C-CC381B7AAA30}
{A10F0D89-13F3-49B3-ACF7-66E45DC95225} = {95A69671-16CA-4133-981C-CC381B7AAA30}
{D3F09B30-1ED5-48C2-81CD-A2AD88E751AC} = {4827B3EC-73D8-436D-AE2A-5E29AC95FD0C}
{44881DEE-8B49-44EA-B0BA-8BDA4F706E1A} = {95A69671-16CA-4133-981C-CC381B7AAA30}
Expand Down
1 change: 1 addition & 0 deletions sandbox/MicroBenchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/BenchmarkDotNet.Artifacts
17 changes: 2 additions & 15 deletions sandbox/MicroBenchmark/SerializationBuffersBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace MicroBenchmark;
public class SerializationBuffersBench
{
private static readonly string Data = new('0', 126);
private static readonly NatsPubOpts OptsWaitUntilSentTrue = new() { WaitUntilSent = true };
private static readonly NatsPubOpts OptsWaitUntilSentFalse = new() { WaitUntilSent = false };

private NatsConnection _nats;

Expand All @@ -22,22 +20,11 @@ public class SerializationBuffersBench
public void Setup() => _nats = new NatsConnection();

[Benchmark]
public async ValueTask<TimeSpan> WaitUntilSentTrue()
public async ValueTask<TimeSpan> PublishAsync()
{
for (var i = 0; i < Iter; i++)
{
await _nats.PublishAsync("foo", Data, opts: OptsWaitUntilSentTrue);
}

return await _nats.PingAsync();
}

[Benchmark]
public async ValueTask<TimeSpan> WaitUntilSentFalse()
{
for (var i = 0; i < Iter; i++)
{
await _nats.PublishAsync("foo", Data, opts: OptsWaitUntilSentFalse);
await _nats.PublishAsync("foo", Data);
}

return await _nats.PingAsync();
Expand Down
Loading

0 comments on commit 421463c

Please sign in to comment.