Browse Source

update beetlex to beetlex.light (#9095)

* update beetleX to BeetleX.Light

* update beetlex to beetlex.light

* fix fortunes error

* fix error

* remove beetlex-core-updb

* update

* update benchmark_config

* update

* update

* update
Henry 1 year ago
parent
commit
1e7c4e86e3
25 changed files with 491 additions and 446 deletions
  1. 3 3
      frameworks/CSharp/beetlex/Benchmarks.sln
  2. 2 3
      frameworks/CSharp/beetlex/Benchmarks/Benchmarks.csproj
  3. 5 4
      frameworks/CSharp/beetlex/Benchmarks/Program.cs
  4. 2 3
      frameworks/CSharp/beetlex/PlatformBenchmarks/DBRaw.cs
  5. 3 2
      frameworks/CSharp/beetlex/PlatformBenchmarks/GMTDate.cs
  6. 30 11
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.Caching.cs
  7. 201 151
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.cs
  8. 23 11
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.db.cs
  9. 14 10
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.default.cs
  10. 27 58
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.fortunes.cs
  11. 14 20
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.json.cs
  12. 3 5
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.plaintext.cs
  13. 32 13
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.queries.cs
  14. 14 11
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.updates.cs
  15. 23 17
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpServer.cs
  16. 57 57
      frameworks/CSharp/beetlex/PlatformBenchmarks/HttpToken.cs
  17. 19 0
      frameworks/CSharp/beetlex/PlatformBenchmarks/NetApplication.cs
  18. 6 6
      frameworks/CSharp/beetlex/PlatformBenchmarks/PlatformBenchmarks.csproj
  19. 6 0
      frameworks/CSharp/beetlex/PlatformBenchmarks/Program.cs
  20. 3 14
      frameworks/CSharp/beetlex/PlatformBenchmarks/RequestData.cs
  21. 0 12
      frameworks/CSharp/beetlex/beetlex-core-updb.dockerfile
  22. 2 2
      frameworks/CSharp/beetlex/beetlex-core.dockerfile
  23. 2 2
      frameworks/CSharp/beetlex/beetlex.dockerfile
  24. 0 19
      frameworks/CSharp/beetlex/benchmark_config.json
  25. 0 12
      frameworks/CSharp/beetlex/config.toml

+ 3 - 3
frameworks/CSharp/beetlex/Benchmarks.sln

@@ -1,11 +1,11 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.28010.2036
+# Visual Studio Version 17
+VisualStudioVersion = 17.9.34728.123
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{12CA0190-5EA2-460F-ABC4-FAD454148EBF}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlatformBenchmarks", "PlatformBenchmarks\PlatformBenchmarks.csproj", "{8ACF83AD-E861-4642-BEF3-A6211F99389D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformBenchmarks", "PlatformBenchmarks\PlatformBenchmarks.csproj", "{8ACF83AD-E861-4642-BEF3-A6211F99389D}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+ 2 - 3
frameworks/CSharp/beetlex/Benchmarks/Benchmarks.csproj

@@ -2,13 +2,12 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>net5.0</TargetFramework>
+    <TargetFramework>net8.0</TargetFramework>
     <ServerGarbageCollection>true</ServerGarbageCollection>
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="BeetleX.FastHttpApi" Version="1.9.6" />
     <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
-    <PackageReference Include="Npgsql" Version="5.0.0-alpha1" />
-    <PackageReference Include="SpanJson" Version="3.0.1" />
+    <PackageReference Include="Npgsql" Version="8.0.3" />
   </ItemGroup>
 </Project>

+ 5 - 4
frameworks/CSharp/beetlex/Benchmarks/Program.cs

@@ -6,9 +6,9 @@ using System;
 using System.Threading;
 using System.Text;
 using BeetleX.Buffers;
-using SpanJson;
 using System.Collections.Generic;
 using BeetleX.EventArgs;
+using System.Text.Json;
 
 namespace Benchmarks
 {
@@ -109,8 +109,8 @@ namespace Benchmarks
                 mComplete.TrySetResult(new object());
             };
             mApiServer.Open();
-            RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
-            //RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
+            RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;SSL Mode=Disable;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Buffer Threshold Bytes=1000";
+            //RawDb._connectionString = "Server=localhost;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
             await mComplete.Task;
         }
 
@@ -140,7 +140,8 @@ namespace Benchmarks
 
         public override void Write(PipeStream stream, HttpResponse response)
         {
-            JsonSerializer.NonGeneric.Utf8.SerializeAsync(Data, stream);
+
+            JsonSerializer.Serialize(stream, Data); ;
         }
 
 

+ 2 - 3
frameworks/CSharp/beetlex/PlatformBenchmarks/DBRaw.cs

@@ -7,11 +7,11 @@ using System.Linq;
 using System.Runtime.Versioning;
 using System.Text;
 using System.Threading.Tasks;
-using System.Runtime.InteropServices.ComTypes;
-using BeetleX.EventArgs;
+
 using Microsoft.Extensions.Caching.Memory;
 using Npgsql;
 
+
 namespace PlatformBenchmarks
 {
     public class RawDb
@@ -342,7 +342,6 @@ namespace PlatformBenchmarks
                     }
                 }
                 mInited = true;
-                HttpServer.ApiServer.Log(LogType.Info, null, $"Init update commands cached");
                 return;
             }
         }

+ 3 - 2
frameworks/CSharp/beetlex/PlatformBenchmarks/GMTDate.cs

@@ -1,4 +1,5 @@
-using BeetleX.Buffers;
+
+using BeetleX.Light.Memory;
 using System;
 using System.Collections.Generic;
 using System.Text;
@@ -99,7 +100,7 @@ namespace PlatformBenchmarks
             return GetData(DateTime.Now);
         }
 
