Nugget 6: Load Test WEB API with NBomber
This note incursions into load testing WEB API endpoints using a novel framework, designed to test Pull and Push scenarios regardless of the protocol used (HTTP/WebSockets/AMQP, etc).
For this example, a Web API controller (SuppliersController) was created with two similar endpoints. The system is based on the Northwind database. The difference between these endpoints is that GetSuppliers() projects suppliers and their products into data transfer objects using AutoMapper, and the second one, GetUserSuppliers() returns a collection of entities ignoring reference looping and the context is configured for no proxy creation.
To use NBomber create a console application and add the following packages:
To load test the above endpoints a class SupplierControllerTest was added to the project. Note that the client requires authorization to use these endpoints This is not required but adds some realism to the test. NBomber collects information from the execution of the scenario lambda expression. A scenario is capable of running steps providing the possibility of creating workflows.
Virtual users execute a scenario, these are execution threads that run the scenario and are discarded when done. In these simulations, the rate represents the number of visual users employed to run the scenario.
Three simulations are combined in this test:
Ramp up from 0 to 20, where (RampingInject), the NBomber scheduler will be activated
every second(by injection interval) to inject a new Scenario copy.
This simulation will continue ramping up the injection rate from 0 to 20 until the end duration.Simulation(Inject) will keep injecting with the injection rate of 20 copies per 1 sec for 1 minute.
The last simulation(RampingInject) starts smoothly ramping down the injection rate from 20 to 0 copies.
The result is shown below. I feel the sample data is not very complex and the results are similar, although you can see that the standard deviation in the Entity test is significantly smaller showing more consistency.
This initial incursion in the use of NBomber does not even scratch the surface of this framework's potential to load testing. Because we are using the HttpClient we can also test MVC controllers.
Comments
Post a Comment