Skip to content

Commit 3978692

Browse files
LLT21LLT21
andauthored
Increase max number of connections + write plaintext synchronously (#8829)
* New versions * Synchronous plaintext generation * Write byte array * Increase number of connections * Determine string length dynamically --------- Co-authored-by: LLT21 <[email protected]> Co-authored-by: LLT21 <>
1 parent 6dd2630 commit 3978692

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

frameworks/CSharp/appmpower/src/Data/DbConnection.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ public void Dispose()
142142

143143
public async Task OpenAsync()
144144
{
145-
#if ADO && SQLSERVER
146-
_internalConnection = new();
147-
_internalConnection.DbConnection = new System.Data.SqlClient.SqlConnection(_connectionString);
148-
#elif ADO && POSTGRESQL
145+
#if ADO && POSTGRESQL
149146
_internalConnection = new();
150147
_internalConnection.DbConnection = new Npgsql.NpgsqlConnection(_connectionString);
151148
#else

frameworks/CSharp/appmpower/src/Data/DbConnections.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class DbConnections
77
{
88
private static bool _connectionsCreated = false;
99
private static short _createdConnections = 0;
10-
private static short _maxConnections = 250;
10+
private static short _maxConnections = 500;
1111

1212
private static ConcurrentStack<InternalConnection> _stack = new();
1313
private static ConcurrentQueue<TaskCompletionSource<InternalConnection>> _waitingQueue = new();

frameworks/CSharp/appmpower/src/HttpApplication.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public async Task ProcessRequestAsync(IFeatureCollection featureCollection)
3535

3636
if (pathStringLength == 10 && pathStringStart == "p")
3737
{
38-
await PlainText.RenderAsync(httpResponse.Headers, httpResponseBody.Writer, _plainText);
38+
//await PlainText.RenderAsync(httpResponse.Headers, httpResponseBody.Writer, _plainText);
39+
PlainText.Render(httpResponse.Headers, httpResponseBody, _plainText);
3940
return;
4041
}
4142
else if (pathStringLength == 5 && pathStringStart == "j")

frameworks/CSharp/appmpower/src/Kestrel/PlainText.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO.Pipelines;
55
using Microsoft.AspNetCore.Http;
66
using Microsoft.Extensions.Primitives;
7+
using Microsoft.AspNetCore.Http.Features;
78

89
namespace appMpower.Kestrel
910
{
@@ -23,5 +24,15 @@ public static async Task RenderAsync(IHeaderDictionary headerDictionary, PipeWri
2324
await pipeWriter.WriteAsync(utf8String);
2425
pipeWriter.Complete();
2526
}
27+
28+
public static void Render(IHeaderDictionary headerDictionary, IHttpResponseBodyFeature httpResponseBodyFeature, byte[] utf8String)
29+
{
30+
headerDictionary.Add(_headerServer);
31+
headerDictionary.Add(_headerContentType);
32+
int length = utf8String.Length;
33+
headerDictionary.Add(new KeyValuePair<string, StringValues>("Content-Length", length.ToString()));
34+
35+
httpResponseBodyFeature.Stream.Write(utf8String, 0, length);
36+
}
2637
}
2738
}

frameworks/CSharp/appmpower/src/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static async Task Main(string[] args)
1919
var kestrelServerOptions = new KestrelServerOptions();
2020

2121
kestrelServerOptions.Listen(IPAddress.Any, 8080);
22+
kestrelServerOptions.AllowSynchronousIO = true;
2223
kestrelServerOptions.AddServerHeader = false;
2324

2425
using var kestrelServer = new KestrelServer(Options.Create(kestrelServerOptions), socketTransportFactory, NullLoggerFactory.Instance);

frameworks/CSharp/appmpower/src/appMpower.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
<ItemGroup>
4545
<PackageReference Include="System.Data.Odbc" Version="8.0.0" />
46-
<PackageReference Include="Npgsql" Version="8.0.0-*" />
46+
<PackageReference Include="Npgsql" Version="8.0.2-*" />
4747
</ItemGroup>
4848

4949
<PropertyGroup>

0 commit comments

Comments
 (0)