Skip to content

Commit cb78633

Browse files
committed
TEMP
1 parent 2a6eac8 commit cb78633

79 files changed

Lines changed: 733 additions & 9677 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
using Akka.Actor;
12
using BenchmarkDotNet.Attributes;
2-
using System.Buffers;
33
using TurboHTTP.MicroBenchmarks.Internal;
4-
using TurboHTTP.Protocol;
5-
using TurboHTTP.Protocol.Http11;
6-
using TurboHTTP.Tests.Shared;
4+
using TurboHTTP.Protocol.Syntax;
5+
using TurboHTTP.Protocol.Syntax.Http11.Client;
6+
using TurboHTTP.Protocol.Syntax.Http11.Options;
77

88
namespace TurboHTTP.MicroBenchmarks.Http11;
99

@@ -12,12 +12,12 @@ public class Http11ChunkedDecoderBenchmark
1212
{
1313
private byte[] _singleChunk = null!;
1414
private byte[] _manySmallChunks = null!;
15-
private Decoder _decoder = null!;
15+
private Http11ClientDecoder _decoder = null!;
1616

1717
[GlobalSetup]
1818
public void Setup()
1919
{
20-
_decoder = new Decoder();
20+
_decoder = new Http11ClientDecoder(Http11ClientDecoderOptions.Default);
2121

2222
_singleChunk = System.Text.Encoding.Latin1.GetBytes(
2323
"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n" +
@@ -35,34 +35,21 @@ public void Setup()
3535
_manySmallChunks = System.Text.Encoding.Latin1.GetBytes(sb.ToString());
3636
}
3737

38-
[GlobalCleanup]
39-
public void Cleanup() => _decoder.Dispose();
40-
4138
[Benchmark(Baseline = true)]
4239
public bool DecodeSingleChunk()
4340
{
4441
_decoder.Reset();
45-
var decoded = _decoder.TryDecodeHeaders(_singleChunk, out _, out var framing, out _);
46-
if (framing != BodyFraming.None)
47-
{
48-
var (owner, _, _) = _decoder.FeedBody(ReadOnlyMemory<byte>.Empty);
49-
owner?.Dispose();
50-
}
42+
var outcome = _decoder.Feed(_singleChunk, false, out _);
5143
_decoder.Reset();
52-
return decoded;
44+
return outcome == DecodeOutcome.Complete;
5345
}
5446

5547
[Benchmark]
5648
public bool Decode20SmallChunks()
5749
{
5850
_decoder.Reset();
59-
var decoded = _decoder.TryDecodeHeaders(_manySmallChunks, out _, out var framing, out _);
60-
if (framing != BodyFraming.None)
61-
{
62-
var (owner, _, _) = _decoder.FeedBody(ReadOnlyMemory<byte>.Empty);
63-
owner?.Dispose();
64-
}
51+
var outcome = _decoder.Feed(_manySmallChunks, false, out _);
6552
_decoder.Reset();
66-
return decoded;
53+
return outcome == DecodeOutcome.Complete;
6754
}
6855
}
Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
using Akka.Actor;
12
using BenchmarkDotNet.Attributes;
2-
using System.Buffers;
33
using TurboHTTP.MicroBenchmarks.Internal;
4-
using TurboHTTP.Protocol;
5-
using TurboHTTP.Protocol.Http11;
6-
using TurboHTTP.Tests.Shared;
4+
using TurboHTTP.Protocol.Syntax;
5+
using TurboHTTP.Protocol.Syntax.Http11.Client;
6+
using TurboHTTP.Protocol.Syntax.Http11.Options;
77

88
namespace TurboHTTP.MicroBenchmarks.Http11;
99

@@ -13,12 +13,12 @@ public class Http11DecoderBenchmark
1313
private byte[] _smallResponse = null!;
1414
private byte[] _largeResponse = null!;
1515
private byte[] _multipleHeaders = null!;
16-
private Decoder _decoder = null!;
16+
private Http11ClientDecoder _decoder = null!;
1717

1818
[GlobalSetup]
1919
public void Setup()
2020
{
21-
_decoder = new Decoder();
21+
_decoder = new Http11ClientDecoder(Http11ClientDecoderOptions.Default);
2222

2323
_smallResponse = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\nConnection: keep-alive\r\n\r\nHello"u8.ToArray();
2424

@@ -36,48 +36,30 @@ public void Setup()
3636
_multipleHeaders = System.Text.Encoding.Latin1.GetBytes(headers.ToString());
3737
}
3838

39-
[GlobalCleanup]
40-
public void Cleanup() => _decoder.Dispose();
41-
4239
[Benchmark(Baseline = true)]
4340
public bool DecodeSmallResponse()
4441
{
4542
_decoder.Reset();
46-
var decoded = _decoder.TryDecodeHeaders(_smallResponse, out _, out var framing, out _);
47-
if (framing != BodyFraming.None)
48-
{
49-
var (owner, _, _) = _decoder.FeedBody(ReadOnlyMemory<byte>.Empty);
50-
owner?.Dispose();
51-
}
43+
var outcome = _decoder.Feed(_smallResponse, false, out _);
5244
_decoder.Reset();
53-
return decoded;
45+
return outcome == DecodeOutcome.Complete;
5446
}
5547

5648
[Benchmark]
5749
public bool DecodeLargeResponse()
5850
{
5951
_decoder.Reset();
60-
var decoded = _decoder.TryDecodeHeaders(_largeResponse, out _, out var framing, out _);
61-
if (framing != BodyFraming.None)
62-
{
63-
var (owner, _, _) = _decoder.FeedBody(ReadOnlyMemory<byte>.Empty);
64-
owner?.Dispose();
65-
}
52+
var outcome = _decoder.Feed(_largeResponse, false, out _);
6653
_decoder.Reset();
67-
return decoded;
54+
return outcome == DecodeOutcome.Complete;
6855
}
6956

7057
[Benchmark]
7158
public bool Decode50Headers()
7259
{
7360
_decoder.Reset();
74-
var decoded = _decoder.TryDecodeHeaders(_multipleHeaders, out _, out var framing, out _);
75-
if (framing != BodyFraming.None)
76-
{
77-
var (owner, _, _) = _decoder.FeedBody(ReadOnlyMemory<byte>.Empty);
78-
owner?.Dispose();
79-
}
61+
var outcome = _decoder.Feed(_multipleHeaders, false, out _);
8062
_decoder.Reset();
81-
return decoded;
63+
return outcome == DecodeOutcome.Complete;
8264
}
8365
}

