예제 #1
0
        static string GetDefaultPackagePath(SquirtOptions options)
        {
            if (options.Rebuild)
            {
                BuildPackage(options.Configuration, options.Framework, options.Verbose);
            }
            var proj     = new DirectoryInfo(Directory.GetCurrentDirectory()).Name;
            var filePath = Path.Combine(Environment.CurrentDirectory, "bin", options.Configuration, options.Framework, proj) +
                           ".zip";

            if (!File.Exists(filePath))
            {
                throw new ArgumentException($"Could not find a package at {filePath}. Did you call 'dotnet lambda package'?");
            }

            return(filePath);
        }
예제 #2
0
        static async Task <int> SquirtAsync(SquirtOptions options)
        {
            options.Validate();
            var ctrlC = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, args) =>
            {
                Console.WriteLine("Beetles, abort!");
                args.Cancel = true;
                ctrlC.Cancel();
            };
            var verbose = options.Verbose ? (Action <object>)WriteVerbose : o => { };

            var timestamp = DateTimeOffset.UtcNow.ToString("yyyy-MM-dd_HHmmss");

            Console.WriteLine("Preparing battle plan...");
            var packagePath = options.PackagePath ?? GetDefaultPackagePath(options);

            var settings = LoadTypeInfo(options.Configuration, options.Framework, options.Name);

            var deployer = new LambdaDeployer(
                timestamp: timestamp,
                packagePath: packagePath,
                configurationType: settings.ConfigurationType,
                verbose: verbose);

            var rps      = options.RequestsPerSecond;
            var duration = Parser.Duration(options.Duration);

            Console.WriteLine($"Load testing at {rps}rps for {duration} using lambda {packagePath}");

            try
            {
                Console.WriteLine("Beetles, assemble!");
                await deployer.Deploy(options.MemorySize, settings.Name, ctrlC.Token);

                Console.WriteLine("Beetles, attack!");

                var lambdaControlPlane = new LambdaControlPlane(deployer.Topic, 600, detailsLog: verbose);

                var nullLoadTest = new LoadTest(
                    rps,
                    duration,
                    options.WarmUpTime != null ? Parser.Duration(options.WarmUpTime) : TimeSpan.Zero,
                    settings.StoryTeller,
                    lambdaControlPlane,
                    PrintLoadStep);

                var result = await nullLoadTest.RunAsync(ctrlC.Token);

                Console.WriteLine($"Beetles have returned in {result.Elapsed}.");
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception e)
            {
                WriteError($"An error occured - {e.Message}");

                WriteVerbose(e.ToString());
            }
            finally
            {
                Console.WriteLine("Calling back the beetles...");
                await deployer.Shutdown();
            }

            Console.WriteLine("It's goodbye from them, and it's goodbye from me!");
            return(0);
        }