예제 #1
0
        protected override void OnHandler(ParameterHandlerInfo info)
        {
            Core.Log.Warning("Starting COMPRESSOR TEST");

            Core.Log.InfoBasic("Generating Random Bytes");
            var rnd   = new Random();
            var bytes = new byte[ushort.MaxValue * 2000];

            for (var i = 0; i < bytes.Length; i++)
            {
                bytes[i] = (byte)rnd.Next(50, 60);
            }
            Core.Log.InfoBasic("Total Bytes = {0}", bytes.Length.ToReadableBytes());

            Core.Log.InfoBasic("Creating GZip Compressor");
            var gzipCompressor = CompressorManager.GetByEncodingType("gzip");

            using (Watch.Create("GZIP COMPRESSOR"))
            {
                var gzipBytes = gzipCompressor.Compress(bytes);
                Core.Log.InfoBasic("Total GZIP Bytes = {0} - {1:0.000}%", gzipBytes.Count.ToReadableBytes(), ((double)gzipBytes.Count * 100) / bytes.Length);
            }

            Core.Log.InfoBasic("Creating Deflate Compressor");
            var deflateCompressor = CompressorManager.GetByEncodingType("deflate");

            using (Watch.Create("DEFLATE COMPRESSOR"))
            {
                var deflateBytes = deflateCompressor.Compress(bytes);
                Core.Log.InfoBasic("Total DEFLATE Bytes = {0} - {1:0.000}%", deflateBytes.Count.ToReadableBytes(), ((double)deflateBytes.Count * 100) / bytes.Length);
            }
        }
예제 #2
0
        private static void SerializerProcess(string name, object value, Type valueType, int times, ISerializer serializer, MemoryStream memStream)
        {
            double totalValue;

            memStream.Position = 0;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Thread.Sleep(1500);
            using (var w = Watch.Create(name + " SERIALIZER"))
            {
                for (var i = 0; i < times; i++)
                {
                    serializer.Serialize(value, valueType, memStream);
                    memStream.Position = 0;
                }
                totalValue = w.GlobalElapsedMilliseconds;
            }
            Core.Log.InfoBasic("\t" + name + " SERIALIZER - Average Time: {0}ms", totalValue / times);
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Thread.Sleep(1500);
            using (var w = Watch.Create(name + " DESERIALIZER"))
            {
                for (var i = 0; i < times; i++)
                {
                    serializer.Deserialize(memStream, valueType);
                    memStream.Position = 0;
                }
                totalValue = w.GlobalElapsedMilliseconds;
            }
            Core.Log.InfoBasic("\t" + name + " DESERIALIZER - Average Time: {0}ms", totalValue / times);
            Thread.Sleep(1000);
            Core.Log.WriteEmptyLine();
        }
예제 #3
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            Core.DebugMode = false;
            Core.Log.Warning("Starting CACHE Async TEST");

            var cacheService = new TestCacheService();

            cacheService.OnStart(null);

            using (var cachePool = new CacheClientPoolAsync("Pool Test")
            {
                Serializer = GlobalSerializer, ForceAtLeastOneNetworkItemEnabled = false, WriteNetworkItemsToMemoryOnGet = true
            })
            {
                var cacheClient = await CacheClientProxy.GetClientAsync(new DefaultTransportClient("127.0.0.1", 20051, 3, GlobalSerializer)).ConfigureAwait(false);

                cachePool.Add("localhost:20051", cacheClient, StorageItemMode.ReadAndWrite);
                //cachePool.Add("memory", new LRU2QStorage(2000), StorageItemMode.ReadAndWrite);

                var res = await cachePool.GetMetaAsync("metaValue").ConfigureAwait(false);

                await cachePool.GetKeysAsync().ConfigureAwait(false);

                using (var watch = Watch.Create("GetKeysAsync"))
                {
                    for (var i = 0; i < 1000; i++)
                    {
                        await cachePool.GetKeysAsync().ConfigureAwait(false);
                    }
                    Core.Log.InfoBasic("Time Per Item: {0}ms", watch.GlobalElapsedMilliseconds / 1000);
                }

                Console.ReadLine();

                using (var watch = Watch.Create("Get And Sets"))
                {
                    for (var i = 0; i < 5000; i++)
                    {
                        var key = "test-" + (i % 500);
                        await cachePool.GetAsync(key).ConfigureAwait(false);

                        await cachePool.SetAsync(key, "bla bla bla bla bla").ConfigureAwait(false);
                    }
                    Core.Log.InfoBasic("Time Per Item: {0}ms", watch.GlobalElapsedMilliseconds / 5000);
                }
            }

            cacheService.OnStop();
            Console.ReadLine();
        }