src/TurboHTTP.MicroBenchmarks/Http11/Http11EncoderBenchmark.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using Akka.Actor;
12
using BenchmarkDotNet.Attributes;
23
using TurboHTTP.MicroBenchmarks.Internal;
3-
using TurboHTTP.Protocol.Http11;
4+
using TurboHTTP.Protocol.Syntax.Http11.Client;
5+
using TurboHTTP.Protocol.Syntax.Http11.Options;
46

57
namespace TurboHTTP.MicroBenchmarks.Http11;
68

@@ -10,11 +12,13 @@ public class Http11EncoderBenchmark
1012
private HttpRequestMessage _simpleGet = null!;
1113
private HttpRequestMessage _postWithBody = null!;
1214
private byte[] _buffer = null!;
15+
private Http11ClientEncoder _encoder = null!;
1316

1417
[GlobalSetup]
1518
public void Setup()
1619
{
1720
_buffer = new byte[16384];
21+
_encoder = new Http11ClientEncoder(Http11ClientEncoderOptions.Default);
1822

1923
_simpleGet = new HttpRequestMessage(HttpMethod.Get, "http://example.com/path")
2024
{
@@ -30,19 +34,18 @@ public void Setup()
3034
_postWithBody.Headers.TryAddWithoutValidation("X-Request-Id", "perf-bench-001");
3135
_postWithBody.Content = new ByteArrayContent(new byte[1024]);
3236
_postWithBody.Content.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream");
37+
_postWithBody.Content.Headers.ContentLength = 1024;
3338
}
3439

3540
[Benchmark(Baseline = true)]
3641
public int EncodeSimpleGet()
3742
{
38-
var span = _buffer.AsSpan();
39-
return Encoder.Encode(_simpleGet, ref span);
43+
return _encoder.Encode(_buffer.AsSpan(), _simpleGet, ActorRefs.Nobody);
4044
}
4145

4246
[Benchmark]
4347
public int EncodePostWithBody()
4448
{
45-
var span = _buffer.AsSpan();
46-
return Encoder.Encode(_postWithBody, ref span);
49+
return _encoder.Encode(_buffer.AsSpan(), _postWithBody, ActorRefs.Nobody);
4750
}
4851
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Akka.Streams;
22
using Akka.Streams.Stage;
33
using Servus.Akka.Transport;
4-
using TurboHTTP.Protocol.Http11;
4+
using TurboHTTP.Protocol.Syntax.Http11.Server;
55

66
namespace TurboHTTP.Server.Streams.Stages;
77

@@ -12,19 +12,15 @@ internal sealed class Http11ConnectionStage : GraphStage<ConnectionShape>
1212
private readonly Inlet<HttpResponseMessage> _inResponse = new("Http11Connection.In.Response");
1313
private readonly Outlet<ITransportOutbound> _outNetwork = new("Http11Connection.Out.Network");
1414
private readonly int _maxPipelinedRequests;
15-
private readonly TimeSpan? _keepAliveTimeout;
16-
private readonly TimeSpan? _requestHeadersTimeout;
1715

18-
public Http11ConnectionStage(int maxPipelinedRequests = 16, TimeSpan? keepAliveTimeout = null, TimeSpan? requestHeadersTimeout = null)
16+
public Http11ConnectionStage(int maxPipelinedRequests = 16)
1917
{
2018
_maxPipelinedRequests = maxPipelinedRequests;
21-
_keepAliveTimeout = keepAliveTimeout;
22-
_requestHeadersTimeout = requestHeadersTimeout;
2319
}
2420

2521
public override ConnectionShape Shape => new(_inNetwork, _outRequest, _inResponse, _outNetwork);
2622

2723
protected override GraphStageLogic CreateLogic(Attributes inheritedAttributes)
28-
=> new HttpConnectionServerStageLogic<ServerStateMachine>(this,
29-
ops => new ServerStateMachine(ops, _maxPipelinedRequests, _keepAliveTimeout, _requestHeadersTimeout));
24+
=> new HttpConnectionServerStageLogic<Http11ServerStateMachine>(this,
25+
ops => new Http11ServerStateMachine(ops, maxPipelineDepth: _maxPipelinedRequests));
3026
}

src/TurboHTTP.Tests/Http11/ChunkExtensionParserV2Spec.cs renamed to src/TurboHTTP.Tests/Http11/ChunkExtensionParserSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace TurboHTTP.Tests.Http11;
66

77
[Trait("RFC", "RFC9112")]
8-
public sealed class ChunkExtensionParserV2Spec
8+
public sealed class ChunkExtensionParserSpec
99
{
1010
[Fact(Timeout = 5000)]
1111
public void EmptyExtensions_ShouldParse()

0 commit comments

Comments
 (0)