public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var server = new HttpListener(); server.Prefixes.Add("http://localhost:20000/"); server.Start(); var serverTransport = server.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <IMyService>(new MyService()); var client = new ClientWebSocket(); client.Options.SetBuffer(8192, 8192); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <IMyService>(); client.ConnectAsync(new Uri("ws://localhost:20000/"), CancellationToken.None).Wait(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); server.Stop(); server.Close(); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var listener = new WebSocketServer("ws://localhost:" + port); var serverTransport = listener.GenerateTransportSource("/p1"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <IMyService>(new MyService()); listener.Start(); var client = new WebSocket("ws://localhost:" + port + "/p1"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <IMyService>(); client.Connect(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Close(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Stop(); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var listener = new WebSocketServer("ws://localhost:" + port); var serverTransport = listener.GenerateTransportSource("/p1"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<IMyService>(new MyService()); listener.Start(); var client = new WebSocket("ws://localhost:" + port + "/p1"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<IMyService>(); client.Connect(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Close(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Stop(); }
private Task RunClient <T>(ICommonSerializer serializer, int port, Action <Poller> loadPoller, Action <T> loadProxy) where T : class { var task = new Task(() => { var clientContext = NetMQContext.Create(); var clientSocket = clientContext.CreateRequestSocket(); // clientContext.CreateRouterSocket(); clientSocket.Options.Linger = TimeSpan.Zero; var clientPoller = new Poller(clientSocket); var clientScheduler = new NetMQScheduler(clientContext, clientPoller); var clientTransport = clientSocket.GenerateTransportSource(clientScheduler); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <T>(); clientSocket.Connect("tcp://localhost:" + port); loadPoller.Invoke(clientPoller); loadProxy.Invoke(proxy); clientPoller.PollTillCancelled(); clientScheduler.Dispose(); clientPoller.Dispose(); clientRouter.Dispose(); clientTransport.Dispose(); clientSocket.Dispose(); clientContext.Dispose(); }, TaskCreationOptions.LongRunning); task.Start(); return(task); }
public void BasicRoundTrip() { if (IntPtr.Size != 8) throw new InvalidOperationException("Expected x64"); var serializer = new JsonCommonSerializer(); var factory = DomainParticipantFactory.Instance; //var p1 = factory.LookupParticipant(DomainId.Default); var serverParticipant = factory.CreateParticipant(DomainId.Default); var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<EverytingToOwin.IMyService>(new EverytingToOwin.MyService()); var clientParticipant = factory.CreateParticipant(DomainId.Default); var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse"); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<EverytingToOwin.IMyService>(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); factory.DeleteParticipant(clientParticipant); serverRouter.Dispose(); serverTransport.Dispose(); factory.DeleteParticipant(serverParticipant); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram); listener.Bind(IPAddress.Loopback, port); listener.Listen(100); var serverTransport = listener.GenerateTransportSource(true); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <IMyService>(new MyService()); var client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram); client.Connect(IPAddress.Loopback, port); var clientTransport = client.GenerateTransportSource(false); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <IMyService>(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
private Task RunServer <T>(ICommonSerializer serializer, Action <int> loadPort, Action <Poller> loadPoller, T service) where T : class { var task = new Task(() => { var serverContext = NetMQContext.Create(); var serverSocket = serverContext.CreateResponseSocket(); // serverContext.CreateRouterSocket(); var serverPoller = new Poller(serverSocket); var serverScheduler = new NetMQScheduler(serverContext, serverPoller); var serverTransport = serverSocket.GenerateTransportSource(serverScheduler); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService(service); var port = serverSocket.BindRandomPort("tcp://localhost"); loadPoller.Invoke(serverPoller); loadPort.Invoke(port); serverPoller.PollTillCancelled(); serverScheduler.Dispose(); serverPoller.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); serverSocket.Dispose(); serverContext.Dispose(); }, TaskCreationOptions.LongRunning); task.Start(); return(task); }
public void WebSocket4NetRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(20000, 60000); var server = WebApp.Start <Startup>("http://localhost:" + port + "/"); var client = new WebSocket4Net.WebSocket("ws://localhost:" + port + "/rt1", "", WebSocket4Net.WebSocketVersion.Rfc6455); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <IMyService>(); client.Open(); while (client.State != WebSocket4Net.WebSocketState.Open) { Thread.Sleep(10); } var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); server.Dispose(); }
public void WebSocket4NetRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(20000, 60000); var server = WebApp.Start<Startup>("http://localhost:" + port + "/"); var client = new WebSocket4Net.WebSocket("ws://localhost:" + port + "/rt1", "", WebSocket4Net.WebSocketVersion.Rfc6455); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<IMyService>(); client.Open(); while (client.State != WebSocket4Net.WebSocketState.Open) Thread.Sleep(10); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); server.Dispose(); }
public void WebSocketSharpRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(20000, 60000); var server = WebApp.Start <Startup>("http://localhost:" + port + "/"); var client = new WebSocketSharp.WebSocket("ws://localhost:" + port + "/rt1"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <IMyService>(); client.Connect(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Close(); server.Dispose(); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var server = new HttpListener(); server.Prefixes.Add("http://localhost:20000/"); server.Start(); var serverTransport = server.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<IMyService>(new MyService()); var client = new ClientWebSocket(); client.Options.SetBuffer(8192, 8192); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<IMyService>(); client.ConnectAsync(new Uri("ws://localhost:20000/"), CancellationToken.None).Wait(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); server.Stop(); server.Close(); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var options = new WebSocketListenerOptions(); options.SubProtocols = new[] { "SignalR" }; var listener = new WebSocketListener(new IPEndPoint(IPAddress.Loopback, port), options); var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(listener); listener.Standards.RegisterStandard(rfc6455); var serverTransport = listener.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<IMyService>(new MyService()); listener.Start(); var client = new ClientWebSocket(); client.Options.AddSubProtocol("SignalR"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<IMyService>(); client.ConnectAsync(new Uri("ws://localhost:" + port + "/"), CancellationToken.None).Wait(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram); listener.Bind(IPAddress.Loopback, port); listener.Listen(100); var serverTransport = listener.GenerateTransportSource(true); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<IMyService>(new MyService()); var client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram); client.Connect(IPAddress.Loopback, port); var clientTransport = client.GenerateTransportSource(false); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<IMyService>(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void Configuration(IAppBuilder app) { var serializer = new JsonCommonSerializer(); // new ProtobufCommonSerializer(); // var source = app.GenerateTransportSource("/rt1"); var serverRouter = new DefaultMessageRouter(source, serializer); serverRouter.AddService<IMyService>(new MyService()); serverRouter.AddService<ISumService>(new SumService()); }
public void Configuration(IAppBuilder app) { var serializer = new JsonCommonSerializer(); // new ProtobufCommonSerializer(); // var source = app.GenerateTransportSource("/rt1"); var serverRouter = new DefaultMessageRouter(source, serializer); serverRouter.AddService <IMyService>(new MyService()); serverRouter.AddService <ISumService>(new SumService()); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var factory = DomainParticipantFactory.get_instance(); var serverQos = new DomainParticipantQos(); factory.get_default_participant_qos(serverQos); //serverQos.transport_builtin.mask = 0; // disable built-in transports //serverQos.property_qos.value serverQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); var serverParticipant = factory.create_participant(0, serverQos, null, StatusMask.STATUS_MASK_NONE); var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <EverytingToOwin.IMyService>(new EverytingToOwin.MyService()); var clientQos = new DomainParticipantQos(); factory.get_default_participant_qos(clientQos); clientQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); var clientParticipant = factory.create_participant(0, clientQos, null, StatusMask.STATUS_MASK_NONE); var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse"); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <EverytingToOwin.IMyService>(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); factory.delete_participant(ref clientParticipant); serverRouter.Dispose(); serverTransport.Dispose(); factory.delete_participant(ref serverParticipant); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var options = new WebSocketListenerOptions(); options.SubProtocols = new[] { "SignalR" }; var listener = new WebSocketListener(new IPEndPoint(IPAddress.Loopback, port), options); var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(listener); listener.Standards.RegisterStandard(rfc6455); var serverTransport = listener.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <IMyService>(new MyService()); listener.Start(); var client = new WebSocket("ws://localhost:" + port + "/", "SignalR", WebSocket4Net.WebSocketVersion.Rfc6455); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <IMyService>(); client.Open(); while (client.State != WebSocket4Net.WebSocketState.Open) { Thread.Sleep(10); } var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var factory = DomainParticipantFactory.get_instance(); var serverQos = new DomainParticipantQos(); factory.get_default_participant_qos(serverQos); //serverQos.transport_builtin.mask = 0; // disable built-in transports //serverQos.property_qos.value serverQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); var serverParticipant = factory.create_participant(0, serverQos, null, StatusMask.STATUS_MASK_NONE); var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<EverytingToOwin.IMyService>(new EverytingToOwin.MyService()); var clientQos = new DomainParticipantQos(); factory.get_default_participant_qos(clientQos); clientQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); var clientParticipant = factory.create_participant(0, clientQos, null, StatusMask.STATUS_MASK_NONE); var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse"); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<EverytingToOwin.IMyService>(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); factory.delete_participant(ref clientParticipant); serverRouter.Dispose(); serverTransport.Dispose(); factory.delete_participant(ref serverParticipant); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var options = new WebSocketListenerOptions(); options.SubProtocols = new[] { "SignalR" }; var listener = new WebSocketListener(new IPEndPoint(IPAddress.Loopback, port), options); var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(listener); listener.Standards.RegisterStandard(rfc6455); var serverTransport = listener.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <IMyService>(new MyService()); listener.Start(); var client = new ClientWebSocket(); client.Options.AddSubProtocol("SignalR"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <IMyService>(); client.ConnectAsync(new Uri("ws://localhost:" + port + "/"), CancellationToken.None).Wait(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void BasicRoundTrip() { if (IntPtr.Size != 8) { throw new InvalidOperationException("Expected x64"); } var serializer = new JsonCommonSerializer(); var factory = DomainParticipantFactory.Instance; //var p1 = factory.LookupParticipant(DomainId.Default); var serverParticipant = factory.CreateParticipant(DomainId.Default); var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <EverytingToOwin.IMyService>(new EverytingToOwin.MyService()); var clientParticipant = factory.CreateParticipant(DomainId.Default); var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse"); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <EverytingToOwin.IMyService>(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); factory.DeleteParticipant(clientParticipant); serverRouter.Dispose(); serverTransport.Dispose(); factory.DeleteParticipant(serverParticipant); }
public void BasicRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var options = new WebSocketListenerOptions(); options.SubProtocols = new[] { "SignalR" }; var listener = new WebSocketListener(new IPEndPoint(IPAddress.Loopback, port), options); var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(listener); listener.Standards.RegisterStandard(rfc6455); var serverTransport = listener.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<IMyService>(new MyService()); listener.Start(); var client = new WebSocket("ws://localhost:" + port + "/", "SignalR", WebSocket4Net.WebSocketVersion.Rfc6455); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<IMyService>(); client.Open(); while (client.State != WebSocket4Net.WebSocketState.Open) Thread.Sleep(10); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void Benchmark() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(30000, 60000); var options = new WebSocketListenerOptions(); options.SubProtocols = new[] { "SignalR" }; var listener = new WebSocketListener(new IPEndPoint(IPAddress.Loopback, port), options); var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(listener); listener.Standards.RegisterStandard(rfc6455); var serverTransport = listener.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <ISumService>(new SumService()); listener.Start(); var client = new ClientWebSocket(); client.Options.AddSubProtocol("SignalR"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <ISumService>(); client.ConnectAsync(new Uri("ws://localhost:" + port + "/"), CancellationToken.None).Wait(); const int randCnt = 100; var rand = new Random(42); var randoms = new int[randCnt]; for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var sw = new Stopwatch(); long timeFromClient = 0, timeToClient = 0; const int cnt = 1000; for (int j = 0; j < cnt; j++) { sw.Start(); var sum = proxy.Sum(randoms).Result; sw.Stop(); Assert.Equal(randoms.Sum(), sum); for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result; timeFromClient += times.Item1; timeToClient += Stopwatch.GetTimestamp() - times.Item2; } _testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds); _testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10); _testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10); sw.Reset(); var tree = new SumServiceTree(); SumServiceTree.FillTree(tree, rand, 2); _testOutputHelper.WriteLine("Starting large message transfer."); sw.Start(); var result = proxy.Increment(tree).Result; sw.Stop(); Assert.Equal(tree.Leaf + 1, result.Leaf); _testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void Benchmark() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(6000, 60000); var options = new WebSocketListenerOptions(); options.SubProtocols = new[] { "SignalR" }; var listener = new WebSocketListener(new IPEndPoint(IPAddress.Loopback, port), options); var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(listener); listener.Standards.RegisterStandard(rfc6455); var serverTransport = listener.GenerateTransportSource(); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<ISumService>(new SumService()); listener.Start(); var client = new WebSocket("ws://localhost:" + port + "/", "SignalR", WebSocket4Net.WebSocketVersion.Rfc6455); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<ISumService>(); client.Open(); while (client.State != WebSocket4Net.WebSocketState.Open) Thread.Sleep(10); const int randCnt = 100; var rand = new Random(42); var randoms = new int[randCnt]; for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000); var sw = new Stopwatch(); long timeFromClient = 0, timeToClient = 0; const int cnt = 1000; for (int j = 0; j < cnt; j++) { sw.Start(); var sum = proxy.Sum(randoms).Result; sw.Stop(); Assert.Equal(randoms.Sum(), sum); for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000); var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result; timeFromClient += times.Item1; timeToClient += Stopwatch.GetTimestamp() - times.Item2; } _testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds); _testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10); _testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10); //sw.Reset(); //var tree = new SumServiceTree(); //SumServiceTree.FillTree(tree, rand, 2); //_testOutputHelper.WriteLine("Starting large message transfer."); //sw.Start(); //var result = proxy.Increment(tree).Result; //sw.Stop(); //Assert.Equal(tree.Leaf + 1, result.Leaf); //_testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void BenchmarkMessagesWebSocketSharp() { var serializer = new JsonCommonSerializer(); // new ProtobufCommonSerializer(); // var port = new Random().Next(20000, 60000); var url = "http://localhost:" + port + "/"; var server = WebApp.Start <Startup>(url); var client = new WebSocketSharp.WebSocket("ws://localhost:" + port + "/rt1"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <ISumService>(); client.Connect(); const int randCnt = 100; var rand = new Random(42); var randoms = new int[randCnt]; for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var sw = new Stopwatch(); long timeFromClient = 0, timeToClient = 0; const int cnt = 1000; for (int j = 0; j < cnt; j++) { sw.Start(); var sum = proxy.Sum(randoms).Result; sw.Stop(); Assert.Equal(randoms.Sum(), sum); for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result; timeFromClient += times.Item1; timeToClient += Stopwatch.GetTimestamp() - times.Item2; } _testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds); _testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10); _testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10); sw.Reset(); var tree = new SumServiceTree(); SumServiceTree.FillTree(tree, rand, 2); _testOutputHelper.WriteLine("Starting large message transfer."); sw.Start(); var result = proxy.Increment(tree).Result; sw.Stop(); Assert.Equal(tree.Leaf + 1, result.Leaf); _testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds); client.Close(); server.Dispose(); }
public void Benchmark() { //var serializerSource = new Newtonsoft.Json.JsonSerializer(); var serializer = new ProtobufCommonSerializer(); //new JsonCommonSerializer(serializerSource); // var port = new Random().Next(6000, 60000); var listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram); listener.Bind(IPAddress.Loopback, port); listener.Listen(100); var serverTransport = listener.GenerateTransportSource(true); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <ISumService>(new SumService()); var client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram); client.Connect(IPAddress.Loopback, port); var clientTransport = client.GenerateTransportSource(false); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <ISumService>(); const int randCnt = 100; var rand = new Random(42); var randoms = new int[randCnt]; for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var sw = new Stopwatch(); long timeFromClient = 0, timeToClient = 0; const int cnt = 1000; for (int j = 0; j < cnt; j++) { sw.Start(); var sum = proxy.Sum(randoms).Result; sw.Stop(); Assert.Equal(randoms.Sum(), sum); for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result; timeFromClient += times.Item1; timeToClient += Stopwatch.GetTimestamp() - times.Item2; } _testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds); _testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10); _testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10); sw.Reset(); var tree = new SumServiceTree(); SumServiceTree.FillTree(tree, rand, 2); _testOutputHelper.WriteLine("Starting large message transfer."); sw.Start(); var result = proxy.Increment(tree).Result; sw.Stop(); Assert.Equal(tree.Leaf + 1, result.Leaf); _testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds); clientRouter.Dispose(); clientTransport.Dispose(); client.Dispose(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Dispose(); }
public void WebSocketSharpRoundTrip() { var serializer = new JsonCommonSerializer(); var port = new Random().Next(20000, 60000); var server = WebApp.Start<Startup>("http://localhost:" + port + "/"); var client = new WebSocketSharp.WebSocket("ws://localhost:" + port + "/rt1"); var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<IMyService>(); client.Connect(); var result = proxy.Add(3, 4).Result; Assert.Equal(7, result); clientRouter.Dispose(); clientTransport.Dispose(); client.Close(); server.Dispose(); }
public void Benchmark() { var serializer = new JsonCommonSerializer(); var factory = DomainParticipantFactory.get_instance(); var serverQos = new DomainParticipantQos(); factory.get_default_participant_qos(serverQos); serverQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); const int maxBufferSize = 1 << 24; // 16MB serverQos.receiver_pool.buffer_size = 65530; // max allowed //serverQos.discovery_config.publication_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; serverQos.discovery_config.publication_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; //serverQos.discovery_config.subscription_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; serverQos.discovery_config.subscription_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; var len = serverQos.property_qos.value.length + 3; serverQos.property_qos.value.ensure_length(len, len); serverQos.property_qos.value.set_at(len - 3, new Property_t { name = "dds.transport.UDPv4.builtin.recv_socket_buffer_size", value = maxBufferSize.ToString() }); serverQos.property_qos.value.set_at(len - 2, new Property_t { name = "dds.transport.UDPv4.builtin.parent.message_size_max", value = serverQos.receiver_pool.buffer_size.ToString() }); serverQos.property_qos.value.set_at(len - 1, new Property_t { name = "dds.transport.UDPv4.builtin.send_socket_buffer_size", value = serverQos.receiver_pool.buffer_size.ToString() }); //serverQos.resource_limits.type_code_max_serialized_length = maxBufferSize; serverQos.resource_limits.type_object_max_serialized_length = maxBufferSize; serverQos.resource_limits.type_object_max_deserialized_length = maxBufferSize; var serverParticipant = factory.create_participant(0, serverQos, null, StatusMask.STATUS_MASK_NONE); var controller = serverParticipant.lookup_flowcontroller(FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME); var flowProperty = new FlowControllerProperty_t(); controller.get_property(flowProperty); flowProperty.token_bucket.period = Duration_t.from_millis(50); controller.set_property(flowProperty); var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<ISumService>(new SumService()); var clientQos = new DomainParticipantQos(); factory.get_default_participant_qos(clientQos); clientQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); clientQos.receiver_pool.buffer_size = 65530; // max allowed //clientQos.discovery_config.publication_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; clientQos.discovery_config.publication_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; //clientQos.discovery_config.subscription_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; clientQos.discovery_config.subscription_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; len = clientQos.property_qos.value.length + 3; clientQos.property_qos.value.ensure_length(len, len); clientQos.property_qos.value.set_at(len - 3, new Property_t { name = "dds.transport.UDPv4.builtin.recv_socket_buffer_size", value = maxBufferSize.ToString() }); clientQos.property_qos.value.set_at(len - 2, new Property_t { name = "dds.transport.UDPv4.builtin.parent.message_size_max", value = clientQos.receiver_pool.buffer_size.ToString() }); clientQos.property_qos.value.set_at(len - 1, new Property_t { name = "dds.transport.UDPv4.builtin.send_socket_buffer_size", value = clientQos.receiver_pool.buffer_size.ToString() }); //clientQos.resource_limits.type_code_max_serialized_length = maxBufferSize; clientQos.resource_limits.type_object_max_serialized_length = maxBufferSize; clientQos.resource_limits.type_object_max_deserialized_length = maxBufferSize; var clientParticipant = factory.create_participant(0, clientQos, null, StatusMask.STATUS_MASK_NONE); controller = clientParticipant.lookup_flowcontroller(FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME); flowProperty = new FlowControllerProperty_t(); controller.get_property(flowProperty); flowProperty.token_bucket.period = Duration_t.from_millis(50); controller.set_property(flowProperty); var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse"); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<ISumService>(); const int randCnt = 100; var rand = new Random(42); var randoms = new int[randCnt]; for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000); var sw = new Stopwatch(); long timeFromClient = 0, timeToClient = 0; const int cnt = 1000; for (int j = 0; j < cnt; j++) { sw.Start(); var sum = proxy.Sum(randoms).Result; sw.Stop(); Assert.Equal(randoms.Sum(), sum); for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000); var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result; timeFromClient += times.Item1; timeToClient += Stopwatch.GetTimestamp() - times.Item2; } _testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds); _testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10); _testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10); //sw.Reset(); //var tree = new SumServiceTree(); //SumServiceTree.FillTree(tree, rand, 2); //_testOutputHelper.WriteLine("Starting large message transfer."); //sw.Start(); //var result = proxy.Increment(tree).Result; //sw.Stop(); //Assert.Equal(tree.Leaf + 1, result.Leaf); //_testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds); clientRouter.Dispose(); clientTransport.Dispose(); factory.delete_participant(ref clientParticipant); serverRouter.Dispose(); serverTransport.Dispose(); factory.delete_participant(ref serverParticipant); }
public void Benchmark() { var serializerSource = new Newtonsoft.Json.JsonSerializer(); var serializer =new JsonCommonSerializer(serializerSource); // new ProtobufCommonSerializer();// var port = new Random().Next(6000, 60000); var listener = new WebSocketServer("ws://localhost:" + port); var serverTransport = listener.GenerateTransportSource("/p1"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService<ISumService>(new SumService()); listener.Start(); var client = new WebSocket("ws://localhost:" + port + "/p1"); //client.Compression = WebSocketSharp.CompressionMethod.Deflate; var clientTransport = client.GenerateTransportSource(); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface<ISumService>(); client.Connect(); const int randCnt = 100; var rand = new Random(42); var randoms = new int[randCnt]; for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000); var package = new SumPackage { Numbers = randoms }; var sw = new Stopwatch(); long timeFromClient = 0, timeToClient = 0; const int cnt = 1000; for (int j = 0; j < cnt; j++) { sw.Start(); //var sum = proxy.Sum(randoms).Result; var sum = proxy.SumPackage(package).Result; sw.Stop(); Assert.Equal(randoms.Sum(), sum); for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000); var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result; timeFromClient += times.Item1; timeToClient += Stopwatch.GetTimestamp() - times.Item2; } _testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds); _testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10); _testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10); sw.Reset(); var tree = new SumServiceTree(); SumServiceTree.FillTree(tree, rand, 2); _testOutputHelper.WriteLine("Starting large message transfer."); sw.Start(); var result = proxy.Increment(tree).Result; sw.Stop(); Assert.Equal(tree.Leaf + 1, result.Leaf); _testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds); clientRouter.Dispose(); clientTransport.Dispose(); client.Close(); serverRouter.Dispose(); serverTransport.Dispose(); listener.Stop(); }
public void Benchmark() { var serializer = new JsonCommonSerializer(); var factory = DomainParticipantFactory.get_instance(); var serverQos = new DomainParticipantQos(); factory.get_default_participant_qos(serverQos); serverQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); const int maxBufferSize = 1 << 24; // 16MB serverQos.receiver_pool.buffer_size = 65530; // max allowed //serverQos.discovery_config.publication_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; serverQos.discovery_config.publication_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; //serverQos.discovery_config.subscription_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; serverQos.discovery_config.subscription_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; var len = serverQos.property_qos.value.length + 3; serverQos.property_qos.value.ensure_length(len, len); serverQos.property_qos.value.set_at(len - 3, new Property_t { name = "dds.transport.UDPv4.builtin.recv_socket_buffer_size", value = maxBufferSize.ToString() }); serverQos.property_qos.value.set_at(len - 2, new Property_t { name = "dds.transport.UDPv4.builtin.parent.message_size_max", value = serverQos.receiver_pool.buffer_size.ToString() }); serverQos.property_qos.value.set_at(len - 1, new Property_t { name = "dds.transport.UDPv4.builtin.send_socket_buffer_size", value = serverQos.receiver_pool.buffer_size.ToString() }); //serverQos.resource_limits.type_code_max_serialized_length = maxBufferSize; serverQos.resource_limits.type_object_max_serialized_length = maxBufferSize; serverQos.resource_limits.type_object_max_deserialized_length = maxBufferSize; var serverParticipant = factory.create_participant(0, serverQos, null, StatusMask.STATUS_MASK_NONE); var controller = serverParticipant.lookup_flowcontroller(FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME); var flowProperty = new FlowControllerProperty_t(); controller.get_property(flowProperty); flowProperty.token_bucket.period = Duration_t.from_millis(50); controller.set_property(flowProperty); var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest"); var serverRouter = new DefaultMessageRouter(serverTransport, serializer); serverRouter.AddService <ISumService>(new SumService()); var clientQos = new DomainParticipantQos(); factory.get_default_participant_qos(clientQos); clientQos.discovery.initial_peers.from_array(new[] { "1@localhost" }); clientQos.receiver_pool.buffer_size = 65530; // max allowed //clientQos.discovery_config.publication_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; clientQos.discovery_config.publication_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; //clientQos.discovery_config.subscription_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS; clientQos.discovery_config.subscription_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME; len = clientQos.property_qos.value.length + 3; clientQos.property_qos.value.ensure_length(len, len); clientQos.property_qos.value.set_at(len - 3, new Property_t { name = "dds.transport.UDPv4.builtin.recv_socket_buffer_size", value = maxBufferSize.ToString() }); clientQos.property_qos.value.set_at(len - 2, new Property_t { name = "dds.transport.UDPv4.builtin.parent.message_size_max", value = clientQos.receiver_pool.buffer_size.ToString() }); clientQos.property_qos.value.set_at(len - 1, new Property_t { name = "dds.transport.UDPv4.builtin.send_socket_buffer_size", value = clientQos.receiver_pool.buffer_size.ToString() }); //clientQos.resource_limits.type_code_max_serialized_length = maxBufferSize; clientQos.resource_limits.type_object_max_serialized_length = maxBufferSize; clientQos.resource_limits.type_object_max_deserialized_length = maxBufferSize; var clientParticipant = factory.create_participant(0, clientQos, null, StatusMask.STATUS_MASK_NONE); controller = clientParticipant.lookup_flowcontroller(FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME); flowProperty = new FlowControllerProperty_t(); controller.get_property(flowProperty); flowProperty.token_bucket.period = Duration_t.from_millis(50); controller.set_property(flowProperty); var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse"); var clientRouter = new DefaultMessageRouter(clientTransport, serializer); var proxy = clientRouter.AddInterface <ISumService>(); const int randCnt = 100; var rand = new Random(42); var randoms = new int[randCnt]; for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var sw = new Stopwatch(); long timeFromClient = 0, timeToClient = 0; const int cnt = 1000; for (int j = 0; j < cnt; j++) { sw.Start(); var sum = proxy.Sum(randoms).Result; sw.Stop(); Assert.Equal(randoms.Sum(), sum); for (int i = 0; i < randCnt; i++) { randoms[i] = rand.Next(10000000, 20000000); } var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result; timeFromClient += times.Item1; timeToClient += Stopwatch.GetTimestamp() - times.Item2; } _testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds); _testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10); _testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10); //sw.Reset(); //var tree = new SumServiceTree(); //SumServiceTree.FillTree(tree, rand, 2); //_testOutputHelper.WriteLine("Starting large message transfer."); //sw.Start(); //var result = proxy.Increment(tree).Result; //sw.Stop(); //Assert.Equal(tree.Leaf + 1, result.Leaf); //_testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds); clientRouter.Dispose(); clientTransport.Dispose(); factory.delete_participant(ref clientParticipant); serverRouter.Dispose(); serverTransport.Dispose(); factory.delete_participant(ref serverParticipant); }