예제 #4
0
        private static void RawTest(MQPairConfig mqConfig)
        {
            using (var mqServer = mqConfig.GetRawServer())
            {
                var byteRequest  = new byte[] { 0x21, 0x22, 0x23, 0x24, 0x25, 0x30, 0x31, 0x32, 0x33, 0x34 };
                var byteResponse = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11, 0x12, 0x13, 0x14 };
                mqServer.RequestReceived += (s, e) =>
                {
                    e.Response = byteResponse;
                    return(Task.CompletedTask);
                };
                mqServer.StartListeners();

                using (var mqClient = mqConfig.GetRawClient())
                {
                    var totalQ = 5000;

                    #region Sync Mode
                    Core.Log.Warning("RAW Sync Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times"))
                    {
                        for (var i = 0; i < totalQ; i++)
                        {
                            var response = mqClient.SendAndReceiveAsync(byteRequest).WaitAndResults();
                        }
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion

                    #region Parallel Mode
                    Core.Log.Warning("RAW Parallel Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times"))
                    {
                        Task.WaitAll(
                            Enumerable.Range(0, totalQ).Select((i, vTuple) => (Task)vTuple.mqClient.SendAndReceiveAsync(vTuple.byteRequest), (mqClient, byteRequest)).ToArray()
                            );
                        //Parallel.For(0, totalQ, i =>
                        //{
                        //    var response = mqClient.SendAndReceiveAsync(byteRequest).WaitAndResults();
                        //});
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion
                }
            }
        }
예제 #5
0
        private static void NormalTest(MQPairConfig mqConfig)
        {
            using (var mqServer = mqConfig.GetServer())
            {
                mqServer.RequestReceived += (s, e) =>
                {
                    e.Response.Body = "Bienvenido!!!";
                    return(Task.CompletedTask);
                };
                mqServer.StartListeners();

                using (var mqClient = mqConfig.GetClient())
                {
                    var totalQ = 5000;

                    #region Sync Mode
                    Core.Log.Warning("Sync Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times"))
                    {
                        for (var i = 0; i < totalQ; i++)
                        {
                            var response = mqClient.SendAndReceiveAsync <string>("Hola mundo").WaitAndResults();
                        }
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion

                    #region Parallel Mode
                    Core.Log.Warning("Parallel Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times"))
                    {
                        Task.WaitAll(
                            Enumerable.Range(0, totalQ).Select((i, mc) => (Task)mc.SendAndReceiveAsync <string>("Hola mundo"), mqClient).ToArray()
                            );
                        //Parallel.For(0, totalQ, i =>
                        //{
                        //    var response = mqClient.SendAndReceiveAsync<string>("Hola mundo").WaitAndResults();
                        //});
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion
                }
            }
        }