-        public void Write(PipeStream stream)
+        public void Write(IStreamWriter stream)
         {
             var data = DATE;
             stream.Write(data.Array, 0, data.Count);

+ 30 - 11
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.Caching.cs

@@ -1,18 +1,18 @@
-using BeetleX;
-using BeetleX.Buffers;
-using SpanJson;
+using BeetleX.Light.Memory;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
 
 namespace PlatformBenchmarks
 {
     public partial class HttpHandler
     {
-       
 
-        public async Task caching(string queryString, PipeStream stream, HttpToken token, ISession session)
+
+        public async Task caching(string queryString, IStreamWriter stream)
         {
             int count = 1;
             if (!string.IsNullOrEmpty(queryString))
@@ -30,20 +30,39 @@ namespace PlatformBenchmarks
                 count = 500;
             if (count < 1)
                 count = 1;
+            ContentLengthMemory content = new ContentLengthMemory();
             try
             {
-                var data = await token.Db.LoadCachedQueries(count);
+                var data = await _db.LoadCachedQueries(count);
                 stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
-                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
+                content.Data = GetContentLengthMemory(stream);
                 GMTDate.Default.Write(stream);
-                token.ContentPostion = stream.CacheLength;
-                await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, stream);
+                stream.WriteSequenceNetStream.StartWriteLength();
+
+                var jsonWriter = GetJsonWriter(stream);
+                using (var unflush = stream.UnFlush())
+                {
+                    jsonWriter.WriteStartArray();
+                    foreach (var item in data)
+                    {
+                        jsonWriter.WriteStartObject();
+                        jsonWriter.WriteNumber("Id", item.Id);
+                        jsonWriter.WriteNumber("RandomNumber", item.RandomNumber);
+                        jsonWriter.WriteEndObject();
+                    }
+                    jsonWriter.WriteEndArray();
+                    jsonWriter.Flush();
+
+                }
             }
             catch (Exception e_)
             {
-                stream.Write(e_.Message);
+                Context.GetLoger(BeetleX.Light.Logs.LogLevel.Error)?.WriteException(Context, "PlatformBenchmarks", "caching", e_);
+                stream.WriteString(e_.Message);
             }
-            OnCompleted(stream, session, token);
+            var len = stream.WriteSequenceNetStream.EndWriteLength();
+            content.Full(len);
+
         }
     }
 }

+ 201 - 151
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.cs

@@ -1,15 +1,21 @@
-using BeetleX;
-using BeetleX.Buffers;
-using BeetleX.EventArgs;
-using SpanJson;
+using BeetleX.Light;
+using BeetleX.Light.Memory;
 using System;
+using System.Buffers;
 using System.Collections.Generic;
+using System.IO;
+using System.IO.Pipelines;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
 
 namespace PlatformBenchmarks
 {
-    public partial class HttpHandler : ServerHandlerBase
+
+
+
+
+    public partial class HttpHandler : SesionBase
     {
         private static readonly AsciiString _line = new AsciiString("\r\n");
 
@@ -45,7 +51,7 @@ namespace PlatformBenchmarks
 
         private static readonly AsciiString _cached_worlds = "/cached-worlds";
 
-        private readonly static uint _jsonPayloadSize = (uint)System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(new JsonMessage { message = "Hello, World!" }, SerializerOptions).Length;
+        private readonly static uint _jsonPayloadSize = (uint)System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(new JsonMessage { message = "Hello, World!" }).Length;
 
 
 
@@ -65,14 +71,12 @@ namespace PlatformBenchmarks
         private readonly static AsciiString _jsonResultPreamble =
         _httpsuccess
         + _headerContentTypeJson
-        + _headerServer
-       + _headerContentLength;
+        + _headerServer;
 
         private readonly static AsciiString _HtmlResultPreamble =
       _httpsuccess
       + _headerContentTypeHtml
-      + _headerServer
-     + _headerContentLength;
+      + _headerServer;
 
 
 
@@ -83,24 +87,49 @@ namespace PlatformBenchmarks
 
         private static byte _question = 63;
 
-        public HttpHandler()
+        struct ContentLengthMemory
+        {
+            public Memory<byte> Data { get; set; }
+
+            public void Full(int length)
+            {
+                _headerContentLength.Data.CopyTo(Data);
+                var span = Data.Slice(_headerContentLength.Length).Span;
+                var len = span.Write(length.ToString(), Encoding.ASCII);
+                for (int i = len; i < span.Length - 2; i++)
+                {
+                    span[i] = 32;
+                }
+                span[^2] = 13;
+                span[^1] = 10;
+            }
+        }
+
+
+        protected Memory<byte> GetContentLengthMemory(IStreamWriter writer)
         {
-            RequestDispatchs = new BeetleX.Dispatchs.DispatchCenter<HttpToken>(OnRequest, Math.Min(Environment.ProcessorCount, 16));
+            var result = writer.WriteSequenceNetStream.GetWriteMemory(28);
+            writer.WriteSequenceNetStream.WriteAdvance(28);
+            return result;
         }
 
-        private BeetleX.Dispatchs.DispatchCenter<HttpToken> RequestDispatchs;
+        public NetContext Context { get; set; }
+
+        public HttpHandler()
+        {
 
+        }
 
+        private Queue<RequestData> _Requests = new Queue<RequestData>();
 
-        public override void Connected(IServer server, ConnectedEventArgs e)
+        private RawDb _db;
+
+        private RequestData _ReadRequest = null;
+        public override void Connected(NetContext context)
         {
-            base.Connected(server, e);
-            e.Session.Socket.NoDelay = true;
-            var token = new HttpToken();
-            token.ThreadDispatcher = RequestDispatchs.Next();
-            token.Session = e.Session;
-            token.Db = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance);
-            e.Session.Tag = token;
+            base.Connected(context);
+            this.Context = context;
+            _db = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance); ;
         }
 
         private int AnalysisUrl(ReadOnlySpan<byte> url)
@@ -114,195 +143,216 @@ namespace PlatformBenchmarks
 
         }
 
-        private void OnRequest(HttpToken token)
+        public override void Receive(NetContext context, object message)
         {
-            if (token.Requests.TryDequeue(out RequestData result))
+            var stream = context.Reader.ReadSequenceNetStream;
+            var reader = stream.GetReadOnlySequence();
+            var len = reader.IndexOf(_line);
+            while (len != null)
             {
-                OnStartRequest(result, token.Session, token, token.Session.Stream.ToPipeStream());
-            }
-        }
-
-        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
-        {
-            base.SessionReceive(server, e);
-            PipeStream pipeStream = e.Session.Stream.ToPipeStream();
-            HttpToken token = (HttpToken)e.Session.Tag;
-            var result = pipeStream.IndexOfLine();
-            while (result.End != null)
-            {
-                if (result.Length == 2)
+                var lendata = len.Value;
+                stream.ReadAdvance(lendata.Length);
+                if (lendata.Length == 2)
                 {
-                    pipeStream.ReadFree(result.Length);
-                    OnStartRequest(token.CurrentRequest, e.Session, token, pipeStream);
+                    _Requests.Enqueue(_ReadRequest);
+                    _ReadRequest = null;
                 }
                 else
                 {
-                    if (token.CurrentRequest == null)
+                    if (_ReadRequest == null)
+                    {
+                        _ReadRequest = new RequestData();
+                    }
+                    if (_ReadRequest.Action == null)
                     {
-                        var request = new RequestData();
-                        byte[] buffer = null;
-                        buffer = new byte[result.Length];
-                        pipeStream.Read(buffer, 0, result.Length);
-                        request.Data = new ArraySegment<byte>(buffer, 0, result.Length);
-                        AnalysisAction(request);
-                        if (request.Action == ActionType.Plaintext)
-                        {
-                            token.CurrentRequest = request;
-                        }
-                        else
-                        {
-                            token.CurrentRequest = request;
-                            pipeStream.ReadFree((int)pipeStream.Length);
-                            OnStartRequest(request, e.Session, token, pipeStream);
-                            return;
-                        }
+                        AnalysisAction(lendata, out var type, out var querystring);
+                        _ReadRequest.Action = type;
+                        _ReadRequest.QueryString = querystring;
+
                     }
                     else
                     {
-                        pipeStream.ReadFree(result.Length);
+
                     }
                 }
-                if (pipeStream.Length > 0)
-                    result = pipeStream.IndexOfLine();
-                else
-                    break;
+                reader = stream.GetReadOnlySequence();
+                len = reader.IndexOf(_line);
+            }
+            if (_Requests.Count > 0)
+            {
+                OnStartRequest(context.Writer);
             }
         }
 
