public static unsafe void Main(string[] args) { var sendPool = new RioFixedBufferPool(10, 256); var recivePool = new RioFixedBufferPool(10, 256); var pool = new RioConnectionlessSocketPool(sendPool, recivePool, ADDRESS_FAMILIES.AF_INET, SOCKET_TYPE.SOCK_DGRAM, PROTOCOL.IPPROTO_UDP); RioConnectionlessSocket sock = null; var multicastAdress = IPAddress.Parse("238.0.3.15"); try { sock = pool.Bind(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 3000)); } catch (Exception) { sock = pool.Bind(); } var nics = NetworkInterface.GetAllNetworkInterfaces() .Where(n => n.Supports(NetworkInterfaceComponent.IPv4)) .Select(n => new { n.GetIPProperties().GetIPv4Properties().Index }); sock.JoinMulticastGroup(multicastAdress, 0); RioSegmentReader r = new RioSegmentReader(sock); r.OnIncommingSegment = segment => Console.WriteLine(Encoding.ASCII.GetString(segment.DataPointer, segment.CurrentContentLength)); r.Start(); while (true) { sock.Send(Encoding.ASCII.GetBytes("Hello, i'm process " + Process.GetCurrentProcess().Id), new IPEndPoint(multicastAdress, 3000)); Thread.Sleep(1000); } }
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) ?? "1024"); Console.WriteLine("RioSharp http server"); Console.WriteLine("Optimizing for " + connections + " connections"); Console.WriteLine("Optimizing for pipeline depth of: " + pipeLineDeph); sendPool = new RioFixedBufferPool(10 * connections, 256 * pipeLineDeph); recivePool = new RioFixedBufferPool(10 * connections, 256 * pipeLineDeph); listener = new RioTcpListener(sendPool, recivePool, (uint)connections); currentSegment = listener.PreAllocateWrite(GetResponse()); responseBytes = GetResponse(); //Task.Run(async () => //{ // while (true) // { // UpdateResponse(); // await Task.Delay(60000); // } //}); listener.OnAccepted = new Action <RioSocket>(s => ThreadPool.QueueUserWorkItem(o => Servebuff((RioSocket)o), s)); listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024 * connections); Console.WriteLine("Listening on : http://localhost:5000"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); listener.Dispose(); }
public void Start <TContext>(IHttpApplication <TContext> application) { var information = Features.Get <IRioSharpServerInformation>(); sendPool = new RioFixedBufferPool(1000, 140 * information.PipeLineDepth); recivePool = new RioFixedBufferPool(1000, 64 * information.PipeLineDepth); listener = new RioTcpListener(sendPool, recivePool, 1024); listener.OnAccepted = new Action <RioSocket>(s => ThreadPool.QueueUserWorkItem(o => Servebuff((RioSocket)o), s)); listener.Listen(new IPEndPoint(new IPAddress(new byte[] { 0, 0, 0, 0 }), 5000), 1024 * information.Connections); // do things }
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"); timer = new Stopwatch(); span = TimeSpan.FromSeconds(int.Parse(args.FirstOrDefault(f => f.StartsWith("-d"))?.Substring(2) ?? "25")); uri = new Uri(args.FirstOrDefault(a => !a.StartsWith("-")) ?? "http://localhost:5000/plaintext"); keepAlive = bool.Parse(args.FirstOrDefault(f => f.StartsWith("-k"))?.Substring(2) ?? "true"); Console.WriteLine("RioSharp http benchmark"); Console.WriteLine("Connections: " + connections); Console.WriteLine("Duration: " + span.TotalSeconds + " seconds"); Console.WriteLine("Pipeline depth: " + pipeLineDeph); Console.WriteLine("Target: " + uri); Task.Delay(span).ContinueWith(t => { Console.WriteLine("should be done by now..."); }); var _requestBytes = Encoding.ASCII.GetBytes($"GET {uri.PathAndQuery} HTTP/1.1\r\nHost: {uri.Host}:{uri.Port}\r\n\r\n"); reqz = new byte[pipeLineDeph + 1][]; for (int i = 0; i < reqz.Length; i++) { reqz[i] = Enumerable.Repeat(_requestBytes, i).SelectMany(b => b).ToArray(); } sendPool = new RioFixedBufferPool(10 * connections, _requestBytes.Length * pipeLineDeph); clientPool = new RioTcpClientPool(sendPool, new RioFixedBufferPool(10 * connections, (256 * pipeLineDeph)), (uint)connections, 4096, 4096); Console.WriteLine("Benchmarking..."); timer.Start(); var tasks = Enumerable.Range(0, connections).Select(t => keepAlive ? Task.Run(ExecuteSegment) : Task.Run(ExecuteStream)).ToList(); var totalRequests = tasks.Sum(t => t.Result.Requests); Console.WriteLine($"Made {totalRequests } requests over {span.TotalSeconds} seconds ({totalRequests / span.TotalSeconds} Rps)"); clientPool.Dispose(); }
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"); timer = new Stopwatch(); span = TimeSpan.FromSeconds(int.Parse(args.FirstOrDefault(f => f.StartsWith("-d"))?.Substring(2) ?? "25")); uri = new Uri(args.FirstOrDefault(a => !a.StartsWith("-")) ?? "http://localhost:5000/plaintext"); keepAlive = bool.Parse(args.FirstOrDefault(f => f.StartsWith("-k"))?.Substring(2) ?? "true"); Console.WriteLine("RioSharp http benchmark"); Console.WriteLine("Connections: " + connections); Console.WriteLine("Duration: " + span.TotalSeconds + " seconds"); Console.WriteLine("Pipeline depth: " + pipeLineDeph); Console.WriteLine("Target: " + uri); Task.Delay(span).ContinueWith(t => { Console.WriteLine("should be done by now..."); }); var _requestBytes = Encoding.ASCII.GetBytes($"GET {uri.PathAndQuery} HTTP/1.1\r\nHost: {uri.Host}:{uri.Port}\r\n\r\n"); reqz = new byte[pipeLineDeph + 1][]; for (int i = 0; i < reqz.Length; i++) { reqz[i] = Enumerable.Repeat(_requestBytes, i).SelectMany(b => b).ToArray(); } sendPool = new RioFixedBufferPool(10 * connections, _requestBytes.Length * pipeLineDeph); clientPool = new RioTcpClientPool(sendPool, new RioFixedBufferPool(10 * connections, (256 * pipeLineDeph)), (uint)connections,4096,4096); Console.WriteLine("Benchmarking..."); timer.Start(); var tasks = Enumerable.Range(0, connections).Select(t => keepAlive ? Task.Run(ExecuteSegment) : Task.Run(ExecuteStream)).ToList(); var totalRequests = tasks.Sum(t => t.Result.Requests); Console.WriteLine($"Made {totalRequests } requests over {span.TotalSeconds} seconds ({totalRequests / span.TotalSeconds} Rps)"); clientPool.Dispose(); }
public RioConnectionlessSocketPool(RioFixedBufferPool sendPool, RioFixedBufferPool revicePool, int socketCount, uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024, uint maxOutsandingCompletions = 1024) : base(sendPool, revicePool, maxOutstandingReceive, maxOutstandingSend, maxOutsandingCompletions) { }
public RioConnectionlessSocketPool(RioFixedBufferPool sendPool, RioFixedBufferPool revicePool, ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol, uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024, uint maxOutsandingCompletions = 1024) : base(sendPool, revicePool, adressFam, sockType, protocol, maxOutstandingReceive, maxOutstandingSend, maxOutsandingCompletions) { }
private void Initialize() { _bufferManager = new GrowingByteBufferManager(_configuration.InitialPooledBufferCount, _configuration.ReceiveBufferSize); int pipeLineDeph = 16; int connections = 1024; _sendPool = new RioFixedBufferPool(10 * connections, 140 * pipeLineDeph); _receivePool = new RioFixedBufferPool(10 * connections, 128 * pipeLineDeph); _listener = new RioTcpListener(_sendPool, _receivePool, 1024); _listener.OnAccepted = (acceptedSocket) => { Task.Run(async () => { await Process(acceptedSocket); }) .Forget(); }; }
public void Shutdown() { if (Interlocked.Exchange(ref _state, _disposed) == _disposed) { return; } try { _listener.Dispose(); _listener = null; Task.Run(async () => { try { foreach (var session in _sessions.Values) { await session.Close(); } } catch (Exception ex) when (!ShouldThrow(ex)) { } }) .Wait(); _sendPool.Dispose(); _receivePool.Dispose(); _sendPool = null; _receivePool = null; } catch (Exception ex) when (!ShouldThrow(ex)) { } }