예제 #6
0
        protected override void OnHandler(ParameterHandlerInfo info)
        {
            Core.Log.Warning("Starting String Hash Test");

            var  str           = "Lorem ipsum dolor sit amet";
            int  number        = 10_000_000;
            int  normalHash    = 0;
            uint superFastHash = 0;
            uint murmurhash2   = 0;
            uint murmurhash3   = 0;

            str.GetHashCode();
            str.GetSuperFastHash();
            str.GetMurmurHash2();
            str.GetMurmurHash3();
            using (Watch.Create("Normal Hash - GetHashCode()"))
            {
                for (var i = 0; i < number; i++)
                {
                    normalHash = (str + i).GetHashCode();
                }
            }
            using (Watch.Create("Superfast Hash - GetSuperFastHash()"))
            {
                for (var i = 0; i < number; i++)
                {
                    superFastHash = (str + i).GetSuperFastHash();
                }
            }
            using (Watch.Create("MurmurHash2 Hash - GetMurmurHash2()"))
            {
                for (var i = 0; i < number; i++)
                {
                    murmurhash2 = (str + i).GetMurmurHash2();
                }
            }
            using (Watch.Create("MurmurHash3 Hash - GetMurmurHash3()"))
            {
                for (var i = 0; i < number; i++)
                {
                    murmurhash3 = (str + i).GetMurmurHash3();
                }
            }
            Core.Log.InfoBasic("Normal Hash: {0}", normalHash);
            Core.Log.InfoBasic("Superfast Hash: {0}", superFastHash);
            Core.Log.InfoBasic("MurmurHash2 Hash: {0}", murmurhash2);
            Core.Log.InfoBasic("MurmurHash3 Hash: {0}", murmurhash3);
        }
예제 #7
0
        protected override void OnHandler(ParameterHandlerInfo info)
        {
            var n2obj1 = Core.Injector.New <IInjectTestA>("Default");
            var n2obj2 = Core.Injector.New <IInjectTestB>("Default");

            var instance1 = Core.Injector.New <IInjectTestA>("Default");
            var instance2 = Core.Injector.New <IInjectTestA>("Default");

            var times = 10_000_000;

            Core.Log.InfoBasic("Injector Number of times: {0}", times);

            using (var w = Watch.Create("Injector Object A"))
                for (var i = 0; i < times; i++)
                {
                    Core.Injector.New <IInjectTestA>("Default");
                }

            using (var w = Watch.Create("Injector Object B"))
                for (var i = 0; i < times; i++)
                {
                    Core.Injector.New <IInjectTestB>("Default");
                }


            if (instance1 != instance2)
            {
                Core.Log.InfoBasic("The instance are differents. OK");
            }
            else
            {
                Core.Log.Error("The instance is the same. Error");
            }

            var guid1 = instance1.GetGuid();
            var guid2 = instance2.GetGuid();

            if (guid1 != guid2)
            {
                Core.Log.InfoBasic("The Guid are differents. OK");
            }
            else
            {
                Core.Log.Error("The Guid are the same. Error");
            }
        }
예제 #8
0
        private static async Task NormalTest(MQPairConfig mqConfig)
        {
            using (var mqServer = mqConfig.GetServer())
            {
                mqServer.RequestReceived += (s, e) =>
                {
                    //Core.Trace.Write("Grupo", e.Request.CorrelationId.ToString(), e.Request.Body);
                    e.Response.Body = new SerializedObject("Bienvenido!!!");
                    return(Task.CompletedTask);
                };
                mqServer.StartListeners();

                using (var mqClient = mqConfig.GetClient())
                {
                    var totalQ = 50000;

                    #region Sync Mode
                    Core.Log.Warning("Sync Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times"))
                    {
                        for (var i = 0; i < totalQ; i++)
                        {
                            var response = await mqClient.SendAndReceiveAsync <string>("Hola mundo").ConfigureAwait(false);
                        }
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion

                    #region Parallel Mode
                    Core.Log.Warning("Parallel Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times"))
                    {
                        await Task.WhenAll(
                            Enumerable.Range(0, totalQ).Select((i, mqc) => (Task)mqc.SendAndReceiveAsync <string>("Hola mundo"), mqClient).ToArray()
                            ).ConfigureAwait(false);

                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion
                }
            }
        }
