Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Gatling

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use Gatling". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use Gatling.

Before discussing Gatling, let's take a look at the theory, the two types of performance testing, load testing and stress testing:

* * load testing (Load Testing): * * load testing is mainly used to test whether the software system meets the design goal of the requirements document, such as the maximum number of concurrent users supported by the software within a certain period of time, the error rate of software requests, etc., and mainly tests the performance of the software system.

* * stress test (Stress Testing): * * the main purpose of stress test is to test whether the hardware system meets the performance goals designed in the requirements document, for example, the system's cpu utilization, memory utilization, disk I / O throughput, network throughput, etc. The biggest difference between stress test and load test lies in the test purpose.

Introduction to Gatling

Gatling is a powerful load testing tool. It is designed for ease of use, maintainability and high performance.

Out of the box, Gatling comes with excellent support for the HTTP protocol, making it the tool of choice for load testing any HTTP server. Because the core engine is actually protocol agnostic, it is possible to support other protocols. For example, Gatling currently provides JMS support.

As long as the underlying protocol (such as HTTP) can be implemented in a non-blocking manner, the architecture of Gatling is asynchronous. This architecture can implement the virtual user as a message rather than a dedicated thread. Therefore, running thousands of concurrent virtual users is not a problem.

Gatling Quick start practice

1. Create Spring Boot application and provide RESTful API for testing > https://github.com/ChinaSilence/gatling-test.git

If you have your own tested Web application, you can ignore this step!

2. Start the database

The sample code in Github relies on PostgresSQL, so the easiest way to start the database first is to use Docker:

Docker run-d\-- name postgres\-e POSTGRES_DB=gatling\-e POSTGRES_USER=gatling\-e POSTGRES_PASSWORD=gatling123\-p 5432 POSTGRES_USER=gatling 5432\ postgres

3. Install the scala environment in IDEA

Install the scala plug-in

Install scala SDK

4. Write performance test scripts

Every Gatling test inherits the Simulation class, in which you can use Gatling Scala DSL to declare a list of scenarios. The goal is to run 30 clients and send 1000 requests at the same time. First, the client adds data to the database by calling the POST / persons method; then, it tries to query the data using id by calling the GET / persons/ {id} method.

Class ApiGatlingSimulationTest extends Simulation {val scn = scenario ("AddAndFindPersons"). Repeat (1000, "n") {exec (http ("AddPerson-API") .post ("http://localhost:8080/persons") .header (" Content-Type "," application/json ") .body (StringBody (" {"firstName": "John$ {n}", "lastName": "Smith$ {n}", "birthDate": "1980-01-01") "address": {"country": "pl", "city": "Warsaw", "street": "Test$ {n}", "postalCode": "02-200", "houseNo": ${n}} "") .check (status.is (200)) .pause (Duration.apply (5, TimeUnit.MILLISECONDS))} .repeat (1000) "n") {exec (http ("GetPerson-API") .get ("http://localhost:8080/persons/${n}") .check (status.is (200)} setUp (scn.inject (atOnceUsers (30) .maxDuration (FiniteDuration.apply (10," minutes "))}

5. Run the Spring Boot application

6. Run the test script

Configure Maven plug-in parameters

Io.gatling gatling-maven-plugin ${gatling-plugin.version} com.anoyi.test.ApiGatlingSimulationTest / Users/admin/code/gatling

Perform a test

Mvn gatling:execute

7. View the test report

Global report

Single interface detail report

At this point, I believe you have a deeper understanding of "how to use Gatling". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report