示例#1
0
        static async Task Main()
        {
            Logger.LogInformation($"Starting load gen with the following settings:\r\n{Settings.Current}");

            try
            {
                ModuleClient moduleClient = await ModuleUtil.CreateModuleClientAsync(
                    Settings.Current.TransportType,
                    ModuleUtil.DefaultTimeoutErrorDetectionStrategy,
                    ModuleUtil.DefaultTransientRetryStrategy,
                    Logger);

                using (var timers = new Timers())
                {
                    Guid batchId = Guid.NewGuid();
                    Logger.LogInformation($"Batch Id={batchId}");

                    // setup the message timer
                    timers.Add(
                        Settings.Current.MessageFrequency,
                        Settings.Current.JitterFactor,
                        () => GenerateMessageAsync(moduleClient, batchId));

                    // setup the twin update timer
                    timers.Add(
                        Settings.Current.TwinUpdateFrequency,
                        Settings.Current.JitterFactor,
                        () => GenerateTwinUpdateAsync(moduleClient, batchId));

                    timers.Start();
                    (CancellationTokenSource cts, ManualResetEventSlim completed, Option <object> handler) = ShutdownHandler.Init(TimeSpan.FromSeconds(5), Logger);
                    Logger.LogInformation("Load gen running.");

                    await cts.Token.WhenCanceled();

                    Logger.LogInformation("Stopping timers.");
                    timers.Stop();
                    Logger.LogInformation("Closing connection to Edge Hub.");
                    await moduleClient.CloseAsync();

                    completed.Set();
                    handler.ForEach(h => GC.KeepAlive(h));
                    Logger.LogInformation("Load Gen complete. Exiting.");
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error occurred during load gen.\r\n{ex}");
            }
        }
示例#2
0
        static async Task Main()
        {
            ILogger logger = InitLogger().CreateLogger("loadgen");

            Log.Information($"Starting load gen with the following settings:\r\n{Settings.Current}");

            try
            {
                var client = await GetModuleClientWithRetryAsync();

                using (var timers = new Timers())
                {
                    Guid batchId = Guid.NewGuid();

                    // setup the message timer
                    timers.Add(
                        Settings.Current.MessageFrequency,
                        Settings.Current.JitterFactor,
                        () => GenerateMessageAsync(client, batchId));

                    // setup the twin update timer
                    timers.Add(
                        Settings.Current.TwinUpdateFrequency,
                        Settings.Current.JitterFactor,
                        () => GenerateTwinUpdateAsync(client, batchId));

                    timers.Start();
                    (CancellationTokenSource cts, ManualResetEventSlim completed, Option <object> handler) = ShutdownHandler.Init(TimeSpan.FromSeconds(5), logger);
                    Log.Information("Load gen running.");

                    await cts.Token.WhenCanceled();

                    Log.Information("Stopping timers.");
                    timers.Stop();
                    Log.Information("Closing connection to Edge Hub.");
                    await client.CloseAsync();

                    completed.Set();
                    handler.ForEach(h => GC.KeepAlive(h));
                    Log.Information("Load gen complete. Exiting.");
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error occurred during load gen.\r\n{ex}");
            }
        }
示例#3
0
        static async Task Main()
        {
            Microsoft.Extensions.Logging.ILogger logger = InitLogger().CreateLogger("loadgen");
            Log.Information($"Starting load run with the following settings:\r\n{Settings.Current.ToString()}");

            try
            {
                var retryPolicy = new RetryPolicy(TimeoutErrorDetectionStrategy, TransientRetryStrategy);
                retryPolicy.Retrying += (_, args) =>
                {
                    Log.Error($"Creating ModuleClient failed with exception {args.LastException}");
                    if (args.CurrentRetryCount < RetryCount)
                    {
                        Log.Information("Retrying...");
                    }
                };
                ModuleClient client = await retryPolicy.ExecuteAsync(() => InitModuleClient(Settings.Current.TransportType));

                using (var timers = new Timers())
                {
                    var    random     = new Random();
                    SHA256 sha        = SHA256Managed.Create();
                    var    bufferPool = new BufferPool();

                    // setup the message timer
                    timers.Add(
                        Settings.Current.MessageFrequency,
                        Settings.Current.JitterFactor,
                        () => GenMessage(client, random, sha, bufferPool));

                    // setup the twin update timer
                    timers.Add(
                        Settings.Current.TwinUpdateFrequency,
                        Settings.Current.JitterFactor,
                        () => GenTwinUpdate(client));
                    timers.Start();

                    (
                        CancellationTokenSource cts,
                        ManualResetEventSlim completed,
                        Option <object> handler
                    ) = ShutdownHandler.Init(TimeSpan.FromSeconds(5), logger);

                    Log.Information("Load gen running.");

                    await cts.Token.WhenCanceled();

                    Log.Information("Stopping timers.");
                    timers.Stop();
                    Log.Information("Closing connection to Edge Hub.");
                    await client.CloseAsync();

                    completed.Set();
                    handler.ForEach(h => GC.KeepAlive(h));

                    Log.Information("Load run complete. Exiting.");
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error occurred during load run. \r\n{ex.ToString()}");
            }
        }