lith 4 gadi atpakaļ
vecāks
revīzija
2822d72a00

+ 2 - 2
dotnet/Library/Sers/Sers.CL/Socket/Sers.CL.Socket.Iocp/DeliveryClient.cs

@@ -55,11 +55,11 @@ namespace Sers.CL.Socket.Iocp
         /// <summary>
         ///  服务端 host地址(默认 "127.0.0.1" )。例如: "127.0.0.1"、"sers.com"。
         /// </summary>
-        public string host;
+        public string host = "127.0.0.1";
         /// <summary>
         /// 服务端 监听端口号(默认4501)。例如: 4501。
         /// </summary>
-        public int port;
+        public int port = 4501;
         public bool Connect()
         {
             try

+ 24 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryClient/DeliveryClient.csproj

@@ -0,0 +1,24 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\Ipc\Sers.CL.Ipc.NamedPipe\Sers.CL.Ipc.NamedPipe.csproj" />
+    <ProjectReference Include="..\..\..\Ipc\Sers.CL.Ipc.SharedMemory\Sers.CL.Ipc.SharedMemory.csproj" />
+    <ProjectReference Include="..\..\..\Socket\Sers.CL.Socket.Iocp\Sers.CL.Socket.Iocp.csproj" />
+    <ProjectReference Include="..\..\..\Socket\Sers.CL.Socket.ThreadWait\Sers.CL.Socket.ThreadWait.csproj" />
+    <ProjectReference Include="..\..\..\WebSocket\Sers.CL.WebSocket\Sers.CL.WebSocket.csproj" />
+    <ProjectReference Include="..\..\..\Zmq\FullDuplex\Sers.CL.Zmq.FullDuplex\Sers.CL.Zmq.FullDuplex.csproj" />
+    <ProjectReference Include="..\..\..\Zmq\ThreadWait\Sers.CL.ClrZmq.ThreadWait\Sers.CL.ClrZmq.ThreadWait.csproj" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <None Update="StartConsole.bat">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
+</Project>

+ 4 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryClient/DeliveryTest.csproj

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup />
+</Project>

+ 119 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryClient/Program.cs

@@ -0,0 +1,119 @@
+using CLServer.Statistics;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using Vit.Core.Module.Log;
+using Vit.Core.Util.Threading;
+
+namespace DeliveryTest
+{
+    class Program
+    {
+
+
+        static StatisticsQpsInfo qpsInfo = new StatisticsQpsInfo();
+        static void Main(string[] args)
+        {
+            Logger.OnLog = (level, msg) => { Console.Write("[" + level + "]" + msg); };
+
+            try
+            {
+
+                if (args != null && args.Length > 0)
+                {
+                    int t = 0;
+
+                    if (args.Length > t)
+                    {
+                        host = args[t];
+                    }
+
+                    t++;
+                    if (args.Length > t)
+                    {
+                        int.TryParse(args[t], out port);
+                    }
+
+                    t++;
+                    if (args.Length > t)
+                    {
+                        int.TryParse(args[t], out thread);
+                    }
+
+
+                    t++;
+                    if (args.Length > t)
+                    {
+                        int.TryParse(args[t], out msgLen);
+                    }
+
+                }
+
+                qpsInfo.Start("Msg");
+
+                StartClient();
+
+
+                while (true)
+                {
+                    Thread.Sleep(5000);
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex);
+            }
+
+        }
+
+        static string host = "127.0.0.1";
+        static int port = 4501;
+
+        static int thread = 16;
+        static int msgLen = 1024;
+
+
+
+ 
+
+        static void StartClient()
+        {
+            var client = new Sers.CL.Socket.Iocp.DeliveryClient();
+            client.host = host;
+            client.port = port;
+
+            //var client = new Sers.CL.WebSocket.DeliveryClient();
+            //var client = new Sers.CL.ClrZmq.ThreadWait.DeliveryClient();
+            //var client = new Sers.CL.Ipc.SharedMemory.DeliveryClient();
+            //var client = new Sers.CL.Zmq.FullDuplex.DeliveryClient();
+            //var client = new Sers.CL.Ipc.NamedPipe.DeliveryClient();
+
+            client.Conn_OnGetFrame = (conn, data) =>
+            {
+
+                qpsInfo.IncrementRequest();
+
+                //data[0]++;
+
+                data[1] = 10;
+                var byteData = new List<ArraySegment<byte>>() { data };
+                conn.SendFrameAsync(byteData);
+           
+            };
+
+            var connected = client.Connect();
+
+            Console.WriteLine(connected?"连接成功": "连接失败");
+
+
+            byte[] buff = new byte[msgLen];
+
+            for (var t = 0; t < thread; t++)
+            {
+                client.conn.SendFrameAsync(new List<ArraySegment<byte>>() { new ArraySegment<byte>(buff)});
+            }
+
+        }
+
+    }
+}

+ 15 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryClient/Properties/PublishProfiles/FolderProfile.pubxml

@@ -0,0 +1,15 @@
+<?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.1</TargetFramework>
+    <PublishDir>bin\DeliveryClient</PublishDir>
+    <SelfContained>false</SelfContained>
+    <_IsPortable>true</_IsPortable>
+  </PropertyGroup>
+</Project>

+ 10 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryClient/StartConsole.bat

@@ -0,0 +1,10 @@
+
+:: dotnet DeliveryClient.dll host port thread msgLen
+:: dotnet DeliveryClient.dll 127.0.0.1 4501 200 1024
+
+
+dotnet DeliveryClient.dll
+pause
+
+
+ 

+ 111 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryClient/Statistics/StatisticsQpsInfo.cs

@@ -0,0 +1,111 @@
+/// v3
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace CLServer.Statistics
+{
+    public class StatisticsQpsInfo
+    {
+        //public static StatisQpsInfo Instance = new StatisQpsInfo();
+
+
+        string name = "";
+
+
+        DateTime? startTime;
+
+        bool finished = false;
+        public void Start(string name)
+        {
+            this.name += name;
+            finished = false;
+            startTime = DateTime.Now;
+            Console.WriteLine("¿ªÊ¼");
+
+            Task.Run(() => {
+
+                while (!finished)
+                {
+                    Console.WriteLine(ToString());
+                    Thread.Sleep(1000);
+                }
+
+            });
+
+
+        }
+        public void Stop()
+        {
+            finished = true;
+            Console.WriteLine("½áÊø");
+            Console.WriteLine(ToString());
+        }
+
+        public int RequestCount = 0;
+        public void IncrementRequest() => Interlocked.Increment(ref RequestCount);
+
+        public long RequestTicks = 0;
+        public void IncrementRequestTicks(long value) => Interlocked.Add(ref RequestTicks, value);
+
+
+        public int ErrorCount = 0;
+        public void IncrementError() => Interlocked.Increment(ref ErrorCount);
+
+
+        long lastRequestTicks = 0;
+        int lastCount = 0;
+        DateTime lastTime;
+        public override string ToString()
+        {
+            var curCount = RequestCount;
+            var curRequestTicks = RequestTicks;
+
+            var msg = $"[{name}]ReqCount: {curCount}";
+
+            double d;
+
+            if (curCount > 0)
+            {
+                d = ErrorCount * 100.0 / curCount;
+                msg += $",error:{ErrorCount}({d.ToString("0.00")}%)";
+            }
+            if (startTime.HasValue)
+            {
+                if (lastCount == 0)
+                {
+                    lastTime = startTime.Value;
+                }
+                var curTime = DateTime.Now;
+
+                //sum
+                var ms = (curTime - startTime.Value).TotalMilliseconds;
+                d =  curCount / ms * 1000;
+                msg += $",qps:{ d.ToString("0.00") }";
+
+                ms = 1.0 * curRequestTicks / TimeSpan.TicksPerMillisecond;
+                d = (curCount <= 0 ? 0 : ms / curCount);
+                msg += $",ms/req:{ d.ToString("0.00") }";
+
+
+                //cur
+                msg += $",------Cur";                
+                msg += $",ReqCount: {curCount}";
+                ms = (curTime - lastTime).TotalMilliseconds;
+                d = (curCount - lastCount) / ms * 1000;
+                msg += $",qps:{ d.ToString("0.00")  }";
+                ms = 1.0 * (curRequestTicks - lastRequestTicks) / TimeSpan.TicksPerMillisecond;
+                d = (curCount <= lastCount ? 0 : ms / (curCount - lastCount));
+                msg += $",ms/req:{ d.ToString("0.00") }";
+
+
+                lastRequestTicks = curRequestTicks;
+                lastCount = curCount;
+                lastTime = curTime;
+                return msg;
+            }
+            return msg;
+        }
+    }
+}

+ 24 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryServer/DeliveryServer.csproj

@@ -0,0 +1,24 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\Ipc\Sers.CL.Ipc.NamedPipe\Sers.CL.Ipc.NamedPipe.csproj" />
+    <ProjectReference Include="..\..\..\Ipc\Sers.CL.Ipc.SharedMemory\Sers.CL.Ipc.SharedMemory.csproj" />
+    <ProjectReference Include="..\..\..\Socket\Sers.CL.Socket.Iocp\Sers.CL.Socket.Iocp.csproj" />
+    <ProjectReference Include="..\..\..\Socket\Sers.CL.Socket.ThreadWait\Sers.CL.Socket.ThreadWait.csproj" />
+    <ProjectReference Include="..\..\..\WebSocket\Sers.CL.WebSocket\Sers.CL.WebSocket.csproj" />
+    <ProjectReference Include="..\..\..\Zmq\FullDuplex\Sers.CL.Zmq.FullDuplex\Sers.CL.Zmq.FullDuplex.csproj" />
+    <ProjectReference Include="..\..\..\Zmq\ThreadWait\Sers.CL.ClrZmq.ThreadWait\Sers.CL.ClrZmq.ThreadWait.csproj" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <None Update="StartConsole.bat">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
+</Project>

+ 4 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryServer/DeliveryTest.csproj

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup />
+</Project>

+ 80 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryServer/Program.cs

@@ -0,0 +1,80 @@
+using CLServer.Statistics;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using Vit.Core.Module.Log;
+
+namespace DeliveryTest
+{
+    class Program
+    {
+
+        static StatisticsQpsInfo qpsInfo = new StatisticsQpsInfo();
+        static void Main(string[] args)
+        {
+            Logger.OnLog = (level, msg) => { Console.Write("[" + level + "]" + msg); };
+            try
+            {
+
+                if (args != null && args.Length > 0)
+                {
+                    int.TryParse(args[0], out port);
+                }
+
+
+                qpsInfo.Start("Msg");
+
+                StartServer();
+
+
+                while (true)
+                {
+                    Thread.Sleep(5000);
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex);
+            }
+        }
+
+        static int port = 4501;
+
+
+        static void StartServer()
+        {
+            var server = new Sers.CL.Socket.Iocp.DeliveryServer();
+            server.port = port;
+
+            //var server = new Sers.CL.WebSocket.DeliveryServer();
+            //var server = new Sers.CL.ClrZmq.ThreadWait.DeliveryServer();
+            //var server = new Sers.CL.Ipc.SharedMemory.DeliveryServer();
+            //var server = new Sers.CL.Zmq.FullDuplex.DeliveryServer();
+            //var server = new Sers.CL.Ipc.NamedPipe.DeliveryServer();
+
+            server.Conn_OnConnected = (conn) =>
+            {
+                Logger.Info("Conn_OnConnected");
+
+                conn.OnGetFrame = (conn_, data) =>
+                {
+                    qpsInfo.IncrementRequest();
+
+                    //data[0]++;
+                    data[1] = 5;
+                    var byteData = new List<ArraySegment<byte>>() { data };
+
+                    conn_.SendFrameAsync(byteData);
+                };
+            };
+
+
+            server.Start();
+
+        }
+
+
+
+
+    }
+}

+ 15 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryServer/Properties/PublishProfiles/FolderProfile.pubxml

@@ -0,0 +1,15 @@
+<?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.1</TargetFramework>
+    <PublishDir>bin\DeliveryServer</PublishDir>
+    <SelfContained>false</SelfContained>
+    <_IsPortable>true</_IsPortable>
+  </PropertyGroup>
+</Project>

+ 9 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryServer/StartConsole.bat

@@ -0,0 +1,9 @@
+
+:: dotnet DeliveryServer.dll port
+:: dotnet DeliveryServer.dll 4501
+
+dotnet DeliveryServer.dll
+pause
+
+
+ 

+ 111 - 0
dotnet/Library/Sers/Sers.CL/Test/MessageDelivery/DeliveryServer/Statistics/StatisticsQpsInfo.cs

@@ -0,0 +1,111 @@
+/// v3
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace CLServer.Statistics
+{
+    public class StatisticsQpsInfo
+    {
+        //public static StatisQpsInfo Instance = new StatisQpsInfo();
+
+
+        string name = "";
+
+
+        DateTime? startTime;
+
+        bool finished = false;
+        public void Start(string name)
+        {
+            this.name += name;
+            finished = false;
+            startTime = DateTime.Now;
+            Console.WriteLine("¿ªÊ¼");
+
+            Task.Run(() => {
+
+                while (!finished)
+                {
+                    Console.WriteLine(ToString());
+                    Thread.Sleep(1000);
+                }
+
+            });
+
+
+        }
+        public void Stop()
+        {
+            finished = true;
+            Console.WriteLine("½áÊø");
+            Console.WriteLine(ToString());
+        }
+
+        public int RequestCount = 0;
+        public void IncrementRequest() => Interlocked.Increment(ref RequestCount);
+
+        public long RequestTicks = 0;
+        public void IncrementRequestTicks(long value) => Interlocked.Add(ref RequestTicks, value);
+
+
+        public int ErrorCount = 0;
+        public void IncrementError() => Interlocked.Increment(ref ErrorCount);
+
+
+        long lastRequestTicks = 0;
+        int lastCount = 0;
+        DateTime lastTime;
+        public override string ToString()
+        {
+            var curCount = RequestCount;
+            var curRequestTicks = RequestTicks;
+
+            var msg = $"[{name}]ReqCount: {curCount}";
+
+            double d;
+
+            if (curCount > 0)
+            {
+                d = ErrorCount * 100.0 / curCount;
+                msg += $",error:{ErrorCount}({d.ToString("0.00")}%)";
+            }
+            if (startTime.HasValue)
+            {
+                if (lastCount == 0)
+                {
+                    lastTime = startTime.Value;
+                }
+                var curTime = DateTime.Now;
+
+                //sum
+                var ms = (curTime - startTime.Value).TotalMilliseconds;
+                d =  curCount / ms * 1000;
+                msg += $",qps:{ d.ToString("0.00") }";
+
+                ms = 1.0 * curRequestTicks / TimeSpan.TicksPerMillisecond;
+                d = (curCount <= 0 ? 0 : ms / curCount);
+                msg += $",ms/req:{ d.ToString("0.00") }";
+
+
+                //cur
+                msg += $",------Cur";                
+                msg += $",ReqCount: {curCount}";
+                ms = (curTime - lastTime).TotalMilliseconds;
+                d = (curCount - lastCount) / ms * 1000;
+                msg += $",qps:{ d.ToString("0.00")  }";
+                ms = 1.0 * (curRequestTicks - lastRequestTicks) / TimeSpan.TicksPerMillisecond;
+                d = (curCount <= lastCount ? 0 : ms / (curCount - lastCount));
+                msg += $",ms/req:{ d.ToString("0.00") }";
+
+
+                lastRequestTicks = curRequestTicks;
+                lastCount = curCount;
+                lastTime = curTime;
+                return msg;
+            }
+            return msg;
+        }
+    }
+}

+ 22 - 0
dotnet/Sers.sln

@@ -163,6 +163,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sers.Core.Module.Rpc.MsTest
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sers.Core.MsTest", "Library\Sers\Sers.Core\Test\Sers.Core.MsTest\Sers.Core.MsTest.csproj", "{B21B5462-1244-48BE-BA6B-B46F69DD9F66}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeliveryClient", "Library\Sers\Sers.CL\Test\MessageDelivery\DeliveryClient\DeliveryClient.csproj", "{72525D02-A366-4470-8BFB-797F26C3A6A7}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeliveryServer", "Library\Sers\Sers.CL\Test\MessageDelivery\DeliveryServer\DeliveryServer.csproj", "{67733A68-0505-4977-BC52-8200D536005B}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -515,6 +519,22 @@ Global
 		{B21B5462-1244-48BE-BA6B-B46F69DD9F66}.Release|Any CPU.Build.0 = Release|Any CPU
 		{B21B5462-1244-48BE-BA6B-B46F69DD9F66}.Release|x86.ActiveCfg = Release|Any CPU
 		{B21B5462-1244-48BE-BA6B-B46F69DD9F66}.Release|x86.Build.0 = Release|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Debug|x86.Build.0 = Debug|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Release|Any CPU.Build.0 = Release|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Release|x86.ActiveCfg = Release|Any CPU
+		{72525D02-A366-4470-8BFB-797F26C3A6A7}.Release|x86.Build.0 = Release|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Debug|x86.Build.0 = Debug|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Release|x86.ActiveCfg = Release|Any CPU
+		{67733A68-0505-4977-BC52-8200D536005B}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -596,6 +616,8 @@ Global
 		{6DF6153E-DEAD-43C8-852D-828619CE51EA} = {37633A5F-54B5-4179-8BCD-B7B422B4857C}
 		{ECFF0AAD-0795-4040-921C-944EC52A9F0D} = {37633A5F-54B5-4179-8BCD-B7B422B4857C}
 		{B21B5462-1244-48BE-BA6B-B46F69DD9F66} = {37633A5F-54B5-4179-8BCD-B7B422B4857C}
+		{72525D02-A366-4470-8BFB-797F26C3A6A7} = {4E874DC3-754A-4FE2-92B5-98ADFF74B369}
+		{67733A68-0505-4977-BC52-8200D536005B} = {4E874DC3-754A-4FE2-92B5-98ADFF74B369}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {C7DA16E3-9949-49FA-B0B4-F830636DE60F}