Beispiel #1
0
            private async Task RunBench(string name, Func <Task <PerformanceResult[]> > act)
            {
                var spinner = new Spiner();

                spinner.Start();

                // native test
                var sw = Stopwatch.StartNew();

                PerformanceResult[] results = await act();

                var elapsed = sw.ElapsedMilliseconds;

                // results
                spinner.Stop();

                Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50)));
                Console.WriteLine($";; {name} results:\t\t");
                Console.WriteLine(string.Join("-", Enumerable.Repeat("-", 50)));
                Console.WriteLine($";; {"Overall(ms)",-15} {"OK",-10} {"Errors",-10} {"MIN(ms)",-10}{"MAX(ms)",-10}{"AVG(ms)",-10}{"Median",-10}");
                foreach (var result in results)
                {
                    Console.WriteLine(result);
                }

                var avgRuntime = (1000.0d / elapsed) * (_clients * _runs);

                Console.WriteLine($";; {name} run took {elapsed}ms for {_clients} clients * {_runs} queries: {avgRuntime:N0} queries per second.");
            }
Beispiel #2
0
        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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        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);
        }