Esempio n. 1
0
        /// <summary>
        /// Entry point
        /// </summary>
        /// <param name="args">Arguments provided to the program</param>
        public static void Main(string[] args)
        {
            string testType          = "getdata";
            string ringMasterAddress = "127.0.0.1:99";
            string path = "/Performance";

            var assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var builder      = new ConfigurationBuilder().SetBasePath(Path.GetDirectoryName(assemblyPath)).AddJsonFile("appSettings.json");

            appSettings = builder.Build();

            if (args.Length > 0)
            {
                testType = args[0].ToLower();
            }

            if (args.Length > 1)
            {
                ringMasterAddress = args[1];
            }

            if (args.Length > 2)
            {
                path = args[2];
            }

            bool useSecureConnection = false;

            X509Certificate[] clientCertificates         = null;
            X509Certificate[] acceptedServerCertificates = null;

            if (bool.Parse(appSettings["SSL.UseSSL"]))
            {
                useSecureConnection = true;
                string[] clientCertificateThumbprints = appSettings["SSL.ClientCerts"].Split(new char[] { ';', ',' });
                clientCertificates         = RingMasterClient.GetCertificatesFromThumbPrintOrFileName(clientCertificateThumbprints);
                acceptedServerCertificates = Certificates.GetDecodedCertificates(appSettings["SSL.ServerCerts"]);

                foreach (var certificate in clientCertificates)
                {
                    Trace.TraceInformation($"Client certificate: subject={certificate.Subject} thumbprint={certificate.GetCertHashString()}");
                }

                foreach (var certificate in acceptedServerCertificates)
                {
                    Trace.TraceInformation($"Server certificate: subject={certificate.Subject} thumbprint={certificate.GetCertHashString()}");
                }
            }
            else
            {
                Trace.TraceInformation("Not using SSL");
            }

            var performanceTest = new RingMasterPerformance();

            performanceTest.TestPath                       = path;
            performanceTest.TimeStreamId                   = ulong.Parse(appSettings["TimeStream"]);
            performanceTest.MaxConcurrency                 = int.Parse(appSettings["MaxConcurrency"]);
            performanceTest.MaxDataSize                    = int.Parse(appSettings["MaxDataSize"]);
            performanceTest.MinDataSize                    = int.Parse(appSettings["MinDataSize"]);
            performanceTest.MinChildrenPerNode             = int.Parse(appSettings["MinChildrenPerNode"]);
            performanceTest.MaxChildrenPerNode             = int.Parse(appSettings["MaxChildrenPerNode"]);
            performanceTest.BatchLength                    = int.Parse(appSettings["BatchLength"]);
            performanceTest.MaxAllowedCodePoint            = int.Parse(appSettings["MaxAllowedCodePoint"]);
            performanceTest.MaxGetChildrenEnumerationCount = int.Parse(appSettings["MaxGetChildrenEnumerationCount"]);
            performanceTest.MaxSetOperations               = int.Parse(appSettings["MaxSetOperations"]);
            performanceTest.MaxNodes                       = int.Parse(appSettings["MaxNodes"]);
            performanceTest.TestMaxRunTimeInSeconds        = int.Parse(appSettings["TestMaxRunTimeInSeconds"]);

            int requestTimeout = int.Parse(appSettings["RequestTimeout"]);

            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            var serverSpec = new RingMasterClient.ServerSpec
            {
                Endpoints           = SecureTransport.ParseConnectionString(ringMasterAddress),
                UseSecureConnection = useSecureConnection,
            };

            if (useSecureConnection)
            {
                serverSpec.ClientCertificate              = clientCertificates[0];
                serverSpec.AcceptedServerCertificates     = acceptedServerCertificates;
                serverSpec.MustCheckCertificateRevocation = false;
                serverSpec.MustCheckCertificateTrustChain = false;
            }

            var clientConfiguration = new RingMasterClient.Configuration
            {
                DefaultTimeout = TimeSpan.FromMilliseconds(requestTimeout),
            };

            var cancellation = new CancellationTokenSource();

            cancellation.CancelAfter(TimeSpan.FromSeconds(performanceTest.TestMaxRunTimeInSeconds));

            try
            {
                using (var client = new RingMasterClient(serverSpec, clientConfiguration, instrumentation: null, watcher: null, cancellationToken: CancellationToken.None))
                    using (var ringMaster = client.OpenTimeStream(performanceTest.TimeStreamId))
                    {
                        if (testType == "setdata")
                        {
                            performanceTest.SetDataPerformanceTest(ringMaster).Wait();
                        }
                        else if (testType == "create")
                        {
                            int numNodes = 500000;

                            if (args.Length > 3)
                            {
                                numNodes = int.Parse(args[3]);
                            }

                            performanceTest.CreatePerformanceTest(ringMaster, numNodes);
                        }
                        else if (testType == "createflat")
                        {
                            int numNodes = 1000000;

                            if (args.Length > 3)
                            {
                                numNodes = int.Parse(args[3]);
                            }

                            performanceTest.CreateFlatPerformanceTest(ringMaster, numNodes);
                        }
                        else if (testType == "getchildren")
                        {
                            int maxChildren = 1000;

                            if (args.Length > 3)
                            {
                                maxChildren = int.Parse(args[3]);
                            }

                            performanceTest.GetChildrenPerformanceTest(ringMaster, maxChildren);
                        }
                        else if (testType == "delete")
                        {
                            performanceTest.DeletePerformanceTest(ringMaster).Wait();
                        }
                        else if (testType == "scheduleddelete")
                        {
                            performanceTest.ScheduledDeletePerformanceTest(ringMaster);
                        }
                        else if (testType == "connect")
                        {
                            int numConnections = 100;

                            if (args.Length > 3)
                            {
                                numConnections = int.Parse(args[3]);
                            }

                            var configuration = new SecureTransport.Configuration
                            {
                                UseSecureConnection          = useSecureConnection,
                                ClientCertificates           = clientCertificates,
                                ServerCertificates           = acceptedServerCertificates,
                                CommunicationProtocolVersion = RingMasterCommunicationProtocol.MaximumSupportedVersion,
                            };

                            IPEndPoint[] endpoints = SecureTransport.ParseConnectionString(ringMasterAddress);

                            performanceTest.ConnectPerformanceTest(configuration, endpoints, numConnections);
                        }
                        else if (testType == "exists")
                        {
                            performanceTest.ExistsPerformanceTest(ringMaster).Wait();
                        }
                        else if (testType == "watchers")
                        {
                            int maxWatchers = 1000;
                            if (args.Length > 3)
                            {
                                maxWatchers = int.Parse(args[3]);
                            }

                            performanceTest.WatcherPerformanceTest(ringMaster, maxWatchers, cancellation).Wait();
                        }
                        else
                        {
                            performanceTest.GetDataPerformanceTest(ringMaster, cancellation).Wait();
                        }
                    }
            }
            catch (OperationCanceledException)
            {
            }
            catch (AggregateException ex)
            {
                if (!ex.Flatten().InnerExceptions.Any(e => e is OperationCanceledException))
                {
                    throw ex;
                }
            }
        }
Esempio n. 2
0
 public void Watchers()
 {
     RingMasterPerformance.Main(new[] { "watchers" });
 }
Esempio n. 3
0
 public void GetData()
 {
     RingMasterPerformance.Main(new[] { "getdata" });
 }
Esempio n. 4
0
 public void Create()
 {
     RingMasterPerformance.Main(new[] { "create" });
 }