We are planning to create C# load test framework, where we can make concurrent calls to our IO based API (Cache / Database / File), thus test them under load and following are the possible options:
Use
Async-Await
, with the scheduler hintTaskCreationOptions.LongRunning
, thus ensuring that we havebackground process
for each request initiated and thus genuinely test our API under load. Also will help us in aggregating the final results in an efficient manner as we would get the details of eachTask
returned postAsync
call, something similar to:void Main() { List<Task<long>> taskList = new List<Task<long>>(); for (int i = 0; i < 500; i++) { taskList.Add(TestLoadAsync()); } Task.WaitAll(taskList.ToArray()); long averageTime = taskList.Average(t => t.Result); } public static async Task<long> TestLoadAsync() { // Returns the total time taken using Stop Watch in the same module return await Task.Factory.StartNew(() => // Call IO API, TaskCreationOptions.LongRunning); }
Second option is using
System.Diagnostics
Process.Start
as shown underneath:void Main() { for (int i = 0; i < 500; i++) { System.Diagnostics.Process.Start("LoadAPI.exe"); } } "LoadAPI.exe" public class LoadAPI { public static void Main() { LoadAPI api = new LoadAPI(); api.TestLoadAPI(); // Register the details of stop watch time in database, for further analysis } public void TestLoadAPI() { // Call IO API } }
Important set of questions which need to be answered are:
- Which is a better approach and Why ?
- Does the standard load testing frameworks use a similar strategy ?
I am posting the question to understand the various viewpoints and have a in depth discussion in my organisation, in my understanding we shall use the:
- Async-Await as that's the natural mechanism for IO based concurrent calls
- In using Process.Start we are possibly loading the OS by creating a costly process, which would be starving each other and not the best mechanism for IO calls
- Standard load testing frameworks use the background processes as created by Async -Await
- Windows as an OS, which is a Multi threaded architecture, invoking multiple processes using
process.start
is not the correct way to load test
Please share your view to have a better insight on the topic