Skip to main content
Tweeted twitter.com/StackCodeReview/status/1281785343562350592
added 48 characters in body
Source Link
Kixoka
  • 143
  • 5

Also this is running in .Net Framework 4.8..

Also this is running in .Net Framework 4.8..

added 91 characters in body
Source Link
Kixoka
  • 143
  • 5

I am trying to mimic the number to users hitting the system through the RunLoad method.

I am trying to mimic the number to users hitting the system through the RunLoad method.

Source Link
Kixoka
  • 143
  • 5

Creating an app to simulate load

I am writing an app that is supposed to simulate load on our web api and NServiceBus(particular) service. This is the first time I am writing an application like this. It appears to run ok, however it takes a few seconds before anything shows up in the console window. Is there a better way to do this?

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Press any key to start...");
        Console.ReadKey();
        Console.WriteLine();

        RunLoad(100);

        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
    }

    private static void RunLoad(int loadSize)
    {
        Parallel.For(0, loadSize, i =>
        {
            RunTasks();
        });
    }

    public static async Task RunTasks()
    {
        var tasks = new List<Task>
        {
            GetLoanByLoanId("7000002050"),
            GetEnvelopesForLoan("7000002077"),
            GetLoanDataByLoanId("7000002072")

        };

        await Task.WhenAll(tasks);
    }

    private static async Task GetLoanByLoanId(string loanNumber)
    {
        await Task.Run(() => {
            var svc = new WebApiService();
            var msg1 = svc.GetLoanByLoanId(loanNumber);
            if (string.IsNullOrWhiteSpace(msg1)) return;
            Console.WriteLine($"GL {loanNumber}: {msg1.Length}");
        });
    }

    private static async Task GetLoanDataByLoanId(string loanNumber)
    {
        await Task.Run(() => {
            var svc = new WebApiService();
            var msg1 = svc.GetLoanDataByLoanId(loanNumber);
            if (string.IsNullOrWhiteSpace(msg1)) return;
            Console.WriteLine($"GLD {loanNumber}: {msg1.Length}");
        });
    }

    private static async Task GetEnvelopesForLoan(string loanNumber)
    {
        await Task.Run(() => {
            var svc = new WebApiService();
            var msg1 = svc.GetEnvelopesForLoan(loanNumber);
            if (string.IsNullOrWhiteSpace(msg1)) return;
            Console.WriteLine($"GEFL {loanNumber}: {msg1.Length}");
        });
    }

}
}