Browse Source

add ZYSOCKET-V

yi lu 6 years ago
parent
commit
22668455c9
22 changed files with 1041 additions and 0 deletions
  1. 25 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks.sln
  2. 48 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/AsciiString.cs
  3. 31 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/ConcurrentRandom.cs
  4. 124 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/DBRaw.cs
  5. 24 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/Fortune.cs
  6. 186 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/GMTDate.cs
  7. 198 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/HttpHandler.cs
  8. 9 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/HttpToken.cs
  9. 15 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/JsonMessage.cs
  10. 17 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/PlatformBenchmarks.csproj
  11. 18 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/Program.cs
  12. 13 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/Properties/PublishProfiles/FolderProfile.pubxml
  13. 15 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/World.cs
  14. 91 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/ZYHttpServer.cs
  15. 28 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/db.cs
  16. 63 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/fortunes.cs
  17. 19 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/json.cs
  18. 15 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/plaintext.cs
  19. 40 0
      frameworks/CSharp/zysocket-v/PlatformBenchmarks/queries.cs
  20. 23 0
      frameworks/CSharp/zysocket-v/README.md
  21. 29 0
      frameworks/CSharp/zysocket-v/benchmark_config.json
  22. 10 0
      frameworks/CSharp/zysocket-v/zysocket-v.dockerfile

+ 25 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29230.47
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformBenchmarks", "PlatformBenchmarks\PlatformBenchmarks.csproj", "{E4500562-635D-4DB9-99AE-B321F52A7C46}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{E4500562-635D-4DB9-99AE-B321F52A7C46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E4500562-635D-4DB9-99AE-B321F52A7C46}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E4500562-635D-4DB9-99AE-B321F52A7C46}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E4500562-635D-4DB9-99AE-B321F52A7C46}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {9FD9812E-E78B-4B9F-8526-8C85458ABA2E}
+	EndGlobalSection
+EndGlobal

+ 48 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/AsciiString.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace PlatformBenchmarks
+{
+    public readonly struct AsciiString : IEquatable<AsciiString>
+    {
+        private readonly byte[] _data;
+
+        public AsciiString(string s) => _data = Encoding.ASCII.GetBytes(s);
+
+        public int Length => _data.Length;
+
+        public byte[] Data => _data;
+
+        public ReadOnlySpan<byte> AsSpan() => _data;
+
+        public static implicit operator ReadOnlySpan<byte>(AsciiString str) => str._data;
+        public static implicit operator byte[](AsciiString str) => str._data;
+
+        public static implicit operator AsciiString(string str) => new AsciiString(str);
+
+        public static explicit operator string(AsciiString str) => str.ToString();
+
+        public bool Equals(AsciiString other) => ReferenceEquals(_data, other._data) || SequenceEqual(_data, other._data);
+        private bool SequenceEqual(byte[] data1, byte[] data2) => new Span<byte>(data1).SequenceEqual(data2);
+
+        public static bool operator ==(AsciiString a, AsciiString b) => a.Equals(b);
+        public static bool operator !=(AsciiString a, AsciiString b) => !a.Equals(b);
+        public override bool Equals(object other) => (other is AsciiString) && Equals((AsciiString)other);
+
+        public override int GetHashCode()
+        {
+            // Copied from x64 version of string.GetLegacyNonRandomizedHashCode()
+            // https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/String.Comparison.cs
+            var data = _data;
+            int hash1 = 5381;
+            int hash2 = hash1;
+            foreach (int b in data)
+            {
+                hash1 = ((hash1 << 5) + hash1) ^ b;
+            }
+            return hash1 + (hash2 * 1566083941);
+        }
+
+    }
+}

+ 31 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/ConcurrentRandom.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading;
+
+namespace PlatformBenchmarks
+{
+    public class ConcurrentRandom
+    {
+        private static int nextSeed = 0;
+
+        // Random isn't thread safe
+        [ThreadStatic]
+        private static Random _random;
+
+        private static Random Random => _random ?? CreateRandom();
+
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        private static Random CreateRandom()
+        {
+            _random = new Random(Interlocked.Increment(ref nextSeed));
+            return _random;
+        }
+
+        public int Next(int minValue, int maxValue)
+        {
+            return Random.Next(minValue, maxValue);
+        }
+    }
+}

