Example #1
1
		public void BenchmarkMessages()
		{
			var port = new Random().Next(20000, 60000);

			GlobalHost.Configuration.DefaultMessageBufferSize = 2000; // maximum number of messages to buffer
			GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null;
			GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(15); // auto set keepalive to 5

			var url = "http://localhost:" + port + "/";
			var server = WebApp.Start<Startup>(url);
			var client = new HubConnection(url + "s1");
			var proxy = client.CreateHubProxy("ISumService");
			client.Start().Wait();

			Assert.Equal(ConnectionState.Connected, client.State);

			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.Invoke<int>("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.Invoke<Tuple<long,long>>("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.Invoke<SumServiceTree>("Increment", tree).Result;
			sw.Stop();
			Assert.Equal(tree.Leaf + 1, result.Leaf);
			_testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds);

			client.Dispose();
			server.Dispose();
		}
Example #2
0
		public void BenchmarkMessages()
		{

			var host = StartServer();
			var factory = new WampChannelFactory();

			var channel = factory.ConnectToRealm("realm1")
				.WebSocketTransport("ws://127.0.0.1:8080/")
				//.MsgpackSerialization(new JsonSerializer { TypeNameHandling = TypeNameHandling.Auto })
				//.JsonSerialization(new JsonSerializer { TypeNameHandling = TypeNameHandling.Auto })
				.JsonSerialization()
				//.CraAuthentication(authenticationId: "peter", secret: "secret1")
				.Build();

			channel.RealmProxy.Monitor.ConnectionEstablished += (sender, eventArgs) => _testOutputHelper.WriteLine("Connected with ID " + eventArgs.SessionId);

			channel.Open().Wait();
				
			var proxy = channel.RealmProxy.Services.GetCalleeProxy<ISumService>(new CallerNameInterceptor());

			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.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);

			channel.Close();
			host.Dispose();
		}
Example #3
0
		public Task<SumServiceTree> Increment(SumServiceTree tree)
		{
			if (tree == null) return null;
			tree.Leaf++;
			if (tree.Children != null)
			{
				foreach (var child in tree.Children)
					Increment(child);
			}
			return Task.FromResult(tree);
		}
Example #4
0
		public static void FillTree(SumServiceTree tree, Random rand, int level = 3)
		{
			tree.Leaf = rand.Next(1000000000, 2000000000);

			if (level <= 0)
				return;

			tree.Children = new SumServiceTree[300];
			for (int i = 0; i < tree.Children.Length; i++)
			{
				tree.Children[i] = new SumServiceTree();
				FillTree(tree.Children[i], rand, level - 1);
			}
		}
Example #5
0
		public bool IsExactMatch(SumServiceTree tree, int diff)
		{
			if (Leaf + diff != tree.Leaf)
				return false;

			if (Children == null)
				return true;

			for (int i = 0; i < Children.Length; i++)
			{
				if (!Children[i].IsExactMatch(tree.Children[i], diff))
					return false;
			}
			return true;
		}
Example #6
0
		public void BenchmarkMessagesSoap()
		{
			string baseAddress = "http://localhost:12292/";
			var host = new ServiceHost(typeof(WcfWumService), new Uri(baseAddress));
			host.AddServiceEndpoint(typeof(IWcfSumService), new NetHttpBinding { MaxReceivedMessageSize = int.MaxValue }, "soap");
			host.Open();

			var factory = new ChannelFactory<IWcfSumService>(new NetHttpBinding { MaxReceivedMessageSize = int.MaxValue }, new EndpointAddress(baseAddress + "soap"));
			var proxy = factory.CreateChannel();

			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);

			((IDisposable)proxy).Dispose();
			factory.Close();
			host.Close();
		}
Example #7
0
 public Task <SumServiceTree> Increment(SumServiceTree tree)
 {
     if (tree == null)
     {
         return(null);
     }
     tree.Leaf++;
     if (tree.Children != null)
     {
         foreach (var child in tree.Children)
         {
             Increment(child);
         }
     }
     return(Task.FromResult(tree));
 }
Example #8
0
        public static void FillTree(SumServiceTree tree, Random rand, int level = 3)
        {
            tree.Leaf = rand.Next(1000000000, 2000000000);

            if (level <= 0)
            {
                return;
            }

            tree.Children = new SumServiceTree[300];
            for (int i = 0; i < tree.Children.Length; i++)
            {
                tree.Children[i] = new SumServiceTree();
                FillTree(tree.Children[i], rand, level - 1);
            }
        }
