Наследование: RioConnectionOrientedSocketPool
Пример #1
0
        static void Main(string[] args)
        {
            pipeLineDeph = int.Parse(args.FirstOrDefault(f => f.StartsWith("-p"))?.Substring(2) ?? "16");
            int connections = int.Parse(args.FirstOrDefault(f => f.StartsWith("-c"))?.Substring(2) ?? "512");
            clientPool = new RioTcpClientPool(new RioFixedBufferPool(1000, (256 * pipeLineDeph)), new RioFixedBufferPool(1000, (256 * pipeLineDeph)), (uint)connections);
            timer = new Stopwatch();
            span = TimeSpan.FromSeconds(int.Parse(args.FirstOrDefault(f => f.StartsWith("-d"))?.Substring(2) ?? "5"));
            uri = new Uri(args.FirstOrDefault(a => !a.StartsWith("-")) ?? "http://localhost:5000");
            keepAlive = true;
            requestBytes = Enumerable.Repeat(_requestBytes, pipeLineDeph).SelectMany(b => b).ToArray();

            Console.WriteLine("RioSharp http benchmark");
            Console.WriteLine("Connections: " + connections);
            Console.WriteLine("Duration: " + span.TotalSeconds + " seconds");
            Console.WriteLine("Pipeline depth: " + pipeLineDeph);
            Console.WriteLine("Target: " + uri);
            Console.WriteLine("Benchmarking...");

            timer.Start();
            var tasks = Enumerable.Range(0, connections).Select(t => Task.Run(Execute));

            var totalRequests = tasks.Sum(t => t.Result);
            Console.WriteLine($"Made {totalRequests } requests over {span.TotalSeconds} seconds ({totalRequests / span.TotalSeconds} Rps)");
            clientPool.Dispose();
        }
Пример #2
0
        public async Task ClientTcp()
        {
            RioTcpClientPool l = new RioTcpClientPool(new RioFixedBufferPool(Connections, Transfer), new RioFixedBufferPool(Connections, Transfer), (uint)Connections);
            int apa = 0;
            TaskCompletionSource<object> tcs;

            for (int i = 0; i < Iterations; i++)
            {
                var s = await l.Connect(new Uri(Target));

                if (Pattern == "PushPull")
                {
                    tcs = new TaskCompletionSource<object>();
                    s.WriteFixed(new byte[Transfer]);
                    s.OnIncommingSegment = seg =>
                    {
                        apa += seg.CurrentContentLength;
                        if (apa >= Transfer)
                            tcs.SetResult(null);
                    };
                    await tcs.Task;
                }
                else if (Pattern == "Push")
                    s.WriteFixed(new byte[Transfer]);
                else if (Pattern == "Pull")
                {
                    tcs = new TaskCompletionSource<object>();

                    s.OnIncommingSegment = seg =>
                    {
                        apa += seg.CurrentContentLength;
                        if (apa >= Transfer)
                            tcs.SetResult(null);
                    };
                }
                else if (Pattern == "Duplex")
                {
                    tcs = new TaskCompletionSource<object>();
                    s.WriteFixed(new byte[Transfer / 2]);
                    s.OnIncommingSegment = seg =>
                    {
                        apa += seg.CurrentContentLength;
                        if (apa >= Transfer / 2)
                            tcs.SetResult(null);
                    };
                }
            }

        }
Пример #3
0
        static void Main(string[] args)
        {

            clientPool = new RioTcpClientPool(new RioFixedBufferPool(100, 100), new RioFixedBufferPool(10, 100), 4096);
            listener = new RioTcpListener(new RioFixedBufferPool(100, 100), new RioFixedBufferPool(100, 100), 4096);
            listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024);
            e = new ManualResetEvent(false);

            var task = Task.Run((Action)clientDisconnect);
            Log();
            Console.ReadLine();
            running = false;
            task.Wait();
            clientPool.Dispose();
            listener.Dispose();
        }
Пример #4
0
        static void Main(string[] args)
        {
            pipeLineDeph = int.Parse(args.FirstOrDefault(f => f.StartsWith("-p"))?.Substring(2) ?? "16");
            clientPool = new RioTcpClientPool(new RioFixedBufferPool(1000, (64 * pipeLineDeph)), new RioFixedBufferPool(1000, (140 * pipeLineDeph)), 1024);
            int connections = int.Parse(args.FirstOrDefault(f => f.StartsWith("-c"))?.Substring(2) ?? "512");
            timer = new Stopwatch();
            span = TimeSpan.FromSeconds
                (int.Parse(args.FirstOrDefault(f => f.StartsWith("-d"))?.Substring(2) ?? "10"));
            timer.Start();
            uri = new Uri(args.FirstOrDefault(a => !a.StartsWith("-"))?? "http://localhost:5000");
            keepAlive = true;

            rb = Enumerable.Repeat(_requestBytes, pipeLineDeph).SelectMany(b => b).ToArray();
            var tasks = Enumerable.Range(0, connections).Select(t => Task.Run(doit));

            var ss = tasks.Sum(t => t.Result);
            Console.WriteLine(ss / span.TotalSeconds);
        }
Пример #5
0
        public static async Task ClientTcp()
        {
            RioTcpClientPool l = new RioTcpClientPool(new RioFixedBufferPool(Connections, Transfer), new RioFixedBufferPool(Connections, Transfer), (uint)Connections);
            int totalBytesRecived = 0;
            int currentRecived = 0;
            TaskCompletionSource<object> tcs;

            for (int i = 0; i < Iterations; i++)
            {
                var s = await l.Connect(new Uri(Target));
                var reader = new RioSegmentReader(s);

                if (Pattern == "PushPull")
                {
                    while (totalBytesRecived < Transfer)
                    {
                        tcs = new TaskCompletionSource<object>();
                        s.Send(new byte[PushBytes]);
                        reader.OnIncommingSegment = seg =>
                        {
                            totalBytesRecived += seg.CurrentContentLength;
                            currentRecived += seg.CurrentContentLength;
                            if (currentRecived >= PullBytes)
                                tcs.SetResult(null);
                        };
                        await tcs.Task;
                    }
                }
                else if (Pattern == "Push")
                    s.Send(new byte[Transfer]);
                else if (Pattern == "Pull")
                {
                    tcs = new TaskCompletionSource<object>();

                    reader.OnIncommingSegment = seg =>
                    {
                        totalBytesRecived += seg.CurrentContentLength;
                        if (totalBytesRecived >= Transfer)
                            tcs.SetResult(null);
                    };
                    await tcs.Task;
                }
                else if (Pattern == "Duplex")
                {
                    tcs = new TaskCompletionSource<object>();
                    s.Send(new byte[Transfer / 2]);
                    reader.OnIncommingSegment = seg =>
                    {
                        totalBytesRecived += seg.CurrentContentLength;
                        if (totalBytesRecived >= Transfer / 2)
                            tcs.SetResult(null);
                    };
                }
            }

        }