static void Main(string[] args) { var cmd = CommandLineParameters.Parse(args); if (cmd == null || cmd.Benchmark != BenchmarkType.None) { BenchmarkRunner.Run <Stress>(); return; } Console.WriteLine($"Command Line: {cmd}"); if (cmd.IsServer) { StartServer(); StartClients(cmd); } if (cmd.IsClient) { BeginClient(cmd); } var waits = ProcessWaits.Select(p => new ProcessWaitHandle(p)).ToArray(); WaitHandle.WaitAll(waits); Teardown(); }
public static CommandLineParameters Parse(string[] args) { if (args.Length % 2 > 0 || args.Length == 0) { return(null); } var cmd = new CommandLineParameters(); for (var i = 0; i < args.Length; i += 2) { var key = args[i]; var val = args[i + 1]; switch (key) { case "-benchmark": cmd.Benchmark = Enum.Parse <BenchmarkType>(val, true); break; case "-client": cmd.IsClient = true; cmd.ClientIdentifier = val; break; case "-port": cmd.Port = int.Parse(val); break; case "-threads": cmd.ThreadCount = int.Parse(val); break; case "-requests": cmd.RequestCount = int.Parse(val); break; case "-workers": cmd.WorkerCount = int.Parse(val); break; case "-server": cmd.IsServer = true; cmd.ServerIdentifier = val; break; case "-progress": cmd.DisplayProgress = true; break; } } return(cmd); }
private static Process StartClientProcess(CommandLineParameters cmd) { cmd.Port = Stresser.Port; var assembly = Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe"); return(Process.Start(new ProcessStartInfo { FileName = assembly, Arguments = cmd.ToString() })); }
private static void BeginClient(CommandLineParameters cmd) { WaitForAllProcessesToStart.WaitOne(); if (cmd.Port != null) { Stresser.Port = cmd.Port.Value; } Stresser.ConcurrentRequests = cmd.ThreadCount ?? 1; Stresser.AuthenticationAttempts = cmd.RequestCount ?? 1000; Stresser.RequestTgt(); }
static async Task Main(string[] args) { var cmd = CommandLineParameters.Parse(args); if (cmd == null) { BenchmarkRunner.Run(typeof(Program).Assembly); return; } if (cmd.Benchmark == BenchmarkType.Timing) { BenchmarkRunner.Run <MessageBenchmarks>(); return; } if (cmd.Benchmark == BenchmarkType.Stress) { BenchmarkRunner.Run <StressAsReq>(); BenchmarkRunner.Run <StressTgsReq>(); return; } if (cmd.Benchmark == BenchmarkType.DH) { BenchmarkRunner.Run <BCryptDiffieHellmanBenchmarks>(); return; } Console.WriteLine($"Command Line: {cmd}"); if (cmd.IsServer) { await StartServer(); StartClients(cmd); } if (cmd.IsClient) { BeginClient(cmd); } var waits = ProcessWaits.Select(p => new ProcessWaitHandle(p)).ToArray(); WaitHandle.WaitAll(waits); Teardown(); }
private static void StartClients(CommandLineParameters cmd) { var workerCount = cmd.WorkerCount ?? 1; for (var i = 0; i < workerCount; i++) { var process = StartClientProcess(new CommandLineParameters { ClientIdentifier = Guid.NewGuid().ToString(), ThreadCount = cmd.ThreadCount <= 0 ? Environment.ProcessorCount * 4 : cmd.ThreadCount, Port = cmd.Port, RequestCount = cmd.RequestCount <= 0 ? 1000 : cmd.RequestCount }); ProcessWaits.Add(process); } Thread.Sleep(TimeSpan.FromSeconds(5)); WaitForAllProcessesToStart.Set(); }
private static void BeginClient(CommandLineParameters cmd) { WaitForAllProcessesToStart.WaitOne(); if (cmd.Port != null) { Stresser.Port = cmd.Port.Value; } Stresser.DisplayProgress = cmd.DisplayProgress; Stresser.ConcurrentRequests = cmd.ThreadCount ?? 1; Stresser.AuthenticationAttempts = cmd.RequestCount ?? 1000; var sw = Stopwatch.StartNew(); try { Stresser.RequestTgt(); } catch (AggregateException agg) { foreach (var ex in agg.InnerExceptions) { Console.WriteLine("[Client] " + ex); } } catch (Exception ex) { Console.WriteLine("[Client] " + ex); } var elapsed = sw.Elapsed; sw.Stop(); Console.WriteLine($"Client completed {Stresser.Successes}/{Stresser.ConcurrentRequests * Stresser.AuthenticationAttempts} requests in {elapsed}"); }
static async Task Main(string[] args) { var cmd = CommandLineParameters.Parse(args); if (cmd == null) { BenchmarkRunner.Run(typeof(Program).Assembly); return; } if (cmd.Benchmark == BenchmarkType.Timing) { BenchmarkRunner.Run <MessageBenchmarks>(); return; } if (cmd.Benchmark == BenchmarkType.Stress) { BenchmarkRunner.Run <StressAsReq>(); BenchmarkRunner.Run <StressTgsReq>(); return; } if (cmd.Benchmark == BenchmarkType.DH) { BenchmarkRunner.Run <BCryptDiffieHellmanBenchmarks>(); return; } if (cmd.Benchmark == BenchmarkType.Pac) { BenchmarkRunner.Run <PacEncodingBenchmarks>(); return; } Console.WriteLine($"Command Line: {cmd}"); if (cmd.IsServer) { await StartServer(); StartClients(cmd); Console.WriteLine("All clients started"); } if (cmd.IsClient) { BeginClient(cmd); } var list = SplitList(ProcessWaits.Select(p => new ProcessWaitHandle(p)).ToList(), 64); foreach (var waits in list) { if (waits.Count > 0) { WaitHandle.WaitAll(waits.ToArray()); } } Teardown(); Console.WriteLine("Tearing down"); if (cmd.IsServer) { Console.ReadKey(); } }