예제 #9
0
        protected override void OnHandler(ParameterHandlerInfo info)
        {
            Core.Log.Warning("Starting SQL Server Test");

            IDalCity dalCity = new DalCity();

            using (Watch.Create("Sync Test"))
            {
                for (var i = 0; i < 30; i++)
                {
                    using (var w = Watch.Create())
                    {
                        var values = dalCity.GetAll();
                        w.Tap("GetAll");
                        var arr = values.ToArray();
                        w.Tap($"Entity Binding: {arr.Length} items");
                    }
                }
            }


            Console.ReadLine();

            Task.Run(async() =>
            {
                using (Watch.Create("Async Test"))
                {
                    for (var i = 0; i < 30; i++)
                    {
                        using (var w = Watch.Create())
                        {
                            var values = await dalCity.GetAllAsync().ConfigureAwait(false);
                            w.Tap("GetAll");
                            var arr = values.ToArray();
                            w.Tap($"Entity Binding: {arr.Length} items");
                        }
                    }
                }
            });

            Console.ReadLine();
        }
예제 #10
0
        private static void ApplyTest(IStorage fSto)
        {
            var sobj = new SerializedObject("Esto es un ejemplo del hola mundo");

            using (var w = Watch.Create("Cache GET"))
            {
                Parallel.For(0, 25000, i => fSto.Get("Tony - " + i));
                Core.Log.InfoBasic("Time per item: {0}ms", w.GlobalElapsedMilliseconds / 10000);
            }
            using (var w = Watch.Create("Cache SET"))
            {
                Parallel.For(0, 25000, i =>
                {
                    fSto.Set("Tony - " + i, sobj);
                });
                Core.Log.InfoBasic("Time per item: {0}ms", w.GlobalElapsedMilliseconds / 10000);
            }
            using (var w = Watch.Create("Cache GET"))
            {
                Parallel.For(0, 25000, i => fSto.Get("Tony - " + i));
                Core.Log.InfoBasic("Time per item: {0}ms", w.GlobalElapsedMilliseconds / 10000);
            }
        }
예제 #11
0
        private static void NormalTest(MQPairConfig mqConfig)
        {
            using (var mqServer = mqConfig.GetServer())
            {
                mqServer.RequestReceived += (s, e) =>
                {
                    //Core.Log.Warning("Waiting...");
                    //try
                    //{
                    //    await Task.Delay(int.MaxValue, e.ProcessResponseTimeoutCancellationToken);
                    //}
                    //catch { }
                    //Core.Log.Warning("Cancelled.");
                    //Core.Log.InfoBasic("Received");
                    e.Response.Body = new SerializedObject("Bienvenido!!!");
                    return(Task.CompletedTask);
                };
                mqServer.StartListeners();

                using (var mqClient = mqConfig.GetClient())
                {
                    var totalQ = 50000;

                    #region Sync Mode
                    Core.Log.Warning("Sync Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times"))
                    {
                        for (var i = 0; i < totalQ; i++)
                        {
                            var response = mqClient.SendAndReceiveAsync <string>("Hola mundo").WaitAsync();
                        }
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion

                    totalQ = 50000;

                    #region Parallel Mode
                    Core.Log.Warning("Parallel Mode Test, using Unique Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times"))
                    {
                        var oldContext = Core.ContextGroupName;
                        Task.WaitAll(
                            Enumerable.Range(0, totalQ).Select((i, mc) =>
                        {
                            Core.ContextGroupName = "Message: " + i;
                            return((Task)mc.SendAndReceiveAsync <string>("Hola mundo"));
                        }
                                                               , mqClient).ToArray());
                        Core.ContextGroupName = oldContext;

                        //Parallel.For(0, totalQ, i =>
                        //{
                        //    var response = mqClient.SendAndReceiveAsync<string>("Hola mundo").WaitAndResults();
                        //});
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion
                }

                mqConfig.ResponseOptions.ClientReceiverOptions.Parameters["SingleResponseQueue"] = "false";
                using (var mqClient = mqConfig.GetClient())
                {
                    var totalQ = 50000;

                    #region Sync Mode
                    Core.Log.Warning("Sync Mode Test, using Multiple Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Sync Mode for {totalQ} times"))
                    {
                        for (var i = 0; i < totalQ; i++)
                        {
                            var response = mqClient.SendAndReceiveAsync <string>("Hola mundo").WaitAndResults();
                        }
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion

                    #region Parallel Mode
                    Core.Log.Warning("Parallel Mode Test, using Multiple Response Queue");
                    using (var w = Watch.Create($"Hello World Example in Parallel Mode for {totalQ} times"))
                    {
                        Task.WaitAll(
                            Enumerable.Range(0, totalQ).Select((i, mc) => (Task)mc.SendAndReceiveAsync <string>("Hola mundo"), mqClient).ToArray()
                            );
                        //Parallel.For(0, totalQ, i =>
                        //{
                        //    var response = mqClient.SendAndReceiveAsync<string>("Hola mundo").WaitAndResults();
                        //});
                        Core.Log.InfoBasic("Total time: {0}", TimeSpan.FromMilliseconds(w.GlobalElapsedMilliseconds));
                        Core.Log.InfoBasic("Average time in ms: {0}. Press ENTER To Continue.", (w.GlobalElapsedMilliseconds / totalQ));
                    }
                    Console.ReadLine();
                    #endregion
                }
            }
        }