Example #9
0
        public bool IsExactMatch(SumServiceTree tree, int diff)
        {
            if (Leaf + diff != tree.Leaf)
            {
                return(false);
            }

            if (Children == null)
            {
                return(true);
            }

            for (int i = 0; i < Children.Length; i++)
            {
                if (!Children[i].IsExactMatch(tree.Children[i], diff))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #10
0
        public void BenchmarkMessages()
        {
            var host    = StartServer();
            var factory = new WampChannelFactory();

            var channel = factory.ConnectToRealm("realm1")
                          .WebSocketTransport("ws://127.0.0.1:8080/")
                          //.MsgpackSerialization(new JsonSerializer { TypeNameHandling = TypeNameHandling.Auto })
                          //.JsonSerialization(new JsonSerializer { TypeNameHandling = TypeNameHandling.Auto })
                          .JsonSerialization()
                          //.CraAuthentication(authenticationId: "peter", secret: "secret1")
                          .Build();

            channel.RealmProxy.Monitor.ConnectionEstablished += (sender, eventArgs) => _testOutputHelper.WriteLine("Connected with ID " + eventArgs.SessionId);

            channel.Open().Wait();

            var proxy = channel.RealmProxy.Services.GetCalleeProxy <ISumService>(new CallerNameInterceptor());

            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.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);

            channel.Close();
            host.Dispose();
        }
Example #11
0
        public void BenchmarkMessagesProtobuf()
        {
            var host       = StartServer();
            var factory    = new WampChannelFactory();
            var binding    = new ProtobufBinding();
            var connection = new WebSocket4NetBinaryConnection <ProtobufToken>("ws://localhost:8080/", binding);
            var channel    = factory.CreateChannel("realm1", connection, binding);

            channel.RealmProxy.Monitor.ConnectionEstablished += (sender, eventArgs) => _testOutputHelper.WriteLine("Connected with ID " + eventArgs.SessionId);

            channel.Open().Wait();

            var proxy = channel.RealmProxy.Services.GetCalleeProxy <ISumService>(new CallerNameInterceptor());

            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.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.True(tree.IsExactMatch(result, 1));
            _testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds);

            channel.Close();
            host.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();
		}
Example #13
0
		public Task<SumServiceTree> Increment(SumServiceTree tree)
		{
			return _service.Increment(tree);
		}
Example #14
0
 public Task <SumServiceTree> Increment(SumServiceTree tree)
 {
     return(_service.Increment(tree));
 }
Example #15
0
        public void BenchmarkMessagesJson()
        {
            string baseAddress = "http://localhost:12292/";
            var    host        = new ServiceHost(typeof(WcfWumService), new Uri(baseAddress));
            var    endpoint    = host.AddServiceEndpoint(typeof(IWcfSumService), new WebHttpBinding {
                MaxReceivedMessageSize = int.MaxValue
            }, "json");

            endpoint.EndpointBehaviors.Add(new WebHttpBehavior {
                DefaultOutgoingRequestFormat = WebMessageFormat.Json, DefaultOutgoingResponseFormat = WebMessageFormat.Json
            });
            host.Open();

            var factory = new ChannelFactory <IWcfSumService>(new WebHttpBinding {
                MaxReceivedMessageSize = int.MaxValue
            }, new EndpointAddress(baseAddress + "json"));

            factory.Endpoint.Behaviors.Add(new WebHttpBehavior {
                DefaultOutgoingRequestFormat = WebMessageFormat.Json, DefaultOutgoingResponseFormat = WebMessageFormat.Json
            });
            var proxy = factory.CreateChannel();

            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);

            ((IDisposable)proxy).Dispose();
            factory.Close();
            host.Close();
        }
		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();
		}
Example #17
0
        public void BenchmarkMessages()
        {
            var port = new Random().Next(20000, 60000);

            GlobalHost.Configuration.DefaultMessageBufferSize        = 2000;       // maximum number of messages to buffer
            GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null;
            GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(15); // auto set keepalive to 5

            var url    = "http://localhost:" + port + "/";
            var server = WebApp.Start <Startup>(url);
            var client = new HubConnection(url + "s1");
            var proxy  = client.CreateHubProxy("ISumService");

            client.Start().Wait();

            Assert.Equal(ConnectionState.Connected, client.State);

            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.Invoke <int>("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.Invoke <Tuple <long, long> >("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.Invoke <SumServiceTree>("Increment", tree).Result;

            sw.Stop();
            Assert.Equal(tree.Leaf + 1, result.Leaf);
            _testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds);

            client.Dispose();
            server.Dispose();
        }
Example #18
0
		public void BenchmarkMessagesProtobuf()
		{
			var host = StartServer();
			var factory = new WampChannelFactory();
			var binding = new ProtobufBinding();
			var connection = new WebSocket4NetBinaryConnection<ProtobufToken>("ws://localhost:8080/", binding);
			var channel = factory.CreateChannel("realm1", connection, binding);

			channel.RealmProxy.Monitor.ConnectionEstablished += (sender, eventArgs) => _testOutputHelper.WriteLine("Connected with ID " + eventArgs.SessionId);

			channel.Open().Wait();

			var proxy = channel.RealmProxy.Services.GetCalleeProxy<ISumService>(new CallerNameInterceptor());

			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.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.True(tree.IsExactMatch(result, 1));
			_testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds);

			channel.Close();
			host.Dispose();
		}