Skip to content

Commit 2a6eac8

Browse files
committed
TEMP
1 parent 4bae835 commit 2a6eac8

227 files changed

Lines changed: 8089 additions & 9094 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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using BenchmarkDotNet.Attributes;
22
using TurboHTTP.MicroBenchmarks.Internal;
3-
using TurboHTTP.Protocol.Http10;
3+
using TurboHTTP.Protocol.Syntax;
4+
using TurboHTTP.Protocol.Syntax.Http10;
5+
using TurboHTTP.Protocol.Syntax.Http10.Client;
6+
using TurboHTTP.Protocol.Syntax.Http10.Options;
47

58
namespace TurboHTTP.MicroBenchmarks.Http10;
69

@@ -9,12 +12,12 @@ public class Http10DecoderBenchmark
912
{
1013
private byte[] _smallResponse = null!;
1114
private byte[] _largeResponse = null!;
12-
private Decoder _decoder = null!;
15+
private Http10ClientDecoder _decoder = null!;
1316

1417
[GlobalSetup]
1518
public void Setup()
1619
{
17-
_decoder = new Decoder();
20+
_decoder = new Http10ClientDecoder(Http10ClientDecoderOptions.Default, Http10Profile.Default);
1821

1922
_smallResponse = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nHello"u8.ToArray();
2023

@@ -24,16 +27,16 @@ public void Setup()
2427
}
2528

2629
[Benchmark(Baseline = true)]
27-
public bool DecodeSmallResponse()
30+
public object DecodeSmallResponse()
2831
{
2932
_decoder.Reset();
30-
return _decoder.TryDecode(_smallResponse, out _);
33+
return _decoder.Feed(_smallResponse, requestMethodWasHead: false, out _);
3134
}
3235

3336
[Benchmark]
34-
public bool DecodeLargeResponse()
37+
public object DecodeLargeResponse()
3538
{
3639
_decoder.Reset();
37-
return _decoder.TryDecode(_largeResponse, out _);
40+
return _decoder.Feed(_largeResponse, requestMethodWasHead: false, out _);
3841
}
3942
}

src/TurboHTTP.MicroBenchmarks/Http10/Http10EncoderBenchmark.cs

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

58
namespace TurboHTTP.MicroBenchmarks.Http10;
69

@@ -10,6 +13,7 @@ public class Http10EncoderBenchmark
1013
private HttpRequestMessage _simpleGet = null!;
1114
private HttpRequestMessage _requestWithHeaders = null!;
1215
private byte[] _buffer = null!;
16+
private Http10ClientEncoder _encoder = null!;
1317

1418
[GlobalSetup]
1519
public void Setup()
@@ -24,19 +28,21 @@ public void Setup()
2428
_requestWithHeaders.Headers.TryAddWithoutValidation("X-Request-Id", "bench-001");
2529
_requestWithHeaders.Headers.TryAddWithoutValidation("Cache-Control", "no-cache");
2630
_requestWithHeaders.Content = new ByteArrayContent(new byte[256]);
31+
32+
_encoder = new Http10ClientEncoder(Http10ClientEncoderOptions.Default, Http10Profile.Default);
2733
}
2834

2935
[Benchmark(Baseline = true)]
3036
public int EncodeSimpleGet()
3137
{
3238
var span = _buffer.AsSpan();
33-
return Encoder.Encode(_simpleGet, ref span);
39+
return _encoder.Encode(span, _simpleGet, ActorRefs.Nobody);
3440
}
3541

3642
[Benchmark]
3743
public int EncodeWithHeaders()
3844
{
3945
var span = _buffer.AsSpan();
40-
return Encoder.Encode(_requestWithHeaders, ref span);
46+
return _encoder.Encode(span, _requestWithHeaders, ActorRefs.Nobody);
4147
}
4248
}

src/TurboHTTP.Server/Streams/Stages/Http10ConnectionStage.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using Akka.Streams;
22
using Akka.Streams.Stage;
33
using Servus.Akka.Transport;
4-
using TurboHTTP.Protocol.Http10;
4+
using TurboHTTP.Protocol.Syntax.Http10;
5+
using TurboHTTP.Protocol.Syntax.Http10.Server;
56