-        private void AnalysisAction(RequestData requestData)
+        //public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
+        //{
+        //    base.SessionReceive(server, e);
+        //    PipeStream pipeStream = e.Session.Stream.ToPipeStream();
+        //    HttpToken token = (HttpToken)e.Session.Tag;
+        //    var result = pipeStream.IndexOfLine();
+        //    while (result.End != null)
+        //    {
+        //        if (result.Length == 2)
+        //        {
+        //            pipeStream.ReadFree(result.Length);
+        //            OnStartRequest(token.CurrentRequest, e.Session, token, pipeStream);
+        //        }
+        //        else
+        //        {
+        //            if (token.CurrentRequest == null)
+        //            {
+        //                var request = new RequestData();
+        //                byte[] buffer = null;
+        //                buffer = new byte[result.Length];
+        //                pipeStream.Read(buffer, 0, result.Length);
+        //                request.Data = new ArraySegment<byte>(buffer, 0, result.Length);
+        //                AnalysisAction(request);
+        //                if (request.Action == ActionType.Plaintext)
+        //                {
+        //                    token.CurrentRequest = request;
+        //                }
+        //                else
+        //                {
+        //                    token.CurrentRequest = request;
+        //                    pipeStream.ReadFree((int)pipeStream.Length);
+        //                    OnStartRequest(request, e.Session, token, pipeStream);
+        //                    return;
+        //                }
+        //            }
+        //            else
+        //            {
+        //                pipeStream.ReadFree(result.Length);
+        //            }
+        //        }
+        //        if (pipeStream.Length > 0)
+        //            result = pipeStream.IndexOfLine();
+        //        else
+        //            break;
+        //    }
+        //}
+
+        private void AnalysisAction(ReadOnlySequence<byte> line, out ActionType type, out string queryString)
         {
-            var line = _line.AsSpan();
-            int len = requestData.Data.Count;
-            var receiveData = requestData.GetSpan();
-            ReadOnlySpan<byte> http = line;
-            ReadOnlySpan<byte> method = line;
-            ReadOnlySpan<byte> url = line;
-            int offset2 = 0;
-            int count = 0;
-            for (int i = 0; i < len; i++)
-            {
-                if (receiveData[i] == line[0])
-                {
-                    http = receiveData.Slice(offset2, i - offset2);
-                    break;
-                }
-                else
-                {
-                    if (receiveData[i] == _Space)
-                    {
-                        if (count != 0)
-                        {
-                            url = receiveData.Slice(offset2, i - offset2);
-                            offset2 = i + 1;
-                        }
-                        else
-                        {
-                            method = receiveData.Slice(offset2, i - offset2);
-                            offset2 = i + 1;
-                            count++;
-                        }
-                    }
-                }
-            }
-            int queryIndex = AnalysisUrl(url);
-            ReadOnlySpan<byte> baseUrl = default;
-            ReadOnlySpan<byte> queryString = default;
-            if (queryIndex > 0)
+            type = ActionType.Plaintext;
+            queryString = default;
+            var spanIndex = line.PositionOf((byte)32);
+            var postion = line.GetPosition(1, spanIndex.Value);
+            line = line.Slice(postion);
+            spanIndex = line.PositionOf((byte)32);
+            var url = line.Slice(0, spanIndex.Value);
+            int baseurlLen = 0;
+            spanIndex = url.PositionOf((byte)63);
+            if (spanIndex != null)
             {
-                baseUrl = url.Slice(0, queryIndex);
-                queryString = url.Slice(queryIndex + 1, url.Length - queryIndex - 1);
-                requestData.QueryString = Encoding.ASCII.GetString(queryString);
+                baseurlLen = (int)url.Slice(0, spanIndex.Value).Length;
+                queryString = url.Slice(baseurlLen + 1).ReadString(Encoding.ASCII);
             }
             else
             {
-                baseUrl = url;
+                baseurlLen = (int)url.Length;
             }
+
+            Span<byte> baseUrl = stackalloc byte[baseurlLen];
+            url.Slice(0, baseurlLen).CopyTo(baseUrl);
+
             if (baseUrl.Length == _path_Plaintext.Length && baseUrl.StartsWith(_path_Plaintext))
             {
-                requestData.Action = ActionType.Plaintext;
+                type = ActionType.Plaintext;
             }
             else if (baseUrl.Length == _path_Json.Length && baseUrl.StartsWith(_path_Json))
             {
-                requestData.Action = ActionType.Json;
+                type = ActionType.Json;
             }
             else if (baseUrl.Length == _path_Db.Length && baseUrl.StartsWith(_path_Db))
             {
-                requestData.Action = ActionType.Db;
+                type = ActionType.Db;
             }
             else if (baseUrl.Length == _path_Queries.Length && baseUrl.StartsWith(_path_Queries))
             {
-                requestData.Action = ActionType.Queries;
+                type = ActionType.Queries;
             }
 
             else if (baseUrl.Length == _cached_worlds.Length && baseUrl.StartsWith(_cached_worlds))
             {
-                requestData.Action = ActionType.Caching;
+                type = ActionType.Caching;
             }
 
             else if (baseUrl.Length == _path_Updates.Length && baseUrl.StartsWith(_path_Updates))
             {
-                requestData.Action = ActionType.Updates;
+                type = ActionType.Updates;
             }
             else if (baseUrl.Length == _path_Fortunes.Length && baseUrl.StartsWith(_path_Fortunes))
             {
-                requestData.Action = ActionType.Fortunes;
+                type = ActionType.Fortunes;
             }
             else
             {
-                requestData.Action = ActionType.Other;
+                type = ActionType.Other;
             }
         }
 