예제 #12
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            var serializer = new NBinarySerializer();
            var service    = new SampleProvider();

            Core.Log.InfoBasic("Setting RPC Server");
            var rpcServer = new RPCServer(new DefaultTransportServer(20050, serializer));

            rpcServer.AddService(typeof(ISampleProvider), service);
            await rpcServer.StartAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("Setting RPC Client");
            var rpcClient = new RPCClient(new DefaultTransportClient("127.0.0.1", 20050, 1, serializer));

            var hClient = await rpcClient.CreateDynamicProxyAsync <ISampleProvider>().ConfigureAwait(false);

            var client = hClient.ActAs <ISampleProvider>();

            double perItemMs;

            try
            {
                var intEnumerable = await client.GetInt().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Core.Log.Write(ex);
            }

            using (var watch = Watch.Create("GetSampleAsync"))
            {
                Sample res;
                for (var i = 0; i < 100000; i++)
                {
                    res = await client.GetSampleAsync().ConfigureAwait(false);
                }
                perItemMs = watch.GlobalElapsedMilliseconds / 100000;
            }
            Core.Log.InfoBasic($"GetSampleAsync per item: {perItemMs}ms");
            Console.ReadLine();

            Core.Log.InfoBasic("DelayTestAsync");
            await client.DelayTestAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("GetSample");
            var sample = client.GetSample();

            Core.Log.InfoBasic("GetSample as Async");
            var sampleSimAsync = ((dynamic)hClient).GetSample2Async().Result;

            Console.ReadLine();

            var pClient = await rpcClient.CreateProxyAsync <SampleProxy>().ConfigureAwait(false);

            using (var watch = Watch.Create("GetSampleAsync"))
            {
                Sample res;
                for (var i = 0; i < 100000; i++)
                {
                    res = await pClient.GetSampleAsync().ConfigureAwait(false);
                }
                perItemMs = watch.GlobalElapsedMilliseconds / 100000;
            }
            Core.Log.InfoBasic($"GetSampleAsync per item: {perItemMs}ms");
            Console.ReadLine();

            Core.Log.InfoBasic("DelayTestAsync");
            await pClient.DelayTestAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("GetSample");
            var sample2 = pClient.GetSample();

            rpcClient.Dispose();
            await rpcServer.StopAsync().ConfigureAwait(false);
        }
