lith 4 年 前
コミット
1c20e632c4

+ 40 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/LocalApi/Controllers/DemoController.cs

@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+using System.Linq;
+using Sers.SersLoader;
+using Vit.Core.Util.ComponentModel.Api;
+
+namespace Sers.Core.Module.LocalApi.MsTest.LocalApi.Controllers
+{
+    [SsStationName("Test")]
+    public class DemoController : IApiController
+    {
+
+        public class Arg
+        {
+            public string name { get; set; }
+        }
+
+
+       
+        [SsRoute("api/GetDeviceGuidList")]
+        public string GetDeviceGuidList(string arg)
+        {
+            return arg+ "Test";
+        }
+
+
+        public class GetListArg
+        {
+            public string[] arr;
+        }
+
+        [SsRoute("api/getList")]
+        public List<string> GetList(GetListArg arg)
+        {
+            var ret = from i in arg.arr select i + "_1";
+            return ret.ToList();
+        }
+
+
+    }
+}

+ 53 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/LocalApi/Extensions/LocalApiMngExtensions.cs

@@ -0,0 +1,53 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using Sers.Core.Module.Api.LocalApi;
+using Sers.Core.Module.Message;
+using Vit.Extensions;
+
+namespace Sers.Core.Module.LocalApi.MsTest.LocalApi.Extensions
+{
+
+    public static class LocalApiMngExtensions
+    {
+        #region CallLocalApi
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public static ArraySegment<byte> CallLocalApi(this LocalApiService data,string route, Object arg)
+        {
+            var apiRequestMessage = new ApiMessage().InitAsApiRequestMessage(route, arg);
+
+            ApiMessage apiReplyMessage=null;
+
+            AutoResetEvent mEvent = new AutoResetEvent(false);
+            mEvent.Reset();
+
+            data.CallApiAsync(null, apiRequestMessage, (sender,_apiReplyMessage)=> 
+            {
+                apiReplyMessage = _apiReplyMessage;
+                mEvent?.Set();
+            });
+
+  
+            //TODO
+            int millisecondsTimeout = 60000;
+            mEvent.WaitOne(millisecondsTimeout);
+
+            return apiReplyMessage.value_OriData;
+        }
+
+
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public static ReturnType CallLocalApi<ReturnType>(this LocalApiService data, string route, Object arg)
+        {
+            var returnValue = data.CallLocalApi(route, arg);
+            return returnValue.DeserializeFromArraySegmentByte<ReturnType>();
+        }
+
+        #endregion
+
+      
+
+    }
+}

+ 62 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/LocalApi/LocalApiTest.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Threading.Tasks;
+using CLServer.Statistics;
+using Sers.Core.Module.Api.LocalApi;
+using Sers.Core.Module.LocalApi.MsTest.LocalApi.Extensions;
+
+namespace Sers.Core.Module.LocalApi.MsTest.LocalApi
+{
+
+    public class LocalApiTest
+    {
+        static StatisticsQpsInfo qpsInfo = new StatisticsQpsInfo();
+        static LocalApiService localApiService;
+        static LocalApiTest()
+        {
+            //(x.1)构建
+            localApiService = new LocalApiService() { workThreadCount = 4 };
+            localApiService.LoadSersApi(typeof(LocalApiTest).Assembly);
+
+            localApiService.Start();
+
+
+            qpsInfo.Start("Msg");
+
+        }
+
+
+
+        public static void StartThread()
+        {
+            Task.Run(() =>
+            {
+
+                while (true)
+                {
+                    try
+                    {
+                        for (var t = 0; t < 10000; t++)
+                        {
+                             
+
+                            //(x.2)调用
+                            string route = "/Test/api/GetDeviceGuidList";
+                            string arg = "asfsdf";
+                            object argValue = new { arg };
+
+                            object returnValue = localApiService.CallLocalApi<string>(route, argValue);
+                        }
+
+                        qpsInfo.IncrementRequest();
+                    }
+                    catch (Exception ex)
+                    {
+                    }
+                }
+
+            });
+
+        }
+
+    }
+}

+ 38 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/Program.cs

@@ -0,0 +1,38 @@
+using Sers.Core.Module.LocalApi.MsTest.LocalApi;
+using System;
+using System.Threading;
+using Vit.Core.Module.Log;
+
+namespace DeliveryTest
+{
+    class Program
+    {
+ 
+        static void Main(string[] args)
+        {
+            try
+            {
+                for (var t = 0; t < 4; t++)
+                {
+                    LocalApiTest.StartThread();
+                }
+
+
+                while (true)
+                {
+                    Thread.Sleep(5000);
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex);
+            }
+        }
+
+         
+
+
+
+
+    }
+}

+ 15 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/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\Publish</PublishDir>
+    <SelfContained>false</SelfContained>
+    <_IsPortable>true</_IsPortable>
+  </PropertyGroup>
+</Project>

+ 20 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/Sers.Core.Module.LocalApi.Qps.csproj

@@ -0,0 +1,20 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\..\Sers.Core\Sers.Core.csproj" />
+  </ItemGroup>
+
+ 
+
+  <ItemGroup>
+    <None Update="StartConsole.bat">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
+</Project>

+ 7 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/StartConsole.bat

@@ -0,0 +1,7 @@
+
+ 
+dotnet Sers.Core.Module.LocalApi.Qps.dll
+pause
+
+
+ 

+ 111 - 0
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/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;
+        }
+    }
+}

+ 11 - 0
dotnet/Sers.sln

@@ -169,6 +169,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CmClient", "Library\Sers\Se
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CmServer", "Library\Sers\Sers.CL\Test\CommunicationManage\CmServer\CmServer.csproj", "{EBB905C2-7D58-4A4A-A7F7-2171DB1724AB}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sers.Core.Module.LocalApi.Qps", "Library\Sers\Sers.Core\Test\Sers.Core.Module.LocalApi.Qps\Sers.Core.Module.LocalApi.Qps.csproj", "{A2E07766-8290-446D-AD4E-D8277687D4C0}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -545,6 +547,14 @@ Global
 		{EBB905C2-7D58-4A4A-A7F7-2171DB1724AB}.Release|Any CPU.Build.0 = Release|Any CPU
 		{EBB905C2-7D58-4A4A-A7F7-2171DB1724AB}.Release|x86.ActiveCfg = Release|Any CPU
 		{EBB905C2-7D58-4A4A-A7F7-2171DB1724AB}.Release|x86.Build.0 = Release|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Debug|x86.Build.0 = Debug|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Release|x86.ActiveCfg = Release|Any CPU
+		{A2E07766-8290-446D-AD4E-D8277687D4C0}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -629,6 +639,7 @@ Global
 		{B45BBA33-E315-409E-B44E-97FA40B33BFB} = {37633A5F-54B5-4179-8BCD-B7B422B4857C}
 		{1B6172BF-405A-4752-B0A3-040F2E951F2A} = {0EF01864-BC8C-4C94-8F83-5BB6CC4FECB8}
 		{EBB905C2-7D58-4A4A-A7F7-2171DB1724AB} = {0EF01864-BC8C-4C94-8F83-5BB6CC4FECB8}
+		{A2E07766-8290-446D-AD4E-D8277687D4C0} = {37633A5F-54B5-4179-8BCD-B7B422B4857C}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {C7DA16E3-9949-49FA-B0B4-F830636DE60F}