protected override async Task <int> Execute() { _clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value()) : 10; _runtime = RuntimeArg.HasValue() ? int.Parse(RuntimeArg.Value()) <= 1 ? 5 : int.Parse(RuntimeArg.Value()) : 5; _query = string.IsNullOrWhiteSpace(QueryArg.Value) ? string.Empty : QueryArg.Value; _runSync = SyncArg.HasValue(); _lookup = GetDnsLookup(); _lookup.EnableAuditTrail = false; _running = true; _settings = GetLookupSettings(); Console.WriteLine($"; <<>> Starting perf run with {_clients} clients running for {_runtime} seconds <<>>"); Console.WriteLine($"; ({_settings.Endpoints.Length} Servers, caching:{_settings.UseCache}, minttl:{_settings.MinTTL.TotalMilliseconds})"); _spinner = new Spiner(); _spinner.Start(); var sw = Stopwatch.StartNew(); var timeoutTask = Task.Delay(_runtime * 1000).ContinueWith((t) => { _running = false; }); var tasks = new List <Task>(); tasks.Add(timeoutTask); for (var clientIndex = 0; clientIndex < _clients; clientIndex++) { tasks.Add(ExcecuteRun()); } tasks.Add(CollectPrint()); await Task.WhenAny(tasks.ToArray()); double elapsedSeconds = sw.ElapsedMilliseconds / 1000d; // results _spinner.Stop(); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; results:\t\t"); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; run for {elapsedSeconds}sec {_clients} clients."); var successPercent = _errors == 0 ? 100 : _success == 0 ? 0 : (100 - ((double)_errors / (_success) * 100)); Console.WriteLine($";; {_errors:N0} errors {_success:N0} ok {successPercent:N2}% success."); var execPerSec = _allExcecutions / elapsedSeconds; var avgExec = _allAvgExec / _runtime; Console.WriteLine($";; {execPerSec:N2} queries per second."); Console.WriteLine($";;Log: clients created: {StaticLog.CreatedClients} arraysAllocated: {StaticLog.ByteArrayAllocations} arraysReleased: {StaticLog.ByteArrayReleases} queries: {StaticLog.ResolveQueryCount} queryTries: {StaticLog.ResolveQueryTries}"); return(0); }
protected override async Task <int> Execute() { _clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value()) : 10; if (_clients <= 0) { throw new ArgumentOutOfRangeException(nameof(ClientsArg)); } _tasks = TasksArg.HasValue() ? int.Parse(TasksArg.Value()) : 8; if (_clients <= 0) { throw new ArgumentOutOfRangeException(nameof(TasksArg)); } _runtime = RuntimeArg.HasValue() ? int.Parse(RuntimeArg.Value()) <= 1 ? 5 : int.Parse(RuntimeArg.Value()) : 5; _query = string.IsNullOrWhiteSpace(QueryArg.Value) ? string.Empty : QueryArg.Value; _runSync = SyncArg.HasValue(); _settings = GetLookupSettings(); _settings.EnableAuditTrail = false; _lookup = GetDnsLookup(_settings); _running = true; Console.WriteLine($"; <<>> Starting perf run with {_clients} (x{_tasks}) clients running for {_runtime} seconds <<>>"); Console.WriteLine($"; ({_settings.NameServers.Count} Servers, caching:{_settings.UseCache}, minttl:{_settings.MinimumCacheTimeout?.TotalMilliseconds}, maxttl:{_settings.MaximumCacheTimeout?.TotalMilliseconds})"); _spinner = new Spiner(); _spinner.Start(); var sw = Stopwatch.StartNew(); var timeoutTask = Task.Delay(_runtime * 1000).ContinueWith((t) => { _running = false; }); var tasks = new List <Task> { timeoutTask }; for (var clientIndex = 0; clientIndex < _clients; clientIndex++) { tasks.Add(ExcecuteRun(numTasks: _tasks)); } tasks.Add(CollectPrint()); await Task.WhenAny(tasks.ToArray()); double elapsedSeconds = sw.ElapsedMilliseconds / 1000d; // results _spinner.Stop(); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; results:\t\t"); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; run for {elapsedSeconds}sec {_clients} (x{_tasks}) clients."); var successPercent = _errors == 0 ? 100 : _success == 0 ? 0 : (100 - ((double)_errors / (_success) * 100)); Console.WriteLine($";; {_errors:N0} errors {_success:N0} ok {successPercent:N2}% success."); var execPerSec = _allExcecutions / elapsedSeconds; Console.WriteLine($";; {execPerSec:N2} queries per second."); return(0); }
protected override async Task <int> Execute() { var lines = File.ReadAllLines("names.txt"); _domainNames = new ConcurrentQueue <string>(lines.Select(p => p.Substring(p.IndexOf(',') + 1)).OrderBy(x => _randmom.Next(0, lines.Length * 2))); _clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value()) : 10; _runtime = RuntimeArg.HasValue() ? int.Parse(RuntimeArg.Value()) <= 1 ? 5 : int.Parse(RuntimeArg.Value()) : 5; _runSync = SyncArg.HasValue(); _settings = GetLookupSettings(); _settings.EnableAuditTrail = true; _settings.ThrowDnsErrors = false; _settings.ContinueOnDnsError = false; _lookup = GetDnsLookup(_settings); _running = true; Console.WriteLine($"; <<>> Starting random run with {_clients} clients running for {_runtime} seconds <<>>"); Console.WriteLine($"; ({_settings.NameServers.Count} Servers, caching:{_settings.UseCache}, minttl:{_settings.MinimumCacheTimeout?.TotalMilliseconds})"); _spinner = new Spiner(); _spinner.Start(); var sw = Stopwatch.StartNew(); var timeoutTask = Task.Delay(_runtime * 1000).ContinueWith((t) => { _running = false; }); var tasks = new List <Task> { timeoutTask }; for (var clientIndex = 0; clientIndex < _clients; clientIndex++) { tasks.Add(ExcecuteRun()); } tasks.Add(CollectPrint()); try { await Task.WhenAny(tasks.ToArray()); } catch (Exception ex) { Console.WriteLine(ex); } double elapsedSeconds = sw.ElapsedMilliseconds / 1000d; // results _spinner.Stop(); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; results:\t\t"); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; run for {elapsedSeconds}sec {_clients} clients."); //var successPercent = _errors == 0 ? 100 : _success == 0 ? 0 : (100 - (double)_success / (_errors * (double)_success)); var successPercent = _errors == 0 ? 100 : _success == 0 ? 0 : (100 - ((double)_errors / (_success) * 100)); Console.WriteLine($";; {_errors:N0} errors {_success:N0} ok {successPercent:N2}% success."); foreach (var code in _errorsPerCode.Keys) { Console.WriteLine($"{code,30}:\t {_errorsPerCode[code]}"); } var execPerSec = _allExcecutions / elapsedSeconds; Console.WriteLine($";; {execPerSec:N2} queries per second."); return(0); }
protected async Task Runner <TCacheValue>(Func <Task> task, params EventCounter <TCacheValue>[] handlings) { var spinner = new Spinner(); spinner.Start(); var swatch = Stopwatch.StartNew(); var tasks = new List <Task>(); int.TryParse(RuntimeArg.Value(), out int runtimeSeconds); var source = new CancellationTokenSource(runtimeSeconds * 1000); int.TryParse(NumberOfJobs.Value(), out int concurrentJobs); Console.WriteLine($"Displaying event counter for cache(s): {string.Join(", ", handlings.Select(p => p.Cache.Name))}; showing [local][remote] events."); try { var reportTask = Task.Run(async() => { while (true) { await Task.Delay(100); spinner.Message = ""; foreach (var h in handlings) { spinner.Message += h.Cache.Name + " " + string.Join(" ", GetStatus(new[] { h })); } //spinner.Message = string.Join(" ", GetStatus(handlings)); if (source.IsCancellationRequested) { return; } } }); while (!source.IsCancellationRequested) { tasks.Add(task()); if (tasks.Count >= concurrentJobs) { await Task.WhenAll(tasks); tasks.Clear(); } } await Task.WhenAll(tasks); // wait for all events to complete await Task.Delay(1000); } catch { throw; } finally { spinner.Stop(); var counter = 0; foreach (var status in GetStatus(handlings)) { counter++; Console.WriteLine($"Cache {counter} events received: {status}"); } Console.WriteLine($"Backplane stats: {CacheBackplane.MessagesSent} messages sent in {CacheBackplane.SentChunks} chunks; {CacheBackplane.MessagesReceived} messages received."); } }
protected override async Task <int> Execute() { _clients = ClientsArg.HasValue() ? int.Parse(ClientsArg.Value()) : 10; _runtime = RuntimeArg.HasValue() ? int.Parse(RuntimeArg.Value()) <= 1 ? 5 : int.Parse(RuntimeArg.Value()) : 5; _runSync = SyncArg.HasValue(); _lookup = GetDnsLookup(); _lookup.EnableAuditTrail = true; _running = true; _settings = GetLookupSettings(); Console.WriteLine($"; <<>> Starting random run with {_clients} clients running for {_runtime} seconds <<>>"); Console.WriteLine($"; ({_settings.Endpoints.Length} Servers, caching:{_settings.UseCache}, minttl:{_settings.MinTTL.TotalMilliseconds})"); _spinner = new Spiner(); _spinner.Start(); var sw = Stopwatch.StartNew(); var timeoutTask = Task.Delay(_runtime * 1000).ContinueWith((t) => { _running = false; }); var tasks = new List <Task> { timeoutTask }; for (var clientIndex = 0; clientIndex < _clients; clientIndex++) { tasks.Add(ExcecuteRun()); } tasks.Add(CollectPrint()); await Task.WhenAny(tasks.ToArray()); double elapsedSeconds = sw.ElapsedMilliseconds / 1000d; // results _spinner.Stop(); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; results:\t\t"); Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50))); Console.WriteLine($";; run for {elapsedSeconds}sec {_clients} clients."); //var successPercent = _errors == 0 ? 100 : _success == 0 ? 0 : (100 - (double)_success / (_errors * (double)_success)); var successPercent = _errors == 0 ? 100 : _success == 0 ? 0 : (100 - ((double)_errors / (_success) * 100)); Console.WriteLine($";; {_errors:N0} errors {_success:N0} ok {successPercent:N2}% success."); foreach (var code in _errorsPerCode.Keys) { Console.WriteLine($"{code,30}:\t {_errorsPerCode[code]}"); } var execPerSec = _allExcecutions / elapsedSeconds; Console.WriteLine($";; {execPerSec:N2} queries per second."); return(0); }