lith 4 gadi atpakaļ
vecāks
revīzija
5da886d556

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/Consumer_BlockingCollection.cs

@@ -60,8 +60,8 @@ namespace Sers.Core.Util.Consumer
                     #region Process                        
                     while (true)
                     {
-                        var msgFrame = queue.Take();
-                        processor(msgFrame);
+                        //var msgFrame = queue.Take();
+                        processor(queue.Take());
                     }
                     #endregion
                 }

+ 14 - 40
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/LocalApi/Extensions/LocalApiMngExtensions.cs

@@ -1,12 +1,7 @@
 using System;
 using System.Runtime.CompilerServices;
-using System.Threading;
-
-using Sers.Core.CL.MessageOrganize;
 using Sers.Core.Module.Api.LocalApi;
 using Sers.Core.Module.Message;
-
-using Vit.Core.Util.Threading;
 using Vit.Extensions;
 
 namespace Sers.Core.Module.LocalApi.MsTest.LocalApi.Extensions
@@ -14,58 +9,37 @@ namespace Sers.Core.Module.LocalApi.MsTest.LocalApi.Extensions
 
     public static class LocalApiMngExtensions
     {
-        #region CallLocalApi
-
-
-        #region static curAutoResetEvent      
-        public static AutoResetEvent curAutoResetEvent =>
-            _curAutoResetEvent.Value ?? (_curAutoResetEvent.Value = new AutoResetEvent(false));
-
-
- 
-
-        static System.Threading.ThreadLocal<AutoResetEvent> _curAutoResetEvent = new System.Threading.ThreadLocal<AutoResetEvent>();
-        #endregion
-
+        #region CallLocalApi 
 
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static ArraySegment<byte> CallLocalApi(this LocalApiService data,string route, Object arg)
+        public static void CallLocalApi(this LocalApiService data,string route, Object arg,Action<ApiMessage> onSuc)
         {
-            var apiRequestMessage = new ApiMessage().InitAsApiRequestMessage(route, arg);
-
-            ApiMessage apiReplyMessage=null;
+            var apiRequestMessage = new ApiMessage().InitAsApiRequestMessage(route, arg);                   
 
-            AutoResetEvent mEvent = curAutoResetEvent;
-            mEvent.Reset();
-
-            data.CallApiAsync(null, apiRequestMessage, (sender,_apiReplyMessage)=> 
-            {
-                apiReplyMessage = _apiReplyMessage;
-                mEvent?.Set();
+            data.CallApiAsync(null, apiRequestMessage, (sender, apiReplyMessage) => 
+            {               
+                onSuc(apiReplyMessage);
             });
 
-  
-            //TODO
-            int millisecondsTimeout = 60000;
-            mEvent.WaitOne(millisecondsTimeout);
-            mEvent = null;
-
-            return apiReplyMessage.value_OriData;
         }
 
 
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static ReturnType CallLocalApi<ReturnType>(this LocalApiService data, string route, Object arg)
+        public static void CallLocalApi<ReturnType>(this LocalApiService data, string route, Object arg,Action<ReturnType> onSuc)
         {
-            var returnValue = data.CallLocalApi(route, arg);
-            return returnValue.DeserializeFromArraySegmentByte<ReturnType>();
+            data.CallLocalApi(route, arg, replyMessage =>
+              {
+                  var returnBytes = replyMessage.value_OriData;
+                  var returnValue = returnBytes.DeserializeFromArraySegmentByte<ReturnType>();
+                  onSuc(returnValue);
+              });
         }
 
         #endregion
 
-      
+
 
     }
 }

+ 16 - 23
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Module.LocalApi.Qps/LocalApi/LocalApiTest.cs

@@ -1,9 +1,8 @@
 using System;
-using System.Threading.Tasks;
 using Statistics;
 using Sers.Core.Module.Api.LocalApi;
 using Sers.Core.Module.LocalApi.MsTest.LocalApi.Extensions;
- 
+
 
 namespace Sers.Core.Module.LocalApi.MsTest.LocalApi
 {
@@ -32,34 +31,28 @@ namespace Sers.Core.Module.LocalApi.MsTest.LocalApi
         public static void StartThread()
         {
             QpsData qpsInfo = new QpsData(statisticsQps);
-            Task.Run(() =>
-            {
-
-                while (true)
-                {
-                    try
-                    {
-                        for (var t = 0; t < 1000; t++)
-                        {                       
 
-                            object returnValue = localApiService.CallLocalApi<string>("/a",null);
+            int t = 0;
 
-                            //string route = "/Test/api/GetDeviceGuidList";
-                            //string arg = "asfsdf";
-                            //object argValue = new { arg };
+            Action<string> callApi = null;
 
-                            //object returnValue = localApiService.CallLocalApi<string>(route, argValue);
-                        }
+            callApi = reply =>{
 
-                        qpsInfo.RequestCount++;
-                    }
-                    catch (Exception ex)
-                    {
-                    }
+                t++;
+                if (t >= 1000)
+                {
+                    t = 0;
+                    qpsInfo.RequestCount++;
                 }
+                
+                //string route = "/Test/api/GetDeviceGuidList";
+                //string arg = "asfsdf";
+                //object argValue = new { arg };
 
-            });
+                localApiService.CallLocalApi<string>("/a", null, callApi);
+            };
 
+            callApi(null);
         }
 
     }

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

@@ -8,16 +8,16 @@ namespace DeliveryTest
     class Program
     {
         /// <summary>
-        ///          qps
-        ///   4 4   15-16万
+        ///             qps
+        ///   16 16   25-26万 (2021-03-23)
         /// </summary>
         /// <param name="args"></param>
         static void Main(string[] args)
         {
             try
             {
-                int requestTreadCount = 4;
-                LocalApiTest.workThreadCount = 4;
+                int requestTreadCount = 16;
+                LocalApiTest.workThreadCount = 16;
 
                 if (args != null)
                 {

+ 7 - 0
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Common/CommonHelp.cs

@@ -70,6 +70,13 @@ Debug.WriteLine(guid.ToString("X"));//{0x1f3c6041,0xc68f,0x4ab3,{0xae,0x19,0xf6,
         }
 
 
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public static long NewSnowflakeGuidLong()
+        {
+            return Snowflake.GetId();           
+        }
+
+
         /// <summary>
         /// MD5加密字符串(32位大写)
         /// </summary>

+ 16 - 15
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Guid/FastGuid.cs

@@ -11,30 +11,29 @@ namespace Vit.Core.Util.Guid
         // 64 bit
         // 8 byte   
 
+        //  1 byte        1 byte           4 byte                2 byte             
+        //  机器ID        数据ID            时间                  自增             
+        // machineId    dataCenterId       seconds                curId
+        private static int machineId= CommonHelp.Random(0, 127);//机器ID
+        private static int dataCenterId = CommonHelp.Random(0, 255);//数据ID
+        //private static int seconds;
+        private static int curId=0;
 
-        private static long machineId= CommonHelp.Random(0, 127);//机器ID
-        private static long datacenterId = CommonHelp.Random(0, 255);//数据ID
-         
 
-         
-       
+
+        static DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
 
         /// <summary>
         /// 生成当前时间戳
         /// </summary>
         /// <returns>毫秒</returns>
-        private static long GetTimestamp()
-        {
-            return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
-        }
-
-        private static long curGuid;
-        static FastGuid() 
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        private static double GetTimestamp()
         {
-            curGuid = ((machineId << 8) | datacenterId) << 48;
-            curGuid = curGuid | GetTimestamp();
+            return  (DateTime.UtcNow - start).TotalMilliseconds;
         }
 
+    
 
 
         /// <summary>
@@ -44,7 +43,9 @@ namespace Vit.Core.Util.Guid
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
         public static long GetGuid()
         {
-            return Interlocked.Increment(ref curGuid);             
+            int seconds = (int)(long)GetTimestamp();
+            int id= Interlocked.Increment(ref curId);
+            return (((((machineId << 8) | dataCenterId) << 32) | seconds) << 8) | id;
         }
 
     }

+ 1 - 1
dotnet/todo.txt

@@ -1,7 +1,7 @@
 CUR:
 
 对象缓存是否弃用
-Guid生成算法 效率低
+
 
 -----------------------------------------
 百万优化计划