예제 #13
0
        protected override void OnHandler(ParameterHandlerInfo info)
        {
            Core.Log.Warning("Starting MEMORY STREAMS TEST");


            Core.Log.WriteEmptyLine();
            Core.Log.InfoBasic("Press Enter to Start RecycleMemoryStream Test.");
            Console.ReadLine();
            var xbuffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            using (Watch.Create("RecycleMemoryStream"))
            {
                for (var m = 0; m < 50000; m++)
                {
                    using (var rms = new RecycleMemoryStream())
                    {
                        for (var x = 0; x < 1; x++)
                        {
                            for (int i = 0; i < 10000; i++)
                            {
                                rms.Write(xbuffer, 0, xbuffer.Length);
                            }
                        }
                        rms.Position = 0;
                        for (var x = 0; x < 10; x++)
                        {
                            for (int i = 0; i < 2000; i++)
                            {
                                var bt = rms.ReadByte();
                            }
                        }
                    }
                }
            }
            Core.Log.WriteEmptyLine();
            Core.Log.InfoBasic("Press Enter to Start MemoryStream Test.");
            Console.ReadLine();
            using (Watch.Create("MemoryStream"))
            {
                for (var m = 0; m < 50000; m++)
                {
                    using (var rms = new MemoryStream())
                    {
                        for (var x = 0; x < 1; x++)
                        {
                            for (var i = 0; i < 10000; i++)
                            {
                                rms.Write(xbuffer, 0, xbuffer.Length);
                            }
                        }
                        rms.Position = 0;
                        for (var x = 0; x < 10; x++)
                        {
                            for (var i = 0; i < 2000; i++)
                            {
                                var bt = rms.ReadByte();
                            }
                        }
                    }
                }
            }



            Core.Log.WriteEmptyLine();
            Core.Log.InfoBasic("Press Enter to Start CircularBufferStream Test. Press Enter Again to finish the test.");
            Console.ReadLine();
            using (var cbs = new CircularBufferStream(50))
            {
                var cts = new CancellationTokenSource();
                Task.Run(async() =>
                {
                    var i = 0;
                    while (!cts.Token.IsCancellationRequested)
                    {
                        i++;
                        cbs.WriteBytes(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 });
                        if (i % 50 == 0)
                        {
                            Core.Log.InfoMedium("Write {0}", i);
                        }
                        await Task.Delay(1, cts.Token).ConfigureAwait(false);
                    }
                });
                Task.Run(async() =>
                {
                    var i      = 0;
                    var buffer = new byte[15];
                    while (!cts.Token.IsCancellationRequested)
                    {
                        i++;
                        cbs.Read(buffer, 0, 7);
                        if (i % 50 == 0)
                        {
                            Core.Log.InfoMedium("Read {0}", i);
                        }
                        await Task.Delay(1, cts.Token).ConfigureAwait(false);
                    }
                });
                Console.ReadLine();
                cts.Cancel();
            }



            Core.Log.WriteEmptyLine();
            Core.Log.InfoBasic("Press Enter to Start SharedMemoryStream Test. Press Enter Again to finish the test.");
            Console.ReadLine();
            using (var sharedms = new SharedMemoryStream("test", 2000))
            {
                var cts = new CancellationTokenSource();
                Task.Run(async() =>
                {
                    var i = 0;
                    while (!cts.Token.IsCancellationRequested)
                    {
                        i++;
                        sharedms.WriteBytes(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
                        if (i % 50 == 0)
                        {
                            Core.Log.InfoMedium("Write {0}", i);
                        }
                        await Task.Delay(1, cts.Token).ConfigureAwait(false);
                    }
                });
                Task.Run(async() =>
                {
                    var i      = 0;
                    var buffer = new byte[15];
                    while (!cts.Token.IsCancellationRequested)
                    {
                        i++;
                        sharedms.Read(buffer, 0, 7);
                        if (i % 50 == 0)
                        {
                            Core.Log.InfoMedium("Read {0}", i);
                        }
                        await Task.Delay(1, cts.Token).ConfigureAwait(false);
                    }
                });
                Console.ReadLine();
            }
        }
