Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ThreadPool.SetMinThreads(65535, 65535);
            var remoteUrl = "http://127.0.0.1:8090/";

            if (args.Length != 0 && (args[0].StartsWith("http") || args[0].StartsWith("ws")))
            {
                remoteUrl = args[0];
            }
            var client = new JsonRpcClient();
            IJsonRpcClientEngine clientEngine = remoteUrl.StartsWith("http")?
                                                new JsonRpcHttpClientEngine(remoteUrl):
                                                new JsonRpcWebSocketClientEngine(remoteUrl);

            bool ws = clientEngine is JsonRpcWebSocketClientEngine;

            client.UseEngine(clientEngine);

            var testCount = 3;

            if (args.Contains("-benchmark"))
            {
                testCount = 100;
            }
            var statisticsList = new List <int>();

            for (var i = 0; i < testCount; i++)
            {
                statisticsList.Add(Benchmark(client, TestData, ws));
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine($"Best: {statisticsList.Max()} rpc/sec, \t Average: {(int)statisticsList.Average()} rpc/sec, \t Worst: {statisticsList.Min()} rpc/sec");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ThreadPool.SetMinThreads(65535, 65535);
            var server = new JsonRpcServer();

            var client = new JsonRpcClient();

            if (args.Contains("-debug"))
            {
                Logger.DebugMode = true;
                Logger.UseDefaultWriter();
            }

            if (args.Contains("-benchmark"))
            {
                var engine = new JsonRpcInProcessEngine();
                server.UseEngine(engine);
                client.UseEngine(engine);
                server.Start();
                var statisticsList = new List <int>();
                for (var i = 0; i < 20; i++)
                {
                    statisticsList.Add(Benchmark(client, TestData));
                    Console.WriteLine();
                }
                Console.WriteLine();
                Console.WriteLine($"Best: {statisticsList.Max()} rpc/sec, \t Average: {(int)statisticsList.Average()} rpc/sec, \t Worst: {statisticsList.Min()} rpc/sec");
            }
            else
            {
                IJsonRpcServerEngine serverEngine;
                if (args.Contains("-websocket"))
                {
                    serverEngine = new JsonRpcWebSocketServerEngine("http://*:8090/");
                    server.UseEngine(serverEngine);
                }
                else if (args.Contains("-websocket-kestrel"))
                {
                    serverEngine = new JsonRpcKestrelWebSocketServerEngine(IPAddress.Any, 8090);
                    server.UseEngine(serverEngine);
                }
                else
                if (args.Contains("-http-kestrel"))
                {
                    serverEngine = new JsonRpcKestrelHttpServerEngine(IPAddress.Any, 8090);
                    server.UseEngine(serverEngine);
                }
                else
                {
                    serverEngine = new JsonRpcHttpServerEngine("http://*:8090/");
                    server.UseEngine(serverEngine);
                }

                server.Start();
                Console.WriteLine($"JsonRpc Server Started with engine: {serverEngine.Name}.");
            }
            Console.ReadLine();
        }