+ 124 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/DBRaw.cs

@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PlatformBenchmarks
+{
+    public class RawDb
+    {
+
+        private readonly ConcurrentRandom _random;
+
+        private readonly DbProviderFactory _dbProviderFactory;
+
+        private readonly string _connectionString;
+
+        public RawDb(ConcurrentRandom random, DbProviderFactory dbProviderFactory)
+        {
+            _random = random;
+            _dbProviderFactory = dbProviderFactory;
+            _connectionString = "Server=tfb-database;Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=3";
+            //_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";
+            OnCreateCommand();
+        }
+
+        private void OnCreateCommand()
+        {
+            SingleCommand = new Npgsql.NpgsqlCommand();
+            SingleCommand.CommandText = "SELECT id, randomnumber FROM world WHERE id = @Id";
+            var id = SingleCommand.CreateParameter();
+            id.ParameterName = "@Id";
+            id.DbType = DbType.Int32;
+            id.Value = _random.Next(1, 10001);
+            SingleCommand.Parameters.Add(id);
+            FortuneCommand = new Npgsql.NpgsqlCommand();
+            FortuneCommand.CommandText = "SELECT id, message FROM fortune";
+        }
+
+        private DbCommand SingleCommand;
+
+        private DbCommand FortuneCommand;
+
+        public async Task<World> LoadSingleQueryRow()
+        {
+            using (var db = _dbProviderFactory.CreateConnection())
+            {
+                db.ConnectionString = _connectionString;
+                await db.OpenAsync();
+                SingleCommand.Connection = db;
+                SingleCommand.Parameters[0].Value = _random.Next(1, 10001);
+                return await ReadSingleRow(db, SingleCommand);
+
+            }
+        }
+
+        async Task<World> ReadSingleRow(DbConnection connection, DbCommand cmd)
+        {
+            using (var rdr = await cmd.ExecuteReaderAsync(CommandBehavior.SingleRow))
+            {
+                await rdr.ReadAsync();
+
+                return new World
+                {
+                    Id = rdr.GetInt32(0),
+                    RandomNumber = rdr.GetInt32(1)
+                };
+            }
+        }
+
+        public async Task<World[]> LoadMultipleQueriesRows(int count)
+        {
+            using (var db = _dbProviderFactory.CreateConnection())
+            {
+                db.ConnectionString = _connectionString;
+                await db.OpenAsync();
+                return await LoadMultipleRows(count, db);
+            }
+
+        }
+
+        private async Task<World[]> LoadMultipleRows(int count, DbConnection db)
+        {
+            SingleCommand.Connection = db;
+            SingleCommand.Parameters[0].Value = _random.Next(1, 10001);
+            var result = new World[count];
+            for (int i = 0; i < result.Length; i++)
+            {
+                result[i] = await ReadSingleRow(db, SingleCommand);
+                SingleCommand.Parameters[0].Value = _random.Next(1, 10001);
+            }
+            return result;
+
+        }
+
+        public async Task<List<Fortune>> LoadFortunesRows()
+        {
+            var result = new List<Fortune>();
+
+            using (var db = _dbProviderFactory.CreateConnection())
+
+            {
+                db.ConnectionString = _connectionString;
+                await db.OpenAsync();
+                FortuneCommand.Connection = db;
+                using (var rdr = await FortuneCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection))
+                {
+                    while (await rdr.ReadAsync())
+                    {
+                        result.Add(new Fortune
+                        {
+                            Id = rdr.GetInt32(0),
+                            Message = rdr.GetString(1)
+                        });
+                    }
+                }
+            }
+            result.Add(new Fortune { Message = "Additional fortune added at request time." });
+            result.Sort();
+            return result;
+        }
+    }
+}