-        public virtual async Task OnStartRequest(RequestData data, ISession session, HttpToken token, PipeStream stream)
+        public async Task OnStartRequest(IStreamWriter stream)
         {
-            ActionType type = data.Action;
-            if (type == ActionType.Plaintext)
-            {
-                await Plaintext(stream, token, session);
-            }
-            else if (type == ActionType.Json)
-            {
-                await Json(stream, token, session);
-            }
-            else if (type == ActionType.Db)
-            {
-                await db(stream, token, session);
-            }
-            else if (type == ActionType.Queries)
-            {
-                await queries(data.QueryString, stream, token, session);
-            }
-            else if (type == ActionType.Caching)
-            {
-                await caching(data.QueryString, stream, token, session);
-            }
-            else if (type == ActionType.Updates)
-            {
-                await updates(data.QueryString, stream, token, session);
-            }
-            else if (type == ActionType.Fortunes)
+            bool haveData = false;
+            while (_Requests.Count > 0)
             {
-                await fortunes(stream, token, session);
+                haveData = true;
+                var data = _Requests.Dequeue();
+                ActionType type = data.Action.Value;
+                if (type == ActionType.Plaintext)
+                {
+                    Plaintext(stream);
+                }
+                else if (type == ActionType.Json)
+                {
+                    Json(stream);
+                }
+                else if (type == ActionType.Db)
+                {
+                    await db(stream);
+                }
+                else if (type == ActionType.Queries)
+                {
+                    await queries(data.QueryString, stream);
+                }
+                else if (type == ActionType.Caching)
+                {
+                    await caching(data.QueryString, stream);
+                }
+                else if (type == ActionType.Updates)
+                {
+                    await updates(data.QueryString, stream);
+                }
+                else if (type == ActionType.Fortunes)
+                {
+                    await fortunes(stream);
+                }
+                else
+                {
+                    await Default(stream);
+                }
             }
-            else
+            if (haveData)
             {
-                await Default(stream, token, session);
+                stream.Flush();
             }
-
         }
 
 
-        private void OnCompleted(PipeStream stream, ISession session, HttpToken token)
+
+
+        private Utf8JsonWriter GetJsonWriter(IStreamWriter stream)
         {
-            var type = token.CurrentRequest.Action;
-            if (type != ActionType.Plaintext && type != ActionType.Json)
-            {
-                token.FullLength((stream.CacheLength - token.ContentPostion).ToString());
-            }
-            if (token.Requests.IsEmpty && stream.Length == 0)
-                session.Stream.Flush();
-            token.CurrentRequest = null;
+            Utf8JsonWriter utf8JsonWriter = _utf8JsonWriter ??= new Utf8JsonWriter((Stream)stream.WriteSequenceNetStream, new JsonWriterOptions { SkipValidation = true });
+            utf8JsonWriter.Reset((Stream)stream.WriteSequenceNetStream);
+            return utf8JsonWriter;
         }
+        [ThreadStatic]
+        private static Utf8JsonWriter _utf8JsonWriter;
 
+        public static JsonWriterOptions _jsonWriterOptions = new JsonWriterOptions
+        {
+            SkipValidation = true
+        };
     }
 }

+ 23 - 11
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.db.cs

@@ -1,8 +1,7 @@
-using BeetleX;
-using BeetleX.Buffers;
-using SpanJson;
+using BeetleX.Light.Memory;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -12,23 +11,36 @@ namespace PlatformBenchmarks
     {
 
 
-        public async ValueTask db(PipeStream stream, HttpToken token, ISession session)
+        public async Task db(IStreamWriter stream)
         {
+            ContentLengthMemory content = new ContentLengthMemory();
+
             try
             {
-                var data = await token.Db.LoadSingleQueryRow();
+                var data = await _db.LoadSingleQueryRow();
                 stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
-                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
+                content.Data = GetContentLengthMemory(stream);
                 GMTDate.Default.Write(stream);
-                token.ContentPostion = stream.CacheLength;
-                System.Text.Json.JsonSerializer.Serialize<World>(GetUtf8JsonWriter(stream, token), data, SerializerOptions);
+                stream.WriteSequenceNetStream.StartWriteLength();
+                var jsonWriter = GetJsonWriter(stream);
+                using (var unflush = stream.UnFlush())
+                {
+                    jsonWriter.WriteStartObject();
+                    jsonWriter.WriteNumber("Id", data.Id);
+                    jsonWriter.WriteNumber("RandomNumber", data.RandomNumber);
+                    jsonWriter.WriteEndObject();
+                    System.Text.Json.JsonSerializer.Serialize<World>((Stream)stream.WriteSequenceNetStream, data);
+                }
+
             }
             catch (Exception e_)
             {
-                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"db error {e_.Message}@{e_.StackTrace}");
-                stream.Write(e_.Message);
+                Context.GetLoger(BeetleX.Light.Logs.LogLevel.Error)?.WriteException(Context, "PlatformBenchmarks", "db", e_);
+                stream.WriteString(e_.Message);
             }
-            OnCompleted(stream, session, token);
+            var len = stream.WriteSequenceNetStream.EndWriteLength();
+            content.Full(len);
+
         }
     }
 }

+ 14 - 10
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.default.cs

@@ -1,6 +1,7 @@
-using BeetleX;
-using BeetleX.Buffers;
+
+using BeetleX.Light.Memory;
 using System;
+using System.Buffers;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -15,16 +16,19 @@ namespace PlatformBenchmarks
                + _headerContentTypeJson.ToString()
                + _headerServer.ToString();
 
-        public Task Default(PipeStream stream, HttpToken token, ISession session)
-        {
+        public ValueTask Default(IStreamWriter stream)
+        { 
+            
             stream.Write(_defaultPreamble.Data, 0, _defaultPreamble.Length);
-            token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
+            ContentLengthMemory contentLength = new ContentLengthMemory();
+            contentLength.Data = GetContentLengthMemory(stream);
             GMTDate.Default.Write(stream);
-            token.ContentPostion = stream.CacheLength;
-            stream.Write("<b> beetlex server</b><hr/>");
-            stream.Write("path not found!");
-            OnCompleted(stream, session, token);
-            return Task.CompletedTask;
+            stream.WriteSequenceNetStream.StartWriteLength();
+            stream.WriteString("<b> beetlex server</b><hr/>");
+            stream.WriteString("path not found!");
+            var length = stream.WriteSequenceNetStream.EndWriteLength();
+            contentLength.Full(length);
+            return ValueTask.CompletedTask;
         }
     }
 }

