gatling

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Gatling

Gatling

Gatling is a powerful load testing tool. It is designed for ease of use, maintainability, and high performance. It uses an asynchronous (Akka/Netty) architecture that allows generating huge load from a single machine.
Gatling是一款强大的负载测试工具,它专为易用性、可维护性和高性能设计。它采用异步(Akka/Netty)架构,单台机器即可生成海量负载。

When to Use

适用场景

  • High Throughput: When you need to simulate 10k+ users from a single laptop.
  • Complex Scenarios: The DSL (Domain Specific Language) allows describing very complex user journeys.
  • JVM Shops: If your team uses Java/Scala/Kotlin.
  • 高吞吐量需求:当你需要通过一台笔记本电脑模拟10000+用户时。
  • 复杂场景:其DSL(领域特定语言)可用于描述非常复杂的用户操作流程。
  • JVM技术栈团队:如果你的团队使用Java/Scala/Kotlin。

Quick Start (Java)

快速入门(Java版)

java
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

public class BasicSimulation extends Simulation {

  HttpProtocolBuilder httpProtocol = http
    .baseUrl("http://computer-database.gatling.io")
    .acceptHeader("application/json");

  ScenarioBuilder scn = scenario("BasicSimulation")
    .exec(http("request_1").get("/computers"));

  {
    setUp(
      scn.injectOpen(atOnceUsers(10))
    ).protocols(httpProtocol);
  }
}
java
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

public class BasicSimulation extends Simulation {

  HttpProtocolBuilder httpProtocol = http
    .baseUrl("http://computer-database.gatling.io")
    .acceptHeader("application/json");

  ScenarioBuilder scn = scenario("BasicSimulation")
    .exec(http("request_1").get("/computers"));

  {
    setUp(
      scn.injectOpen(atOnceUsers(10))
    ).protocols(httpProtocol);
  }
}

Core Concepts

核心概念

Simulation

模拟(Simulation)

The definition of the load test. Contains the HTTP configuration, the Scenario (steps users take), and the Injection Profile (how users arrive).
负载测试的定义,包含HTTP配置、场景(用户执行的步骤)和注入配置文件(用户的到达方式)。

Feeders

数据注入器(Feeders)

Mechanisms to inject data (valid usernames, search terms) from CSV/JSON into the virtual users so they don't all look identical.
用于从CSV/JSON中注入数据(有效用户名、搜索词)到虚拟用户的机制,使虚拟用户的行为不会完全一致。

Best Practices (2025)

2025年最佳实践

Do:
  • Use the Java/Kotlin DSL: Scala was the default, but Java/Kotlin SDKs are now first-class and easier for most teams.
  • Record User Journeys: Use the Gatling Recorder (proxy) to capture browser interactions, then clean up the code.
Don't:
  • Don't ignore reports: Gatling generates beautiful HTML reports at the end. Open
    index.html
    to see the response time distribution graphs.
建议
  • 使用Java/Kotlin DSL:Scala曾是默认选择,但现在Java/Kotlin SDK已成为一等公民,对大多数团队来说更易用。
  • 录制用户操作流程:使用Gatling Recorder(代理工具)捕获浏览器交互,然后清理代码。
不建议
  • 不要忽略测试报告:Gatling在测试结束后会生成美观的HTML报告,打开
    index.html
    即可查看响应时间分布图表。

References

参考资料