private static void DoTenUrlsThreeTimesEachAroundTheWorldInParallel(bool runLocal = false)
        {
            var serverEndpoints = new IPEndPoint[0];

            if (runLocal)
            {
                serverEndpoints = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9096) };
            }
            else
            {
                //these server names are temporary - to run this test use your own
                var servers = new string[]
                {
                    "t5westus.cloudapp.net",
                    "t5eastus.cloudapp.net",
                    "t5northeu.cloudapp.net",
                    "t5westeu.cloudapp.net",
                    "t5soeastasia.cloudapp.net",
                    "t5eastasia.cloudapp.net"
                };

                serverEndpoints = new IPEndPoint[servers.Length];
                for (int i = 0; i < servers.Length; i++)
                {
                    var host = Dns.GetHostAddresses(servers[i]);
                    var ip   = (from n in host where n.AddressFamily == AddressFamily.InterNetwork select n).First();
                    serverEndpoints[i] = new IPEndPoint(ip, 9096);
                }
            }

            float subscriptionRate          = 2.0f; //oversubscribed
            int   logPollingIntervalSeconds = 2;

            using (DistributedClient <ISpeedTest> client = Distributor.Connect <ISpeedTest>(typeof(SpeedTest),
                                                                                            subscriptionRate,
                                                                                            logPollingIntervalSeconds,
                                                                                            LogLevel.Debug,
                                                                                            serverEndpoints))
            {
                for (int i = 0; i < 3; i++)
                {
                    var sw = Stopwatch.StartNew();
                    Console.WriteLine(@"round:{0}", i + 1);
                    var loopResult = client.ForEach(TestUrls, (url, proxy) => proxy.GetSpeed(url));
                    foreach (var result in loopResult.Results)
                    {
                        Console.WriteLine(@"r:{0}, s:{1}, b:{2}, on: {3}, u:{4}",
                                          result.ResponseTimeMs, result.ReadStreamTimeMs, result.ResponseLength, result.MachineName, result.Url);
                    }
                    sw.Stop();
                    Console.WriteLine("Total elapsed time: {0}", sw.ElapsedMilliseconds);
                    Console.WriteLine(string.Empty);
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //wait for other host to start
            Thread.Sleep(3000);
            var port     = 9096;
            var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9096);

            float subscriptionRate          = 0.5f;
            int   logPollingIntervalSeconds = 1;

            using (DistributedClient <ITest> client = Distributor.Connect <ITest>(typeof(Test),
                                                                                  subscriptionRate,
                                                                                  logPollingIntervalSeconds,
                                                                                  LogLevel.Debug,
                                                                                  endpoint))
            {
                client.LogMessageReceived += ClientOnLogMessageReceived;

                //set data on each server node - one call per server node
                client.OncePerNode(new Tuple <int, int>(501, 3001),
                                   (source, proxy) => proxy.SetFromTo(source.Item1, source.Item2));

                var distributedLoopResult = client.For(0, 10,
                                                       (index, proxy) => proxy.GetName(index.ToString(CultureInfo.InvariantCulture)));

                //in a real program, deal with distributedLoopResult.Exceptions if any

                var results = distributedLoopResult.Results.ToArray();
                foreach (var result in results)
                {
                    Console.WriteLine(result);
                }
                client.SweepLogs(); //one last log sweep

                //now do it again with results from first using ForEach
                var distributedLoopResult2 = client.ForEach(results,
                                                            (source, proxy) => proxy.GetName(source));

                //in a real program, deal with distributedLoopResult2.Exceptions if any

                var results2 = distributedLoopResult2.Results.ToArray();
                foreach (var result in results2)
                {
                    Console.WriteLine(result);
                }
                client.SweepLogs(); //one last log sweep
            }

            Console.WriteLine("");
            Console.WriteLine("done - hit enter to quit");
            Console.ReadLine();
        }