+ 27 - 58
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.fortunes.cs

@@ -1,5 +1,5 @@
-using BeetleX;
-using BeetleX.Buffers;
+
+using BeetleX.Light.Memory;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -13,87 +13,56 @@ namespace PlatformBenchmarks
     public partial class HttpHandler
     {
 
+        static readonly HtmlEncoder htmlEncoder = CreateHtmlEncoder();
+        static HtmlEncoder CreateHtmlEncoder()
+        {
+            var settings = new TextEncoderSettings(UnicodeRanges.BasicLatin, UnicodeRanges.Katakana, UnicodeRanges.Hiragana);
+            settings.AllowCharacter('\u2014'); // allow EM DASH through
+            return HtmlEncoder.Create(settings);
+        }
+
         private readonly static AsciiString _fortunesTableStart = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>";
         private readonly static AsciiString _fortunesRowStart = "<tr><td>";
         private readonly static AsciiString _fortunesColumn = "</td><td>";
         private readonly static AsciiString _fortunesRowEnd = "</td></tr>";
         private readonly static AsciiString _fortunesTableEnd = "</table></body></html>";
 
-        protected HtmlEncoder HtmlEncoder { get; } = CreateHtmlEncoder();
-
-        private static HtmlEncoder CreateHtmlEncoder()
-        {
-            var settings = new TextEncoderSettings(UnicodeRanges.BasicLatin, UnicodeRanges.Katakana, UnicodeRanges.Hiragana);
-            settings.AllowCharacter('\u2014');  // allow EM DASH through
-            return HtmlEncoder.Create(settings);
-        }
 
-        public async Task fortunes(PipeStream stream, HttpToken token, ISession session)
+        public async Task fortunes(IStreamWriter stream)
         {
+            ContentLengthMemory content = new ContentLengthMemory();
             try
             {
 
-                var data = await token.Db.LoadFortunesRows();
+                var data = await this._db.LoadFortunesRows();
 
                 stream.Write(_HtmlResultPreamble.Data, 0, _HtmlResultPreamble.Length);
-                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
+                content.Data = GetContentLengthMemory(stream);
                 GMTDate.Default.Write(stream);
-                token.ContentPostion = stream.CacheLength;
 
-                var html = token.GetHtmlBufferWriter();
-                html.Reset();
-                html.Write(_fortunesTableStart.Data, 0, _fortunesTableStart.Length);
+                stream.WriteSequenceNetStream.StartWriteLength();
+                stream.Write(_fortunesTableStart.Data, 0, _fortunesTableStart.Length);
                 foreach (var item in data)
                 {
-                    html.Write(_fortunesRowStart.Data, 0, _fortunesRowStart.Length);
-                    WriteNumeric(html, (uint)item.Id);
-                    html.Write(_fortunesColumn.Data, 0, _fortunesColumn.Length);
-                    html.Write(HtmlEncoder.Encode(item.Message));
-                    html.Write(_fortunesRowEnd.Data, 0, _fortunesRowEnd.Length);
+                    stream.Write(_fortunesRowStart.Data, 0, _fortunesRowStart.Length);
+                    stream.WriteString(item.Id.ToString(CultureInfo.InvariantCulture));
+                    stream.Write(_fortunesColumn.Data, 0, _fortunesColumn.Length);
+                    stream.WriteString(htmlEncoder.Encode(item.Message));
+                    stream.Write(_fortunesRowEnd.Data, 0, _fortunesRowEnd.Length);
                 }
-                html.Write(_fortunesTableEnd.Data, 0, _fortunesTableEnd.Length);
-                stream.Write(html.Data, 0, html.Length);
-
+                stream.Write(_fortunesTableEnd.Data, 0, _fortunesTableEnd.Length);
             }
             catch (Exception e_)
             {
-                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"fortunes error {e_.Message}@{e_.StackTrace}");
-                stream.Write(e_.Message);
-            }
-            OnCompleted(stream, session, token);
-        }
-
-        internal void WriteNumeric(HtmlBufferWriter writer, uint number)
-        {
-            const byte AsciiDigitStart = (byte)'0';
-
-            if (number < 10)
-            {
-                writer.Write((byte)(number + AsciiDigitStart));
-
+                Context.GetLoger(BeetleX.Light.Logs.LogLevel.Error)?.WriteException(Context, "PlatformBenchmarks", "fortunes", e_);
+                stream.WriteString(e_.Message);
             }
-            else if (number < 100)
-            {
-                var tens = (byte)((number * 205u) >> 11); // div10, valid to 1028
-                var span = new byte[2];
-                span[0] = (byte)(tens + AsciiDigitStart);
-                span[1] = (byte)(number - (tens * 10) + AsciiDigitStart);
-                writer.Write(span, 0, 2);
+            var len = stream.WriteSequenceNetStream.EndWriteLength();
+            content.Full(len);
 
-            }
-            else if (number < 1000)
-            {
-                var digit0 = (byte)((number * 41u) >> 12); // div100, valid to 1098
-                var digits01 = (byte)((number * 205u) >> 11); // div10, valid to 1028
-                var span = new byte[3];
-                span[0] = (byte)(digit0 + AsciiDigitStart);
-                span[1] = (byte)(digits01 - (digit0 * 10) + AsciiDigitStart);
-                span[2] = (byte)(number - (digits01 * 10) + AsciiDigitStart);
-                writer.Write(span, 0, 3);
-            }
         }
 