+ 24 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/Fortune.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace PlatformBenchmarks
+{
+    public class Fortune : IComparable<Fortune>, IComparable
+    {
+        public int Id { get; set; }
+
+        public string Message { get; set; }
+
+        public int CompareTo(object obj)
+        {
+            return CompareTo((Fortune)obj);
+        }
+
+        public int CompareTo(Fortune other)
+        {
+            // Performance critical, using culture insensitive comparison
+            return String.CompareOrdinal(Message, other.Message);
+        }
+    }
+}

+ 186 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/GMTDate.cs

@@ -0,0 +1,186 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+
+namespace PlatformBenchmarks
+{
+    internal class GMTDate
+    {
+        private List<byte[]> mWeekBuffers = new List<byte[]>();
+
+        public List<byte[]> mYears = new List<byte[]>();
+
+        public List<byte[]> mMoth = new List<byte[]>();
+
+        public List<byte[]> mNumber = new List<byte[]>();
+
+        private byte _1 = 58;
+
+        private byte _s = 32;
+
+        private byte _r = 13;
+
+        private byte _n = 10;
+
+        private byte[] GMT = new byte[3]
+        {
+        71,
+        77,
+        84
+        };
+
+        private static GMTDate mDefault;
+
+        private Timer mUpdateTime;
+
+        public static GMTDate Default
+        {
+            get
+            {
+                if (mDefault == null)
+                {
+                    mDefault = new GMTDate();
+                    mDefault.Init();
+                }
+                return mDefault;
+            }
+        }
+
+        public ArraySegment<byte> DATE
+        {
+            get;
+            set;
+        }
+
+        public GMTDate()
+        {
+            mWeekBuffers.Add(Encoding.ASCII.GetBytes("Sun"));
+            mWeekBuffers.Add(Encoding.ASCII.GetBytes("Mon"));
+            mWeekBuffers.Add(Encoding.ASCII.GetBytes("Tue"));
+            mWeekBuffers.Add(Encoding.ASCII.GetBytes("Wed"));
+            mWeekBuffers.Add(Encoding.ASCII.GetBytes("Thu"));
+            mWeekBuffers.Add(Encoding.ASCII.GetBytes("Fri"));
+            mWeekBuffers.Add(Encoding.ASCII.GetBytes("Sat"));
+            for (int j = 1970; j < 2470; j++)
+            {
+                mYears.Add(Encoding.ASCII.GetBytes(j.ToString()));
+            }
+            for (int i = 0; i <= 100; i++)
+            {
+                mNumber.Add(Encoding.ASCII.GetBytes(i.ToString("00")));
+            }
+            mMoth.Add(Encoding.ASCII.GetBytes("Jan"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Feb"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Mar"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Apr"));
+            mMoth.Add(Encoding.ASCII.GetBytes("May"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Jun"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Jul"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Aug"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Sep"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Oct"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Nov"));
+            mMoth.Add(Encoding.ASCII.GetBytes("Dec"));
+        }
+
+        private void Init()
+        {
+            DATE = GetData(inLine: true);
+            mUpdateTime = new Timer(delegate
+            {
+                DATE = GetData(inLine: true);
+            }, null, 1000, 1000);
+        }
+
+        private ArraySegment<byte> GetData(bool inLine = false)
+        {
+            return GetData(DateTime.Now, inLine);
+        }
+
+        private ArraySegment<byte> GetData(DateTime date, bool inLine = false)
+        {
+            date = date.ToUniversalTime();
+            int offset13 = 0;
+            byte[] GTM_BUFFER = new byte[50];
+            Encoding.ASCII.GetBytes("Date: ", 0, 6, GTM_BUFFER, 0);
+            offset13 = 6;
+            byte[] buffer = GTM_BUFFER;
+            byte[] sub8 = mWeekBuffers[(int)date.DayOfWeek];
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = sub8[2];
+            offset13++;
+            buffer[offset13] = 44;
+            offset13++;
+            buffer[offset13] = _s;
+            offset13++;
+            sub8 = mNumber[date.Day];
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = _s;
+            offset13++;
+            sub8 = mMoth[date.Month - 1];
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = sub8[2];
+            offset13++;
+            buffer[offset13] = _s;
+            offset13++;
+            sub8 = mYears[date.Year - 1970];
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = sub8[2];
+            offset13++;
+            buffer[offset13] = sub8[3];
+            offset13++;
+            buffer[offset13] = _s;
+            offset13++;
+            sub8 = mNumber[date.Hour];
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = _1;
+            offset13++;
+            sub8 = mNumber[date.Minute];
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = _1;
+            offset13++;
+            sub8 = mNumber[date.Second];
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = _s;
+            offset13++;
+            sub8 = GMT;
+            buffer[offset13] = sub8[0];
+            offset13++;
+            buffer[offset13] = sub8[1];
+            offset13++;
+            buffer[offset13] = sub8[2];
+            offset13++;
+            if (inLine)
+            {
+                buffer[offset13] = _r;
+                offset13++;
+                buffer[offset13] = _n;
+                offset13++;
+            }
+            return new ArraySegment<byte>(GTM_BUFFER, 0, offset13);
+        }
+    }
+
+}

+ 198 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/HttpHandler.cs

@@ -0,0 +1,198 @@
+using System;
+using System.Buffers;
+using System.Text;
+using System.Threading.Tasks;
+using ZYSocket;
+using ZYSocket.FiberStream;
+
+namespace PlatformBenchmarks
+{
+    public partial class HttpHandler
+    {
+        private static AsciiString _line = new AsciiString("\r\n");
+
+        private static AsciiString _2line = new AsciiString("\r\n\r\n");
+
+        private static AsciiString _httpsuccess = new AsciiString("HTTP/1.1 200 OK\r\n");
+
+        private static readonly AsciiString _headerServer = "Server: zysocket\r\n";
+
+        private static readonly AsciiString _headerContentLength = "Content-Length: ";
+
+        private static readonly AsciiString _headerContentLengthZero = "Content-Length: 0\r\n";
+
+        private static readonly AsciiString _headerContentTypeText = "Content-Type: text/plain\r\n";
+
+        private static readonly AsciiString _headerContentTypeHtml = "Content-Type: text/html; charset=UTF-8\r\n";
+
+        private static readonly AsciiString _headerContentTypeJson = "Content-Type: application/json\r\n";
+
+        private static readonly AsciiString _path_Json = "/json";
+
+        private static readonly AsciiString _path_Db = "/db";
+
+        private static readonly AsciiString _path_Queries = "/queries";
+
+        private static readonly AsciiString _path_Plaintext = "/plaintext";
+
+        private static readonly AsciiString _path_Fortunes = "/fortunes";
+
+        private static readonly AsciiString _result_plaintext = "Hello, World!";
+
+        private static readonly byte[] LenData = new byte[10] { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
+
+        private static byte _Space = 32;
+
+        private static byte _question = 63;
+
+        private RawDb mPgsql;
+
+        public HttpHandler()
+        {
+
+            mPgsql = new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance);
+        }
+
+        public void Default(IFiberRw<HttpToken> fiberRw,ref WriteBytes write)
+        {
+            write.Write("<b> zysocket server</b><hr/>");         
+            write.Write($"error not found!");
+            OnCompleted(fiberRw, write);
+        }
+
+        private async void OnCompleted(IFiberRw<HttpToken> fiberRw, WriteBytes write)
+        {
+            Task<int> WSend()
+            {
+                var length = write.Stream.Length - fiberRw.UserToken.HttpHandlerPostion;
+                write.Stream.Position = fiberRw.UserToken.ContentPostion.postion;
+                write.Write(length.ToString(), false);
+                write.Flush(false);
+                return fiberRw.Flush();
+            }
+
+            await await fiberRw.Sync.Ask(WSend);
+        }
+
+        private int AnalysisUrl(ReadOnlySpan<byte> url)
+        {
+            for (int i = 0; i < url.Length; i++)
+            {
+                if (url[i] == _question)
+                    return i;
+            }
+            return -1;
+
+        }
+
+        public async Task Receive(IFiberRw<HttpToken> fiberRw, Memory<byte> memory_r, Memory<byte> memory_w)
+        {
+            var data = (await fiberRw.ReadLine(memory_r));
+            ReadHander(fiberRw, ref memory_w,ref data);
+            fiberRw.StreamReadFormat.Position = fiberRw.StreamReadFormat.Length;
+        }
+
+
+        private void ReadHander(IFiberRw<HttpToken> fiberRw,ref Memory<byte> memory_w, ref Memory<byte> linedata)
+        {
+            WriteBytes write = new WriteBytes(fiberRw, ref memory_w);
+            var token = fiberRw.UserToken;
+            ReadOnlySpan<byte> line = linedata.Span;
+            ReadOnlySpan<byte> url = line;
+
+            int offset2 = 0;
+            int count = 0;
+            for (int i = 0; i < line.Length; i++)
+            {
+                if (line[i] == _Space)
+                {
+                    if (count != 0)
+                    {
+                        url = line.Slice(offset2, i - offset2);
+                        offset2 = i + 1;                      
+                        break;
+                    }                  
+                    offset2 = i + 1;
+                    count++;
+                }
+            }
+
+          
+            int queryIndex = AnalysisUrl(url);
+            ReadOnlySpan<byte> queryString = default;
+            ReadOnlySpan<byte> baseUrl;
+            if (queryIndex > 0)
+            {
+                baseUrl = url.Slice(0, queryIndex);
+                queryString = url.Slice(queryIndex + 1, url.Length - queryIndex - 1);
+            }
+            else
+            {
+                baseUrl = url;
+            }
+            OnWriteHeader(ref write);
+
+            if (baseUrl.Length == _path_Plaintext.Length && baseUrl.StartsWith(_path_Plaintext))
+            {
+                write.Write(_headerContentTypeText.Data, 0, _headerContentTypeText.Length);
+                OnWriteContentLength(write, token);
+                Plaintext(fiberRw, ref write);
+            }
+            else if (baseUrl.Length == _path_Json.Length && baseUrl.StartsWith(_path_Json))
+            {
+                write.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
+                OnWriteContentLength(write, token);
+                Json(fiberRw, ref write);
+            }
+            else if (baseUrl.Length == _path_Db.Length && baseUrl.StartsWith(_path_Db))
+            {
+                write.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
+                OnWriteContentLength(write, token);
+                db(fiberRw, write);
+            }
+            else if (baseUrl.Length == _path_Queries.Length && baseUrl.StartsWith(_path_Queries))
+            {
+                write.Write(_headerContentTypeJson.Data, 0, _headerContentTypeJson.Length);
+                OnWriteContentLength(write, token);
+                queries(Encoding.ASCII.GetString(queryString),fiberRw, write);
+            }
+            else if (baseUrl.Length == _path_Fortunes.Length && baseUrl.StartsWith(_path_Fortunes))
+            {
+                write.Write(_headerContentTypeHtml.Data, 0, _headerContentTypeHtml.Length);
+                OnWriteContentLength(write, token);
+                fortunes(fiberRw, write);
+            }
+            else
+            {
+                write.Write(_headerContentTypeHtml.Data, 0, _headerContentTypeHtml.Length);
+                OnWriteContentLength(write, token);
+                Default( fiberRw, ref write);
+            }
+
+        }
+
+
+        private void OnWriteHeader(ref WriteBytes write)
+        {
+            write.Write(_httpsuccess.Data, 0, _httpsuccess.Length);
+            write.Write(_headerServer.Data, 0, _headerServer.Length);
+            ArraySegment<byte> date = GMTDate.Default.DATE;
+            write.Write(date.Array, date.Offset, date.Count);
+        }
+
+
+
+        private void OnWriteContentLength(WriteBytes write, HttpToken token)
+        {
+            write.Write(_headerContentLength.Data, 0, _headerContentLength.Length);
+            token.ContentPostion = write.Allocate(LenData);
+            write.Write(_2line, 0, 4);
+            token.HttpHandlerPostion = (int)write.Stream.Position;
+        }
+
+       
+
+
+
+    }
+}

+ 9 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/HttpToken.cs

@@ -0,0 +1,9 @@
+namespace PlatformBenchmarks
+{
+    public class HttpToken
+    {
+        public (int postion, int size) ContentPostion { get; set; }
+        public long HttpHandlerPostion { get; set; }
+        public RawDb Db { get; set; }
+    }
+}

+ 15 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/JsonMessage.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace PlatformBenchmarks
+{
+    public struct JsonMessage
+    {
+        public string message
+        {
+            get;
+            set;
+        }
+    }
+}

+ 17 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/PlatformBenchmarks.csproj

@@ -0,0 +1,17 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <ServerGarbageCollection>true</ServerGarbageCollection>
+    <LangVersion>7.2</LangVersion>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
+    <PackageReference Include="Npgsql" Version="4.0.10" />
+    <PackageReference Include="SpanJson" Version="2.0.14" />
+    <PackageReference Include="ZYSocketServerV" Version="1.5.7" />
+  </ItemGroup>
+
+</Project>

+ 18 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/Program.cs

@@ -0,0 +1,18 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using System;
+
+namespace PlatformBenchmarks
+{
+    class Program
+    {
+        public static void Main(string[] args)
+        {
+            new HostBuilder().ConfigureServices(delegate (HostBuilderContext hostContext, IServiceCollection services)
+            {
+                services.AddHostedService<ZYHttpServer>();
+
+            }).Build().Run();
+        }
+    }
+}

+ 13 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/Properties/PublishProfiles/FolderProfile.pubxml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+https://go.microsoft.com/fwlink/?LinkID=208121. 
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <PublishProtocol>FileSystem</PublishProtocol>
+    <Configuration>Release</Configuration>
+    <Platform>Any CPU</Platform>
+    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <PublishDir>bin\Release\netcoreapp2.2\publish\</PublishDir>
+  </PropertyGroup>
+</Project>

+ 15 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/World.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace PlatformBenchmarks
+{
+    [StructLayout(LayoutKind.Sequential, Size = 8)]
+    public struct World
+    {
+        public int Id { get; set; }
+
+        public int RandomNumber { get; set; }
+    }
+}

+ 91 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/ZYHttpServer.cs

@@ -0,0 +1,91 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using ZYSocket;
+using ZYSocket.Server;
+using ZYSocket.Server.Builder;
+
+namespace PlatformBenchmarks
+{
+    public class ZYHttpServer : IHostedService
+    {
+        public ISocketServer SocketServer { get; private set; }
+        public IServiceProvider serviceProvider { get; private set; }
+
+        public HttpHandler @HttpHandler { get; private set; }
+
+        public ZYHttpServer()
+        {
+            ArraySegment<byte> date = GMTDate.Default.DATE;
+            var containerBuilder = new ServiceCollection();
+            new SockServBuilder(containerBuilder, p =>
+            {
+                return new ZYSocketSuper(p)
+                {
+                    BinaryInput = new BinaryInputHandler(BinaryInputHandler),
+                    Connetions = new ConnectionFilter(ConnectionFilter),
+                    MessageInput = new DisconnectHandler(DisconnectHandler)
+                };
+            })
+             .ConfigServer(p =>
+             {
+                 p.Port = 8080;
+                 p.MaxBufferSize = 4096;
+                 p.MaxConnectCout = 20000;
+             });
+
+            serviceProvider = containerBuilder.BuildServiceProvider();
+            SocketServer = serviceProvider.GetRequiredService<ISocketServer>();
+            @HttpHandler = new HttpHandler();
+        }
+
+
+        public Task StartAsync(CancellationToken cancellationToken)
+        {
+            SocketServer.Start();
+            return Task.CompletedTask;
+        }
+
+        public Task StopAsync(CancellationToken cancellationToken)
+        {
+            SocketServer.Stop();
+            return Task.CompletedTask;
+        }
+
+        bool ConnectionFilter(ISockAsyncEvent socketAsync) => true;
+
+        void DisconnectHandler(string message, ISockAsyncEvent socketAsync, int erorr)
+        {
+            socketAsync.UserToken = null;
+            socketAsync.AcceptSocket.Dispose();
+        }
+
+
+        async void BinaryInputHandler(ISockAsyncEvent socketAsync)
+        {
+            var fiberRw = await socketAsync.GetFiberRw<HttpToken>();
+            fiberRw.UserToken = new HttpToken
+            {
+                Db= new RawDb(new ConcurrentRandom(), Npgsql.NpgsqlFactory.Instance)
+            };
+            
+           
+
+            using (var data_r = fiberRw.GetMemory(4096))
+            using (var data_w = fiberRw.GetMemory(4096))
+            {
+
+                for (; ; )
+                {
+                    await HttpHandler.Receive(fiberRw, data_r.Memory, data_w.Memory);
+                }
+
+            }
+            
+        }
+    }
+}

+ 28 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/db.cs

@@ -0,0 +1,28 @@
+using SpanJson;
+using System;
+using System.Threading.Tasks;
+using ZYSocket;
+using ZYSocket.FiberStream;
+
+namespace PlatformBenchmarks
+{
+    public partial class HttpHandler
+    {
+
+        public async void db(IFiberRw<HttpToken> fiberRw, WriteBytes write)
+        {
+            try
+            {
+                var data = await fiberRw.UserToken.Db.LoadSingleQueryRow();
+                await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, write.Stream);
+            }
+            catch (Exception e_)
+            {
+                write.Write(e_.Message);               
+            }
+
+            OnCompleted(fiberRw, write);
+
+        }
+    }
+}

+ 63 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/fortunes.cs

@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Threading.Tasks;
+using ZYSocket;
+using ZYSocket.FiberStream;
+
+namespace PlatformBenchmarks
+{
+    public partial class HttpHandler
+    {
+
+        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>";
+
+        public async void fortunes(IFiberRw<HttpToken> fiberRw, WriteBytes write)
+        {
+            List<Fortune> data = null;
+
+            try
+            {
+                data = await mPgsql.LoadFortunesRows();
+
+                Task<int> WSend()
+                {
+                    write.Write(_fortunesTableStart.Data, 0, _fortunesTableStart.Length);
+                    foreach (var item in data)
+                    {
+                        write.Write(_fortunesRowStart.Data, 0, _fortunesRowStart.Length);
+                        write.Write(item.Id.ToString(CultureInfo.InvariantCulture));
+                        write.Write(_fortunesColumn.Data, 0, _fortunesColumn.Length);
+                        write.Write(System.Web.HttpUtility.HtmlEncode(item.Message));
+                        write.Write(_fortunesRowEnd.Data, 0, _fortunesRowEnd.Length);
+                    }
+                    write.Write(_fortunesTableEnd.Data, 0, _fortunesTableEnd.Length);
+
+                    var length = write.Stream.Length - fiberRw.UserToken.HttpHandlerPostion;
+                    write.Stream.Position = fiberRw.UserToken.ContentPostion.postion;
+                    write.Write(length.ToString(), false);
+                    write.Flush(false);
+                    return fiberRw.Flush();
+                }
+
+                await await fiberRw.Sync.Ask(WSend);
+            }
+            catch (Exception e_)
+            {
+                write.Write(e_.Message);
+
+                OnCompleted(fiberRw, write);
+            }
+
+
+
+        
+
+
+        }
+    }
+}

+ 19 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/json.cs

@@ -0,0 +1,19 @@
+using SpanJson;
+using System;
+using System.Threading.Tasks;
+using ZYSocket;
+using ZYSocket.FiberStream;
+
+namespace PlatformBenchmarks
+{
+    public partial class HttpHandler
+    {
+        public void Json(IFiberRw<HttpToken> fiberRw,ref WriteBytes write)
+        {
+            JsonMessage jsonMessage = default(JsonMessage);
+            jsonMessage.message = "Hello, World!";
+            JsonSerializer.NonGeneric.Utf8.SerializeAsync(jsonMessage, write.Stream);
+            OnCompleted(fiberRw, write);
+        }
+    }
+}

+ 15 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/plaintext.cs

@@ -0,0 +1,15 @@
+using System;
+using ZYSocket;
+using ZYSocket.FiberStream;
+
+namespace PlatformBenchmarks
+{
+    public partial class HttpHandler
+    {
+        public  void Plaintext( IFiberRw<HttpToken> fiberRw,  ref WriteBytes write)
+        {
+            write.Write(_result_plaintext.Data, 0, _result_plaintext.Length);
+            OnCompleted(fiberRw, write);
+        }
+    }
+}

+ 40 - 0
frameworks/CSharp/zysocket-v/PlatformBenchmarks/queries.cs

@@ -0,0 +1,40 @@
+using SpanJson;
+using System;
+using ZYSocket;
+using ZYSocket.FiberStream;
+
+namespace PlatformBenchmarks
+{
+    public partial class HttpHandler
+    {
+        public async void queries(string queryString, IFiberRw<HttpToken> fiberRw, WriteBytes write)
+        {
+            int count = 1;
+            if (!string.IsNullOrEmpty(queryString))
+            {
+                var values = queryString.Split('=');
+                if (values.Length > 1)
+                {
+                    if (int.TryParse(values[1], out int size))
+                    {
+                        count = size;
+                    }
+                }
+            }
+            if (count > 500)
+                count = 500;
+            if (count < 1)
+                count = 1;
+            try
+            {
+                var data = await mPgsql.LoadMultipleQueriesRows(count);
+                await JsonSerializer.NonGeneric.Utf8.SerializeAsync(data, write.Stream);
+            }
+            catch (Exception e_)
+            {
+                write.Write(e_.Message);
+            }
+            OnCompleted(fiberRw, write);
+        }
+    }
+}

+ 23 - 0
frameworks/CSharp/zysocket-v/README.md

@@ -0,0 +1,23 @@
+# [ZYSOCKET-V](ZYSOCKET-V](https://github.com/luyikk/zysocket-v)(.Net) Benchmarking Test
+This includes tests for plaintext, json, db, queries and fortune.
+
+## Infrastructure Software Versions
+**Language**
+
+* C# 7.2
+
+**Platforms**
+
+* .NET Core (Windows and Linux)
+
+**Web Servers**
+
+* [ZYSOCKET-V](https://github.com/luyikk/zysocket-v)
+
+## Paths & Source for Tests
+
+* [Plaintext](PlatformBenchmarks/Program.cs): "/plaintext"
+* [JSON Serialization](PlatformBenchmarks/Program.cs): "/json"
+* [Single query](PlatformBenchmarks/Program.cs): "/db"
+* [Multiple query](PlatformBenchmarks/Program.cs): "/queries"
+* [Fortune](PlatformBenchmarks/Program.cs): "/fortune"

+ 29 - 0
frameworks/CSharp/zysocket-v/benchmark_config.json

@@ -0,0 +1,29 @@
+{
+  "framework": "zysocket-v",
+  "tests": [
+    {
+      "default": {
+        "fortune_url": "/fortunes",
+        "plaintext_url": "/plaintext",
+        "json_url": "/json",
+        "db_url": "/db",
+        "query_url": "/queries?queries=",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "Postgres",
+        "framework": "zysocket-v",
+        "language": "C#",
+        "orm": "Raw",
+        "platform": ".NET",
+        "flavor": "CoreCLR",
+        "webserver": "zysocket-v",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "zysocket-v",
+        "notes": "",
+        "versus": "aspcore-mvc"
+      }
+    }
+  ]
+}

+ 10 - 0
frameworks/CSharp/zysocket-v/zysocket-v.dockerfile

@@ -0,0 +1,10 @@
+FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
+WORKDIR /app
+COPY PlatformBenchmarks .
+RUN dotnet publish -c Release -o out
+
+FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
+ENV COMPlus_ReadyToRun 0
+WORKDIR /app
+COPY --from=build /app/out ./
+ENTRYPOINT ["dotnet", "PlatformBenchmarks.dll"]