67
namespace TurboHTTP.Server.Streams.Stages;
78

@@ -15,6 +16,6 @@ internal sealed class Http10ConnectionStage : GraphStage<ConnectionShape>
1516
public override ConnectionShape Shape => new(_inNetwork, _outRequest, _inResponse, _outNetwork);
1617

1718
protected override GraphStageLogic CreateLogic(Attributes inheritedAttributes)
18-
=> new HttpConnectionServerStageLogic<ServerStateMachine>(this,
19-
ops => new ServerStateMachine(ops));
19+
=> new HttpConnectionServerStageLogic<Http10ServerStateMachine>(this,
20+
ops => new Http10ServerStateMachine(ops));
2021
}

src/TurboHTTP.Server/Streams/Stages/HttpConnectionServerStageLogic.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Akka.Actor;
12
using Akka.Event;
23
using Akka.Streams;
34
using Akka.Streams.Stage;
@@ -19,6 +20,7 @@ internal sealed class HttpConnectionServerStageLogic<TSM> : TimerGraphStageLogic
1920
private readonly TSM _sm;
2021
private readonly Queue<HttpRequestMessage> _requestQueue = new();
2122
private readonly Queue<ITransportOutbound> _outboundQueue = new();
23+
private IActorRef _stageActor = ActorRefs.Nobody;
2224

2325
public HttpConnectionServerStageLogic(
2426
GraphStage<ConnectionShape> stage,
@@ -98,10 +100,16 @@ public HttpConnectionServerStageLogic(
98100

99101
public override void PreStart()
100102
{
103+
_stageActor = GetStageActor(OnStageActorMessage).Ref;
101104
_sm.PreStart();
102105
Pull(_inNetwork);
103106
}
104107

108+
private void OnStageActorMessage((IActorRef sender, object message) args)
109+
{
110+
_sm.OnBodyMessage(args.message);
111+
}
112+
105113
private void OnNetworkPush()
106114
{
107115
var item = Grab(_inNetwork);
@@ -166,6 +174,8 @@ void IServerStageOperations.OnCancelTimer(string name)
166174

167175
ILoggingAdapter IServerStageOperations.Log => Log;
168176

177+
IActorRef IServerStageOperations.StageActor => _stageActor;
178+
169179
private void TryPushRequest()
170180
{
171181
if (_requestQueue.Count > 0 && IsAvailable(_outRequest))

src/TurboHTTP.Tests.Shared/FakeOps.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Akka.Actor;
12
using Akka.Event;
23
using Servus.Akka.Transport;
34
using TurboHTTP.Streams.Stages;
@@ -14,4 +15,5 @@ internal sealed class FakeOps : IStageOperations
1415
public void OnScheduleTimer(string name, TimeSpan duration) { }
1516
public void OnCancelTimer(string name) { }
1617
public ILoggingAdapter Log => NoLogger.Instance;
18+
public IActorRef StageActor { get; set; } = ActorRefs.Nobody;
1719
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Akka.Actor;
2+
using Akka.Event;
3+
using Servus.Akka.Transport;
4+
using TurboHTTP.Streams;
5+
6+
namespace TurboHTTP.Tests.Shared;
7+
8+
internal sealed class FakeServerOps : IServerStageOperations
9+
{
10+
public List<HttpRequestMessage> Requests { get; } = [];
11+
public List<ITransportOutbound> Outbound { get; } = [];
12+
13+
public void OnRequest(HttpRequestMessage request) => Requests.Add(request);
14+
public void OnOutbound(ITransportOutbound item) => Outbound.Add(item);
15+
public void OnScheduleTimer(string name, TimeSpan delay) { }
16+
public void OnCancelTimer(string name) { }
17+
public ILoggingAdapter Log => NoLogger.Instance;
18+
public IActorRef StageActor { get; set; } = ActorRefs.Nobody;
19+
}

0 commit comments

Comments
 (0)