-        internal void WriteNumeric(PipeStream stream, uint number)
+        internal void WriteNumeric(IStreamWriter stream, uint number)
         {
             const byte AsciiDigitStart = (byte)'0';
 

+ 14 - 20
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.json.cs

@@ -1,8 +1,10 @@
 using BeetleX;
-using BeetleX.Buffers;
-using SpanJson;
+
+using BeetleX.Light.Memory;
+
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Text;
 using System.Text.Json;
 using System.Threading.Tasks;
@@ -11,29 +13,21 @@ namespace PlatformBenchmarks
 {
     public partial class HttpHandler
     {
-        
 
-        private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions();
 
-        private static Utf8JsonWriter GetUtf8JsonWriter(PipeStream stream, HttpToken token)
-        {
-            var buffer = stream.CreateBufferWriter();
-            if (token.Utf8JsonWriter == null)
-            {
-                token.Utf8JsonWriter = new Utf8JsonWriter(buffer, new JsonWriterOptions { SkipValidation = true });
-            }
-            var writer = token.Utf8JsonWriter;
-            writer.Reset(buffer);
-            return writer;
-        }
-
-        public ValueTask Json(PipeStream stream, HttpToken token, ISession session)
+        public void Json(IStreamWriter stream)
         {
             stream.Write(_jsonPreamble.Data, 0, _jsonPreamble.Length);
             GMTDate.Default.Write(stream);
-            System.Text.Json.JsonSerializer.Serialize<JsonMessage>(GetUtf8JsonWriter(stream, token), new JsonMessage { message = "Hello, World!" }, SerializerOptions);
-            OnCompleted(stream, session, token);
-            return ValueTask.CompletedTask;
+            var jsonWriter = GetJsonWriter(stream);
+            using (var unflush = stream.UnFlush())
+            {
+                jsonWriter.WriteStartObject();
+                jsonWriter.WriteString("message", "Hello, World!");
+                jsonWriter.WriteEndObject();
+                jsonWriter.Flush();
+            }
+            
         }
     }
 }

+ 3 - 5
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.plaintext.cs

@@ -1,5 +1,5 @@
-using BeetleX;
-using BeetleX.Buffers;
+
+using BeetleX.Light.Memory;
 using System;
 using System.Collections.Generic;
 using System.Text;
@@ -11,13 +11,11 @@ namespace PlatformBenchmarks
     {
       
 
-        public ValueTask Plaintext(PipeStream stream, HttpToken token, ISession session)
+        public void Plaintext(IStreamWriter stream)
         {
             stream.Write(_plaintextPreamble.Data, 0, _plaintextPreamble.Length);
             GMTDate.Default.Write(stream);
             stream.Write(_result_plaintext.Data, 0, _result_plaintext.Length);
-            OnCompleted(stream, session, token);
-            return ValueTask.CompletedTask;
         }
     }
 }

+ 32 - 13
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.queries.cs

