Example #1
0
 public async Task WriteHeaderAsync()
 {
     if (await NeedsHeader().ConfigureAwait(false))
     {
         await WriteLineAsync(TelemetryMetrics.GetHeader()).ConfigureAwait(false);
     }
 }
        public PerfTestRunner(
            ResultWriter writer,
            int timeSeconds,
            Client.TransportType transportType,
            int messageSizeBytes,
            int maximumParallelOperations,
            int scenarioInstances,
            string authType,
            int poolSize,
            string scenario,
            string runId,
            Func <PerfScenarioConfig, PerfScenario> scenarioFactory)
        {
            _log                = writer;
            _timeSeconds        = timeSeconds;
            _transportType      = transportType;
            _messageSizeBytes   = messageSizeBytes;
            _parallelOperations = maximumParallelOperations;
            _n               = scenarioInstances;
            _authType        = authType;
            _poolSize        = poolSize;
            _scenarioFactory = scenarioFactory;
            _tests           = new PerfScenario[_n];

            TelemetryMetrics.SetStaticConfigParameters(runId, _timeSeconds, _transportType, _messageSizeBytes, _parallelOperations, _n, _authType, _poolSize, scenario);

            string poolInfo = "";

            if (_poolSize > 0)
            {
                poolInfo = $"(pooled, {_poolSize} connections)";
            }
            Console.WriteLine($"Running {_timeSeconds}s test. ({_transportType}{poolInfo} {authType})");
            Console.WriteLine($"  {_n} operations ({_parallelOperations} parallel) with {_messageSizeBytes}B/message.");
        }
Example #3
0
 public Task WriteAsync(TelemetryMetrics m)
 {
     return(WriteLineAsync(m.ToString()));
 }
Example #4
0
        public static int Main(string[] args)
        {
            Console.WriteLine("IoT Client Performance test");

            if (args.Length < 1)
            {
                Help();
                return(-1);
            }

            int    param_counter = 0;
            int    t             = 10;
            string o             = null;
            string p             = "mqtt";
            int    s             = 128;
            int    l             = 100;
            int    n             = 1;
            string a             = "sas";
            int    c             = -1;
            string i             = null;
            string f             = null;

            while (param_counter + 1 < args.Length)
            {
                switch (args[param_counter])
                {
                case "--":
                    break;

                case "-t":
                    t = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-o":
                    o = args[++param_counter];
                    break;

                case "-p":
                    p = args[++param_counter];
                    break;

                case "-s":
                    s = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-l":
                    l = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-n":
                    n = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-a":
                    a = args[++param_counter];
                    break;

                case "-c":
                    c = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-i":
                    i = args[++param_counter];
                    break;

                case "-f":
                    f = args[++param_counter];
                    break;

                default:
                    Console.WriteLine($"Unknown parameter: {args[param_counter]}.");
                    return(-1);
                }

                param_counter++;
            }

            if (f == null)
            {
                Console.Error.WriteLine("Missing -f <scenario> parameter.");
                Help();
                return(-1);
            }

            if (i == null)
            {
                i = $"{DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.ffZ")}_dotNet_{f}";
            }

            Tuple <string, Func <PerfScenarioConfig, PerfScenario> > scenario;
            Func <PerfScenarioConfig, PerfScenario> scenarioFactory;

            if (!s_scenarios.TryGetValue(f, out scenario))
            {
                Console.Error.WriteLine($"Unknown scenario: {f}");
                return(-1);
            }

            scenarioFactory = scenario.Item2;

            Client.TransportType transportType;
            if (!s_transportDictionary.TryGetValue(p, out transportType))
            {
                Console.Error.WriteLine($"Unknown transport type: {p}");
                return(-1);
            }

            ResultWriter resultWriter;

            if (o == null)
            {
                resultWriter = new ResultWriterConsole();
            }
            else
            {
                resultWriter = new ResultWriterFile(o, TelemetryMetrics.GetHeader());
            }

            Console.CancelKeyPress += delegate
            {
                // Make sure we flush the log before the process is terminated.
                Console.Write("Aborted. Writing output . . . ");
                resultWriter.FlushAsync().GetAwaiter().GetResult();
                Console.WriteLine("OK");
            };

            var runner = new PerfTestRunner(
                resultWriter,
                t,
                transportType,
                s,
                l,
                n,
                a,
                c,
                f,
                i,
                scenarioFactory);

            try
            {
                runner.RunTestAsync().GetAwaiter().GetResult();
            }
            finally
            {
                Console.Write("Writing output . . . ");
                resultWriter.FlushAsync().GetAwaiter().GetResult();
                Console.WriteLine("OK");
            }

            return(0);
        }