2.11Stress and Simulation Testing (Performance Testing)
When developing application systems that are intended for the internet or that need to withstand concurrent access from many users, performance stress testing and automated API simulation testing become critical steps before deployment. Through the report metrics obtained from these two types of testing, we can optimize the code before the system goes live and ensure that it meets the minimum go-live requirements.
Using the official website of the Furion framework as an example, perform stress testing:
var stressTestHarnessResult = await httpRemoteService.StressTestHarnessAsync("https://furion.net/");Console.WriteLine(stressTestHarnessResult.ToString()); // Print the stress test resultsTest result overview:
Stress Test Harness Result: Total Requests: 100 // Total number of requests Total Time (s): 7.95 // Total time (seconds) Successful Requests: 100 // Number of successful requests Failed Requests: 0 // Number of failed requests QPS: 12.58 // Queries per second (QPS) Min RT (ms): 676.38 // Minimum response time (ms) Max RT (ms): 7,419.72 // Maximum response time (ms) Avg RT (ms): 3,314.94 // Average response time (ms) P10 RT (ms): 1,288.82 // P10 response time (ms) P25 RT (ms): 2,057.10 // P25 response time (ms) P50 RT (ms): 3,064.56 // P50 response time (ms) P75 RT (ms): 4,100.03 // P75 response time (ms) P90 RT (ms): 5,026.08 // P90 response time (ms) P95 RT (ms): 7,330.71 // P95 response time (ms) P99 RT (ms): 7,416.20 // P99 response time (ms) P99.99 RT (ms): 7,419.72 // P99.99 response time (ms)The stressTestHarnessResult variable is of type StressTestHarnessResult, which contains the following properties and methods:
-
Properties:
TotalRequests: Total number of requests (longtype).TotalTimeInSeconds: Total time in seconds (doubletype).SuccessfulRequests: Number of successful requests (longtype).FailedRequests: Number of failed requests (longtype).QueriesPerSecond: Queries per second (QPS) (doubletype).MinResponseTime: Minimum response time (ms) (doubletype).MaxResponseTime: Maximum response time (ms) (doubletype).AverageResponseTime: Average response time (ms) (doubletype).Percentile10ResponseTime:P10response time (ms) (doubletype).Percentile25ResponseTime:P25response time (ms) (doubletype).Percentile50ResponseTime:P50response time (ms) (doubletype).Percentile75ResponseTime:P75response time (ms) (doubletype).Percentile90ResponseTime:P90response time (ms) (doubletype).Percentile95ResponseTime:P95response time (ms) (doubletype).Percentile99ResponseTime:P99response time (ms) (doubletype).Percentile9999ResponseTime:P99.99response time (ms) (doubletype).
-
Methods:
ToString(): Outputs a detailed report string with indentation.
By default, the stress test executes 1 round, each containing 100 concurrent requests, with a maximum degree of concurrency of 100. To obtain more accurate test results, you can adjust these parameters as needed:
var stressTestHarnessResult = await httpRemoteService.SendAsync(HttpRequestBuilder.StressTestHarness("https://furion.net/") .SetNumberOfRequests(1000) // Set the number of concurrent requests .SetNumberOfRounds(5) // Set the number of stress test rounds .SetMaxDegreeOfParallelism(500)); // Set the maximum degree of parallelism// In most cases, you only need to set the number of concurrent requestsvar stressTestHarnessResult = await httpRemoteService.StressTestHarnessAsync("https://furion.net/", 500);var stressTestHarnessResult = await httpRemoteService.SendAsync(HttpRequestBuilder.StressTestHarness("https://furion.net/", 500));