예제 #14
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            Core.Log.Warning("Starting RPC TEST");

            var serializer = new NBinarySerializer();
            var service    = new MyService();

            Core.Log.InfoBasic("Setting RPC Server");
            var rpcServer = new RPCServer(new DefaultTransportServer(20050, serializer));

            rpcServer.AddService(service);
            await rpcServer.StartAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("Setting RPC Client");
            var rpcClient = new RPCClient(new DefaultTransportClient("127.0.0.1", 20050, 1, serializer));

            var sw = Stopwatch.StartNew();

            //IHello test
            Core.Log.InfoBasic("IHello test");
            dynamic hClient = await rpcClient.CreateDynamicProxyAsync <IHello>().ConfigureAwait(false);

            var rtest = (string)hClient.SayHi("MyName");

            using (var watch = Watch.Create("IHello Time - SayHi | TestAsync"))
            {
                for (var i = 0; i < 5000; i++)
                {
                    var rHClient = (string)hClient.SayHi("MyName");
                }

                for (var i = 0; i < 5000; i++)
                {
                    var rHClient = await((Task <object>)hClient.TestAsync()).ConfigureAwait(false);
                }

                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 10000);
            }


            //IMyService test
            Core.Log.InfoBasic("IMyService test");
            dynamic dClient = await rpcClient.CreateDynamicProxyAsync <IMyService>().ConfigureAwait(false);

            using (var watch = Watch.Create("IMyService Time - GetAllAsync"))
            {
                for (var i = 0; i < 5000; i++)
                {
                    var aLst = await((Task <object>)dClient.GetAllAsync()).ConfigureAwait(false);
                }
                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 5000);
            }

            //Proxy class test
            Core.Log.InfoBasic("Proxy class test");
            var client = await rpcClient.CreateProxyAsync <MyServiceProxy>().ConfigureAwait(false);

            using (var watch = Watch.Create("Proxy class Time - GetAllAsync"))
            {
                for (var i = 0; i < 5000; i++)
                {
                    var resp = await client.GetAllAsync().ConfigureAwait(false);
                }
                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 5000);
            }

            using (var watch = Watch.Create("Parallel GetAllAsync Time"))
            {
                var rAwait = await Enumerable.Range(0, 50)
                             .Select(i => client.GetAllAsync())
                             .ConfigureAwait(false);

                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 100);
            }

            //Event test
            Core.Log.InfoBasic("Event test");
            using (var watch = Watch.Create("Event Test - AddSimplePersona"))
            {
                client.OnAddSimplePersona += (s, e) =>
                {
                    //Core.Log.Warning("On Add SimplePersona was fired!!!");
                };
                for (var i = 0; i < 5000; i++)
                {
                    client.AddSimplePersona(new SimplePerson {
                        Lastname = "Test", Firstname = "Test"
                    });
                }
                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 5000);
            }

            var sTime = sw.Elapsed;

            Console.ReadLine();
            Core.Log.Warning("All Rpc Requests on: {0}", sTime);
            rpcClient.Dispose();
            await rpcServer.StopAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("Test End.");
        }