@@ -1,24 +1,24 @@
-using BeetleX;
-using BeetleX.Buffers;
-using SpanJson;
+using BeetleX.Light.Memory;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
 
 namespace PlatformBenchmarks
 {
     public partial class  HttpHandler
     {
-        public async ValueTask queries(string queryString, PipeStream stream, HttpToken token, ISession session)
+        public async ValueTask queries(string queryString, IStreamWriter stream)
         {
             int count = 1;
-            if(!string.IsNullOrEmpty(queryString))
+            if (!string.IsNullOrEmpty(queryString))
             {
                 var values = queryString.Split('=');
-                if(values.Length>1)
+                if (values.Length > 1)
                 {
-                    if(int.TryParse(values[1],out int size))
+                    if (int.TryParse(values[1], out int size))
                     {
                         count = size;
                     }
@@ -28,20 +28,39 @@ namespace PlatformBenchmarks
                 count = 500;
             if (count < 1)
                 count = 1;
+            ContentLengthMemory content = new ContentLengthMemory();
             try
             {
-                var data = await token.Db.LoadMultipleQueriesRows(count);
+                var data = await _db.LoadMultipleQueriesRows(count);
                 stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
-                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
+                content.Data = GetContentLengthMemory(stream);
                 GMTDate.Default.Write(stream);
-                token.ContentPostion = stream.CacheLength;
-                System.Text.Json.JsonSerializer.Serialize(GetUtf8JsonWriter(stream, token), data, SerializerOptions);
+
+                stream.WriteSequenceNetStream.StartWriteLength();
+
+                var jsonWriter = GetJsonWriter(stream);
+                using (var unflush = stream.UnFlush())
+                {
+                    jsonWriter.WriteStartArray();
+                    foreach (var item in data)
+                    {
+                        jsonWriter.WriteStartObject();
+                        jsonWriter.WriteNumber("Id", item.Id);
+                        jsonWriter.WriteNumber("RandomNumber", item.RandomNumber);
+                        jsonWriter.WriteEndObject();
+                    }
+                    jsonWriter.WriteEndArray();
+                    jsonWriter.Flush();
+
+                }
             }
             catch (Exception e_)
             {
-                stream.Write(e_.Message);
+                Context.GetLoger(BeetleX.Light.Logs.LogLevel.Error)?.WriteException(Context, "PlatformBenchmarks", "queries", e_);
+                stream.WriteString(e_.Message);
             }
-            OnCompleted(stream, session, token);
+            var len = stream.WriteSequenceNetStream.EndWriteLength();
+            content.Full(len);
         }
     }
 }

+ 14 - 11
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpHandler.updates.cs

@@ -1,16 +1,17 @@
-using BeetleX;
-using BeetleX.Buffers;
-using SpanJson;
+
+using BeetleX.Light.Memory;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
 
 namespace PlatformBenchmarks
 {
     public partial class HttpHandler
     {
-        public async ValueTask updates(string queryString, PipeStream stream, HttpToken token, ISession session)
+        public async ValueTask updates(string queryString, IStreamWriter stream)
         {
             int count = 1;
             if (!string.IsNullOrEmpty(queryString))
@@ -28,22 +29,24 @@ namespace PlatformBenchmarks
                 count = 500;
             if (count < 1)
                 count = 1;
+            ContentLengthMemory content = new ContentLengthMemory();
             try
             {
-                var data = await token.Db.LoadMultipleUpdatesRows(count);
+                var data = await _db.LoadMultipleUpdatesRows(count);
 
                 stream.Write(_jsonResultPreamble.Data, 0, _jsonResultPreamble.Length);
-                token.ContentLength = stream.Allocate(HttpHandler._LengthSize);
+                content.Data = GetContentLengthMemory(stream);
                 GMTDate.Default.Write(stream);
-                token.ContentPostion = stream.CacheLength;
-                System.Text.Json.JsonSerializer.Serialize<World[]>(GetUtf8JsonWriter(stream, token), data, SerializerOptions);
+                stream.WriteSequenceNetStream.StartWriteLength();
+                JsonSerializer.Serialize((Stream)stream.WriteSequenceNetStream, data);
             }
             catch (Exception e_)
             {
-                HttpServer.ApiServer.Log(BeetleX.EventArgs.LogType.Error, null, $"updates error {e_.Message}@{e_.StackTrace}");
-                stream.Write(e_.Message);
+                Context.GetLoger(BeetleX.Light.Logs.LogLevel.Error)?.WriteException(Context, "PlatformBenchmarks", "updates", e_);
+                stream.WriteString(e_.Message);
             }
-            OnCompleted(stream, session, token);
+            var len = stream.WriteSequenceNetStream.EndWriteLength();
+            content.Full(len);
         }
     }
 }

+ 23 - 17
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpServer.cs

@@ -1,5 +1,5 @@
-using BeetleX;
-using BeetleX.EventArgs;
+using BeetleX.Light;
+using BeetleX.Light.Logs;
 using Microsoft.Extensions.Hosting;
 using System;
 using System.Collections.Generic;
@@ -11,38 +11,44 @@ namespace PlatformBenchmarks
 {
     public class HttpServer : IHostedService
     {
-        public static IServer ApiServer;
+        private static NetServer<HttpNetApplication, HttpHandler> _apiServer;
 
         public virtual Task StartAsync(CancellationToken cancellationToken)
         {
+            ThreadPool.SetMinThreads(Environment.ProcessorCount * 2, Environment.ProcessorCount * 2);
+            Constants.MemorySegmentMinSize = 1024 * 8;
+            Constants.MemorySegmentMaxSize = 1024 * 8;
+            Constants.InitMemoryBlock();
             ArraySegment<byte> date = GMTDate.Default.DATE;
-            ServerOptions serverOptions = new ServerOptions();
-            serverOptions.LogLevel = LogType.Error;
-            serverOptions.DefaultListen.Port = 8080;
-            serverOptions.Statistical = false;
-            serverOptions.BufferPoolMaxMemory = 1000;
-            serverOptions.BufferPoolSize = 1024 * 24;
-            ApiServer = SocketFactory.CreateTcpServer<HttpHandler>(serverOptions);
-            ApiServer.Open();
+            _apiServer = new NetServer<HttpNetApplication, HttpHandler>();
+            _apiServer.Options.LogLevel = BeetleX.Light.Logs.LogLevel.Error;
+            _apiServer.Options.AddLogOutputHandler<LogOutputToConsole>();
+            _apiServer.Options.SetDefaultListen(o =>
+            {
+                o.Port = 8080;
+            });
+            _apiServer.Start();
+
+
             if (!Program.UpDB)
             {
-               RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
-               // RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
+                RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;SSL Mode=Disable;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Buffer Threshold Bytes=1000";
+                //RawDb._connectionString = "Server=127.0.0.1;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
             }
             else
             {
 
-                RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3;Multiplexing=true;Write Coalescing Delay Us=500;Write Coalescing Buffer Threshold Bytes=1000";
-               // RawDb._connectionString = "Server=192.168.2.19;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
+                 RawDb._connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;SSL Mode=Disable;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4;Multiplexing=true;Write Coalescing Buffer Threshold Bytes=1000";
+                //RawDb._connectionString = "Server=127.0.0.1;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=64;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
             }
-           // ApiServer.Log(LogType.Info, null, $"Debug mode [{Program.Debug}]");
+            // ApiServer.Log(LogType.Info, null, $"Debug mode [{Program.Debug}]");
             return Task.CompletedTask;
 
         }
 
         public virtual Task StopAsync(CancellationToken cancellationToken)
         {
-            ApiServer.Dispose();
+
             return Task.CompletedTask;
         }
     }

+ 57 - 57
frameworks/CSharp/beetlex/PlatformBenchmarks/HttpToken.cs

@@ -1,76 +1,76 @@
-using BeetleX;
-using BeetleX.Buffers;
-using BeetleX.Dispatchs;
-using System;
-using System.Collections.Concurrent;
-using System.Text;
-using System.Text.Json;
+//using BeetleX;
+//using BeetleX.Buffers;
+//using BeetleX.Dispatchs;
+//using System;
+//using System.Collections.Concurrent;
+//using System.Text;
+//using System.Text.Json;
 
-namespace PlatformBenchmarks
-{
-    public class HttpToken
-    {
-        private byte[] mLengthBuffer = new byte[10];
+//namespace PlatformBenchmarks
+//{
+//    public class HttpToken
+//    {
+//        private byte[] mLengthBuffer = new byte[10];
 
-        public RawDb Db { get; set; }
+//        public RawDb Db { get; set; }
 
-        public HttpToken()
-        {
+//        public HttpToken()
+//        {
 
-        }
+//        }
 
-        public SingleThreadDispatcher<HttpToken> ThreadDispatcher { get; set; }
+//        public SingleThreadDispatcher<HttpToken> ThreadDispatcher { get; set; }
 
-        public ConcurrentQueue<RequestData> Requests { get; set; } = new ConcurrentQueue<RequestData>();
+//        public ConcurrentQueue<RequestData> Requests { get; set; } = new ConcurrentQueue<RequestData>();
 
-        public Utf8JsonWriter Utf8JsonWriter { get; set; }
+//        public Utf8JsonWriter Utf8JsonWriter { get; set; }
 
-        public ISession Session { get; set; }
+//        public ISession Session { get; set; }
 
-        public RequestData CurrentRequest { get; set; }
+//        public RequestData CurrentRequest { get; set; }
 
-        private HtmlBufferWriter mHtmlBufferWriter = null;
+//        private HtmlBufferWriter mHtmlBufferWriter = null;
 
-        public HtmlBufferWriter GetHtmlBufferWriter()
-        {
-            if (mHtmlBufferWriter == null)
-                mHtmlBufferWriter = new HtmlBufferWriter(2048);
-            return mHtmlBufferWriter;
-        }
+//        public HtmlBufferWriter GetHtmlBufferWriter()
+//        {
+//            if (mHtmlBufferWriter == null)
+//                mHtmlBufferWriter = new HtmlBufferWriter(2048);
+//            return mHtmlBufferWriter;
+//        }
 
-        public byte[] GetLengthBuffer(string length)
-        {
-            Encoding.ASCII.GetBytes(length, 0, length.Length, mLengthBuffer, 0);
-            for (int i = length.Length; i < mLengthBuffer.Length; i++)
-            {
-                mLengthBuffer[i] = 32;
-            }
-            mLengthBuffer[6] = (byte)'\r';
-            mLengthBuffer[7] = (byte)'\n';
-            return mLengthBuffer;
-        }
+//        public byte[] GetLengthBuffer(string length)
+//        {
+//            Encoding.ASCII.GetBytes(length, 0, length.Length, mLengthBuffer, 0);
+//            for (int i = length.Length; i < mLengthBuffer.Length; i++)
+//            {
+//                mLengthBuffer[i] = 32;
+//            }
+//            mLengthBuffer[6] = (byte)'\r';
+//            mLengthBuffer[7] = (byte)'\n';
+//            return mLengthBuffer;
+//        }
 
-        public int ContentPostion { get; set; }
+//        public int ContentPostion { get; set; }
 
-        public MemoryBlockCollection ContentLength { get; set; }
+//        public MemoryBlockCollection ContentLength { get; set; }
 
-        public void FullLength(string length)
-        {
-            var item = GetLengthBuffer(length);
-            ContentLength.Full(item);
-        }
+//        public void FullLength(string length)
+//        {
+//            var item = GetLengthBuffer(length);
+//            ContentLength.Full(item);
+//        }
 
-        private int mProcessStatus = 0;
+//        private int mProcessStatus = 0;
 
-        public void CompletedProcess()
-        {
-            System.Threading.Interlocked.Exchange(ref mProcessStatus, 0);
-        }
+//        public void CompletedProcess()
+//        {
+//            System.Threading.Interlocked.Exchange(ref mProcessStatus, 0);
+//        }
 
-        public bool EnterProcess()
-        {
-            return System.Threading.Interlocked.CompareExchange(ref mProcessStatus, 1, 0) == 0;
-        }
+//        public bool EnterProcess()
+//        {
+//            return System.Threading.Interlocked.CompareExchange(ref mProcessStatus, 1, 0) == 0;
+//        }
 
-    }
-}
+//    }
+//}

+ 19 - 0
frameworks/CSharp/beetlex/PlatformBenchmarks/NetApplication.cs

@@ -0,0 +1,19 @@
+using BeetleX.Light;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PlatformBenchmarks
+{
+    public class HttpNetApplication : ApplicationBase
+    {
+        public override bool Connecting(Socket socket, ListenHandler handler)
+        {
+            socket.NoDelay = true;
+            return true;
+        }
+    }
+}

+ 6 - 6
frameworks/CSharp/beetlex/PlatformBenchmarks/PlatformBenchmarks.csproj

@@ -2,17 +2,17 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>net5.0</TargetFramework>
+    <TargetFramework>net8.0</TargetFramework>
     <ServerGarbageCollection>true</ServerGarbageCollection>
    
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="BeetleX" Version="1.6.5.41" />
-    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
-    <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
-    <PackageReference Include="Npgsql" Version="5.0.3" />
-    <PackageReference Include="SpanJson" Version="3.1.0" />
+    <PackageReference Include="BeetleX.Light" Version="0.10.24.607" />
+    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
+    <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
+    <PackageReference Include="Npgsql" Version="8.0.3" />
+    <PackageReference Include="System.Runtime.Caching" Version="8.0.0" />
   </ItemGroup>
 
 </Project>

+ 6 - 0
frameworks/CSharp/beetlex/PlatformBenchmarks/Program.cs

@@ -1,6 +1,7 @@
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
 using System;
+using System.IO;
 
 namespace PlatformBenchmarks
 {
@@ -14,7 +15,12 @@ namespace PlatformBenchmarks
         public static void Main(string[] args)
         {
             //Debug = (args != null && args.Length > 0 && args[0] == "debug");
+            var data = GMTDate.Default.DATE;
             UpDB = (args != null && args.Length > 0 && args[0] == "updb");
+            UpdateCommandsCached.Init();
+            //HttpServer server = new HttpServer();
+            //server.StartAsync(default);
+            //Console.ReadLine();
             new HostBuilder().ConfigureServices(delegate (HostBuilderContext hostContext, IServiceCollection services)
             {
                 services.AddHostedService<HttpServer>();

+ 3 - 14
frameworks/CSharp/beetlex/PlatformBenchmarks/RequestData.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Buffers;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -6,24 +7,12 @@ using System.Threading.Tasks;
 
 namespace PlatformBenchmarks
 {
-    public class RequestData : IDisposable
+    public class RequestData 
     {
-        public ArraySegment<byte> Data { get; set; }
-
-        public ReadOnlySpan<byte> GetSpan()
-        {
-            return new ReadOnlySpan<byte>(Data.Array, Data.Offset, Data.Count);
-        }
-
-        public void Dispose()
-        {
-
-            //System.Buffers.ArrayPool<byte>.Shared.Return(Data.Array);
-        }
 
         public string QueryString { get; set; }
 
-        public ActionType Action { get; set; }
+        public ActionType? Action { get; set; }
 
 
     }

+ 0 - 12
frameworks/CSharp/beetlex/beetlex-core-updb.dockerfile

@@ -1,12 +0,0 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
-WORKDIR /app
-COPY PlatformBenchmarks .
-RUN dotnet publish -c Release -o out
-
-FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
-WORKDIR /app
-COPY --from=build /app/out ./
-
-EXPOSE 8080
-
-ENTRYPOINT ["dotnet", "PlatformBenchmarks.dll","updb"]

+ 2 - 2
frameworks/CSharp/beetlex/beetlex-core.dockerfile

@@ -1,9 +1,9 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
+FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
 WORKDIR /app
 COPY PlatformBenchmarks .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
 WORKDIR /app
 COPY --from=build /app/out ./
 

+ 2 - 2
frameworks/CSharp/beetlex/beetlex.dockerfile

@@ -1,9 +1,9 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
+FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
 WORKDIR /app
 COPY Benchmarks .
 RUN dotnet publish -c Release -o out
 
-FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
 WORKDIR /app
 COPY --from=build /app/out ./
 

+ 0 - 19
frameworks/CSharp/beetlex/benchmark_config.json

@@ -48,25 +48,6 @@
         "display_name": "beetlex-core",
         "notes": "",
         "versus": "aspcore"
-      },
-      "core-updb": {
-        "update_url": "/updates?queries=",
-        "fortune_url": "/fortunes",
-        "port": 8080,
-        "approach": "Realistic",
-        "classification": "Platform",
-        "database": "Postgres",
-        "framework": "beetlex",
-        "language": "C#",
-        "orm": "Raw",
-        "platform": ".NET",
-        "flavor": "CoreCLR",
-        "webserver": "beetlex",
-        "os": "Linux",
-        "database_os": "Linux",
-        "display_name": "beetlex-core-updb",
-        "notes": "",
-        "versus": "aspcore"
       }
     }
   ]

+ 0 - 12
frameworks/CSharp/beetlex/config.toml

@@ -36,15 +36,3 @@ platform = ".NET"
 webserver = "beetlex"
 versus = "aspcore"
 
-[core-updb]
-urls.update = "/updates?queries="
-urls.fortune = "/fortunes"
-approach = "Realistic"
-classification = "Platform"
-database = "Postgres"
-database_os = "Linux"
-os = "Linux"
-orm = "Raw"
-platform = ".NET"
-webserver = "beetlex"
-versus = "aspcore"