{"id":66768,"date":"2023-02-16T14:55:46","date_gmt":"2023-02-16T13:55:46","guid":{"rendered":""},"modified":"2023-07-25T17:43:39","modified_gmt":"2023-07-25T16:43:39","slug":"how-you-should-be-load-testing-your-background-services","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-gb\/industry\/blog\/technetuk\/2023\/02\/16\/how-you-should-be-load-testing-your-background-services\/","title":{"rendered":"How you should be load testing your background services"},"content":{"rendered":"\n
Like many developers, I have followed or attempted to follow best practices and patterns when building APIs and services. Then when it comes to deployment, I deploy my API to my favourite infrastructure on Azure, picked an appropriate SKU and left it there. The use of load testing tools was seen something someone else could do or something a little too specialist for me or complicated for me. But there was always this niggling feeling that what I had built may not perform well enough.<\/p>\n\n\n\n
Load testing is a vital step in the lifecycle of a service – for a team to know<\/em> that their service can take the load required of it.<\/p>\n\n\n\n With the advent of Azure Load Testing, almost all of the infrastructural challenges of building load tests have been removed. You just have to be able to write or adapt JMeter JMX files and upload them into a load test. I recommend looking at this tutorial<\/a> for how to use Azure load testing against a web app.<\/p>\n\n\n\n The use of load testing means it is now quite straightforward to test web apps and APIs, but it is less clear how to effectively load test and monitor a background or asynchronous service and to know when all of the background processing has completed and also that all requests have been processed correctly.<\/p>\n\n\n\n This repository contains an Azure Load Testing sample that tests and monitors an asynchronous service. This is supplied with a sample application against which the load test can be run. This sample application comprises some APIs which push messages to a queue and then later processes these messages from the queue.<\/p>\n\n\n\n This test:<\/p>\n\n\n\n In this way, the load test executes for as long as it takes to process all of the data and the load test can then pull in the custom metric to graph the items remaining to be processed into the load test results. Thus giving the tester a more complete picture of how long an asynchronous process takes to complete a given number of requests.<\/p>\n\n\n\n All JMeter load tests use the notion of thread groups<\/em>. These are blocks of HTTP requests to be sent. Standard load tests start with a low number of threads<\/em> and ramp up to a fixed number and continue for a given period of time. This style of thread group will send many requests to the target and this will vary depending on how fast the target can keep up with the number of requests.<\/p>\n\n\n\n The thread groups in this test are while loops<\/em> and can send a fixed number of requests or can keep sending requests until a condition is met. This is useful as the use of these while loops can firstly send a fixed number of requests and secondly run the test until the background queue<\/em> of requests is empty.<\/p>\n\n\n\n This load test has 2 thread groups:<\/p>\n\n\n\n A simpler arrangement could be to just use a single thread group and to let the test complete once all requests are sent. But you would then have to separately look at the metrics of the system under test to establish when the service has completely finished processing. But, the 2 thread groups give a more complete picture.<\/p>\n\n\n\n To allow the load test to get a more complete picture of the remaining items to be processed, the system under test regularly polls the remaining item count and generates a custom metric<\/a> – this metric can then be pulled into the load test run.<\/p>\n\n\n\n The load test definition JMX file is in this folder here<\/a>.<\/p>\n\n\n\n It requires three parameters to be set in the Azure Load Test parameters<\/em> section:<\/p>\n\n\n\n The system under test comprises 4 Azure functions:<\/p>\n\n\n\n All of the above functions are built into a single function app for a single deployment. These have a number of application settings that are discussed in a later setting.<\/p>\n\n\n\n To be clear, this is a demonstration application, but it allows you to test the load test before using it on a real target service. But elements of this could be added to an existing service to support this form of testing.<\/p>\n\n\n\n As can be seen from above, the first phase of the test rapidly increases the number of items to be processed. Once these have been sent, the background processes start working away. The slope is more shallow as it is taking longer to process each message than it did to create. In a production system, attempts should be made to optimise this background processing. Also Azure Functions when triggered on Service Bus queue also scale out to more instances – thus doing more work in parallel. The scale limit of the funtion app can be changed to tune this. See below:<\/p>\n\n\n\n As can be seen above, this is the report from the load test:<\/p>\n\n\n\n So far there is not a deployment script, but this needs:<\/p>\n\n\n\n Deployment Steps:<\/p>\n\n\n\n It may also be useful (for test purposes) to limit the scale out of the function as service bus is used by the function runtime to scale out to multiple instances – thus getting more work done in parallel. This is what is needed for a real workload, but for this demonstration, limiting the function to a few instances (in the scale out section) is useful to be more representative of a background processing activity.<\/p>\n\n\n\n With the use of a novel form of JMeter JMX file, combined with Azure Load Testing and Application Insights custom metrics allows the load testing and progress monitoring of background processes in an efficient manner. The reports then generated in Azure Load Testing give a view of the progress of the background process.<\/p>\n\n\n\n Load testing is a vital step in the lifecycle of a service. It’s how a team knows\u00a0that their service can take the load required of it.<\/p>\n","protected":false},"author":430,"featured_media":21801,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"_classifai_error":"","_classifai_text_to_speech_error":"","footnotes":""},"categories":[594],"post_tag":[128,1935,519],"content-type":[],"coauthors":[2030],"class_list":["post-66768","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technetuk","tag-azure","tag-github","tag-technet-uk"],"yoast_head":"\n<\/a>Azure Load Test to the rescue<\/h2>\n\n\n\n
<\/a>What is special about background processes?<\/h2>\n\n\n\n
<\/a>How does load testing solve these problems?<\/h2>\n\n\n\n
\n
<\/a>Load Test Structure<\/h2>\n\n\n\n
<\/a><\/figure>\n\n\n\n\n
\n
<\/a><\/figure>\n\n\n\n<\/a>Demonstration System Under Test<\/h2>\n\n\n\n
<\/a><\/figure>\n\n\n\n\n
<\/a>Custom metric<\/h2>\n\n\n\n
<\/a><\/figure>\n\n\n\n
<\/a><\/figure>\n\n\n\n<\/a>Load Test Sample Run<\/h2>\n\n\n\n
<\/a><\/figure>\n\n\n\n\n
<\/a>Deploying the sample application<\/h2>\n\n\n\n
\n
\n
<\/a>Function App Configuration Items needed<\/h2>\n\n\n\n
\n
<\/a>Summary<\/h2>\n\n\n\n
Learn more<\/h2>\n\n\n
\n
<\/a><\/h2>\n","protected":false},"excerpt":{"rendered":"