예제 #15
0
        public static void Run(int min, int max, int numberElements, int capacity)
        {
            var randNum       = new Random();
            var randomNumbers = Enumerable.Repeat(0, numberElements).Select((i, vTuple) => vTuple.randNum.Next(vTuple.min, vTuple.max), (randNum, min, max)).ToArray();
            var lru           = new LRUCollection <int, long>(capacity);
            var lfu           = new LFUCollection <int, long>(capacity);
            var lru2Q         = new LRU2QCollection <int, long>(capacity);
            var lru2QSimple   = new LRU2QSimpleCollection <int, long>(capacity);

            Core.Log.InfoBasic("Processing: {0} elements", numberElements);
            Core.Log.InfoBasic("Collections Capacity: {0} elements", capacity);
            Core.Log.InfoBasic("Random numbers from {0} to {1}", min, max);
            Core.Log.WriteEmptyLine();

            using (var w = Watch.Create("LFU Start", "LFU End"))
            {
                Parallel.ForEach(randomNumbers, item =>
                {
                    var value = lfu.GetOrAdd(item, item);
                    if (value != item)
                    {
                        Core.Log.Warning("Bad value: " + value + " " + item);
                    }
                });
                var ms = w.GlobalElapsedMilliseconds / numberElements;
                Core.Log.InfoDetail("LFU Hits: {0}", lfu.Hits);
                Core.Log.InfoDetail("LFU Deletes: {0}", lfu.Deletes);
                Core.Log.InfoDetail("LFU Inserts: {0}", lfu.Inserts);
                Core.Log.InfoDetail("LFU ms per item: {0}ms", ms);
                Core.Log.InfoDetail("LFU ns per item: {0}ns", ms * 1_000_000);
            }
            Thread.Sleep(1000);
            Core.Log.WriteEmptyLine();


            using (var w = Watch.Create("LRU Start", "LRU End"))
            {
                Parallel.ForEach(randomNumbers, item =>
                {
                    var value = lru.GetOrAdd(item, item);
                    if (value != item)
                    {
                        Core.Log.Warning("Bad value: " + value + " " + item);
                    }
                });
                var ms = w.GlobalElapsedMilliseconds / numberElements;
                Core.Log.InfoDetail("LRU Hits: {0}", lru.Hits);
                Core.Log.InfoDetail("LRU Deletes: {0}", lru.Deletes);
                Core.Log.InfoDetail("LRU Inserts: {0}", lru.Inserts);
                Core.Log.InfoDetail("LRU ms per item: {0}ms", ms);
                Core.Log.InfoDetail("LRU ns per item: {0}ns", ms * 1_000_000);
            }
            Thread.Sleep(1000);
            Core.Log.WriteEmptyLine();


            using (var w = Watch.Create("LRU2QSimple Start", "LRU2QSimple End"))
            {
                Parallel.ForEach(randomNumbers, item =>
                {
                    var value = lru2QSimple.GetOrAdd(item, item);
                    if (value != item)
                    {
                        Core.Log.Warning("Bad value: " + value + " " + item);
                    }
                });
                var ms = w.GlobalElapsedMilliseconds / numberElements;
                Core.Log.InfoDetail("LRU2QSimple Hits: {0}", lru2QSimple.Hits);
                Core.Log.InfoDetail("LRU2QSimple Deletes: {0}", lru2QSimple.Deletes);
                Core.Log.InfoDetail("LRU2QSimple Inserts: {0}", lru2QSimple.Inserts);
                Core.Log.InfoDetail("LRU2QSimple ms per item: {0}ms", ms);
                Core.Log.InfoDetail("LRU2QSimple ns per item: {0}ns", ms * 1_000_000);
            }
            Thread.Sleep(1000);
            Core.Log.WriteEmptyLine();


            using (var w = Watch.Create("LRU2Q Start", "LRU2Q End"))
            {
                Parallel.ForEach(randomNumbers, item =>
                {
                    var value = lru2Q.GetOrAdd(item, item);
                    if (value != item)
                    {
                        Core.Log.Warning("Bad value: " + value + " " + item);
                    }
                });
                var ms = w.GlobalElapsedMilliseconds / numberElements;
                Core.Log.InfoDetail("LRU2Q Hits: {0}", lru2Q.Hits);
                Core.Log.InfoDetail("LRU2Q Deletes: {0}", lru2Q.Deletes);
                Core.Log.InfoDetail("LRU2Q Inserts: {0}", lru2Q.Inserts);
                Core.Log.InfoDetail("LRU2Q ms per item: {0}ms", ms);
                Core.Log.InfoDetail("LRU2Q ns per item: {0}ns", ms * 1_000_000);
            }
            Thread.Sleep(1000);
            Core.Log.WriteEmptyLine();
        }