๐Ÿš€

Gatling (JVM & TypeScript Load Testing)

๋น„๋™๊ธฐ Netty ์—”์ง„ ๊ธฐ๋ฐ˜ ์ดˆ๊ณ ์„ฑ๋Šฅ ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ์™€ TypeScript/Java DSL ์‹œ๋‚˜๋ฆฌ์˜ค, Assertion SLO ๊ฒ€์ฆ ๋ฐ ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ HTML ๋ฆฌํฌํŠธ๋ฅผ ์ œ๊ณตํ•˜๋Š” Gatling ์น˜ํŠธ์‹œํŠธ

--views
๋‹จ์ˆ˜:
#gatling#load-testing#typescript#jvm#performance#benchmark#ci-cd#http์ตœ์ข… ์—…๋ฐ์ดํŠธ: 2026-11-29

๐Ÿ’ป ์‹œ์Šคํ…œ ์„ค์น˜ ๋ฐ ์‹คํ–‰ ์š”๊ตฌ์‚ฌ์–‘ (System Requirements)

์ตœ์‹  Gatling TypeScript/JavaScript SDK (@gatling.io/core, @gatling.io/http) ๋ฐ JVM Engine ๊ธฐ์ค€ ์š”๊ตฌ์‚ฌ์–‘์ž…๋‹ˆ๋‹ค.

๊ตฌ๋ถ„์ตœ์†Œ ์‚ฌ์–‘ (Minimum)๊ถŒ์žฅ ์‚ฌ์–‘ (Recommended)
์šด์˜์ฒด์ œ (OS)Linux, macOS, WindowsUbuntu 24.04 LTS (ulimit -n 65535 ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ ๊ถŒ์žฅ)
Java ๋Ÿฐํƒ€์ž„ (ํ•„์ˆ˜)OpenJDK 11 ~ 25 (LTS)OpenJDK 21 ๋˜๋Š” 25 LTS (TypeScript SDK๋„ ๋‚ด๋ถ€ ์—”์ง„ ์‹คํ–‰์— JDK ํ•„์š”)
Node.js (TS/JS ์‚ฌ์šฉ ์‹œ)Node.js 20+ / npm 10+Node.js 24 LTS / npm 11+ (@gatling.io/core, @gatling.io/http)
CPU / RAM2 vCPU / 2 GB RAM4 ~ 8+ vCPU / 4 GB ~ 16 GB RAM (Netty ๋น„๋™๊ธฐ I/O ๊ธฐ๋ฐ˜ ๊ณ ๋™์‹œ์„ฑ ์ฒ˜๋ฆฌ)

์ตœ์‹  ๋ฒ„์ „ ์„ค์น˜ (TypeScript ํ”„๋กœ์ ํŠธ ๊ธฐ์ค€)

# 1. Java 21+ ํ™•์ธ (Gatling ์—”์ง„ ์‹คํ–‰ ํ•„์ˆ˜)
java -version

# 2. TypeScript Gatling ํ”„๋กœ์ ํŠธ ์ดˆ๊ธฐํ™” ๋˜๋Š” ๊ณต์‹ ํ…œํ”Œ๋ฆฟ ํด๋ก 
mkdir gatling-perf && cd gatling-perf
npm init -y
npm install --save-dev @gatling.io/core @gatling.io/http @gatling.io/cli typescript

๐Ÿง  Gatling ๋ฉ˜ํƒˆ ๋ชจ๋ธ (Protocol ยท Scenario ยท Injection Profile ยท Assertions)

Gatling์€ ์Šค๋ ˆ๋“œ๋ฅผ ๊ฐ€์ƒ ์‚ฌ์šฉ์ž๋งˆ๋‹ค 1๊ฐœ์”ฉ ์ ์œ ํ•˜์ง€ ์•Š๊ณ  Netty/Akka ๋น„๋™๊ธฐ ์ด๋ฒคํŠธ ๋ฃจํ”„ ์œ„์—์„œ ์ˆ˜๋งŒ ๋ช…์˜ ๊ฐ€์ƒ ์‚ฌ์šฉ์ž(Virtual Users)๋ฅผ ๊ฐ€๋ณ๊ฒŒ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ํ•ฉ๋‹ˆ๋‹ค.

[httpProtocol] (BaseURL, ๊ณตํ†ต ํ—ค๋”, ์ปค๋„ฅ์…˜ ํ’€)
      โ”‚
      โ–ผ
[Scenario (์‚ฌ์šฉ์ž ์—ฌ์ •)] โ”€โ”€โ–ถ exec(GET /api) โ”€โ”€โ–ถ check(status=200, jsonPath) โ”€โ”€โ–ถ pause(1s)
      โ”‚
      โ–ผ
[Injection Profile] (rampUsers / constantUsersPerSec / stressPeakUsers)
      โ”‚
      โ–ผ
[Assertions & HTML Report] (p95 < 300ms, failedRequests < 1% -> CI Exit Code)

๐Ÿš€ ๋‹จ๊ณ„๋ณ„ ์‹ค์ „ ์‹ค์Šต (Step-by-Step)

[1๋‹จ๊ณ„] ํ—ฌ๋กœ์›”๋“œ: TypeScript ์ฒซ ๋ถ€ํ•˜ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ (basic.gatling.ts)

@gatling.io/core์™€ @gatling.io/http๋ฅผ ์‚ฌ์šฉํ•ด ํƒ€์ž… ์•ˆ์ „ํ•œ HTTP ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

// src/basic.gatling.ts
import { simulation, scenario, rampUsers } from "@gatling.io/core";
import { http, status } from "@gatling.io/http";

export default simulation((setUp) => {
  // 1. ๊ณตํ†ต HTTP ํ”„๋กœํ† ์ฝœ ์„ค์ •
  const httpProtocol = http
    .baseUrl("https://httpbin.org")
    .acceptHeader("application/json")
    .userAgentHeader("Gatling-TS-Perf/1.0");

  // 2. ์‚ฌ์šฉ์ž ์‹œ๋‚˜๋ฆฌ์˜ค ์ •์˜
  const scn = scenario("HealthAndGetScenario")
    .exec(
      http("GET_JSON_Sample")
        .get("/json")
        .check(status().is(200))
    )
    .pause(1);

  // 3. 10์ดˆ ๋™์•ˆ 20๋ช…์˜ ๊ฐ€์ƒ ์‚ฌ์šฉ์ž๋ฅผ ์ ์ง„ ํˆฌ์ž…(Ramp-up)
  setUp(
    scn.injectOpen(rampUsers(20).during(10))
  ).protocols(httpProtocol);
});
# Gatling CLI๋กœ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ์‹คํ–‰ (์™„๋ฃŒ ํ›„ target/gatling/.../index.html ๋ฆฌํฌํŠธ ์ž๋™ ์ƒ์„ฑ)
npx gatling run --simulation basic

[2๋‹จ๊ณ„] ํ•ต์‹ฌ ๊ธฐ๋Šฅ: CSV Feeder ๋ฐ์ดํ„ฐ ์ฃผ์ž…, JSON ์ถ”์ถœ ๋ฐ ์ƒ๊ด€๊ด€๊ณ„(Correlation)

์‹ค๋ฌด์—์„œ๋Š” ๋กœ๊ทธ์ธ ์‘๋‹ต์—์„œ ํ† ํฐ์ด๋‚˜ orderId๋ฅผ ์ถ”์ถœ(saveAs)ํ•ด ๋‹ค์Œ ์š”์ฒญ์— ์ „๋‹ฌํ•˜๊ณ , csv Feeder๋กœ ๋งค ์‚ฌ์šฉ์ž๋งˆ๋‹ค ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ์ž…ํ•ฉ๋‹ˆ๋‹ค.

import { simulation, scenario, csv, jsonPath, constantUsersPerSec } from "@gatling.io/core";
import { http, status, StringBody } from "@gatling.io/http";

export default simulation((setUp) => {
  const httpProtocol = http.baseUrl("https://api.example.com");

  // resources/users.csv (username,password ์ปฌ๋Ÿผ) ์ˆœํ™˜ ์ฝ๊ธฐ
  const userFeeder = csv("users.csv").circular();

  const orderFlow = scenario("AuthenticatedOrderFlow")
    .feed(userFeeder)
    .exec(
      http("Login")
        .post("/auth/login")
        .header("Content-Type", "application/json")
        .body(StringBody('{"username":"#{username}","password":"#{password}"}'))
        .check(status().is(200))
        .check(jsonPath("$.accessToken").saveAs("authToken"))
    )
    .pause(1, 3)
    .exec(
      http("CreateOrder")
        .post("/v1/orders")
        .header("Authorization", "Bearer #{authToken}")
        .body(StringBody('{"sku":"PRO-PLAN","qty":1}'))
        .check(status().in(200, 201))
    );

  // Open Workload Model: 30์ดˆ๊ฐ„ ์ดˆ๋‹น 15๋ช…์˜ ์‹ ๊ทœ ์‚ฌ์šฉ์ž ์œ ์ž… ์œ ์ง€
  setUp(
    orderFlow.injectOpen(constantUsersPerSec(15).during(30))
  ).protocols(httpProtocol);
});

[3๋‹จ๊ณ„] ์‹ค๋ฌด ์‘์šฉ: CI/CD์šฉ assertions SLO ๊ฒŒ์ดํŠธ & Open/Closed ๋ชจ๋ธ ์„ ํƒ

์‹œ๋ฎฌ๋ ˆ์ด์…˜ ์ข…๋ฃŒ ์‹œ ์‘๋‹ต ์‹œ๊ฐ„(p95/p99)๊ณผ ์„ฑ๊ณต๋ฅ  ๊ธฐ์ค€์„ assertions๋กœ ๊ฑธ์–ด๋‘๋ฉด, ๊ธฐ์ค€ ๋ฏธ๋‹ฌ ์‹œ Gatling์ด 0์ด ์•„๋‹Œ ์ข…๋ฃŒ ์ฝ”๋“œ๋ฅผ ๋ฐ˜ํ™˜ํ•ด CI ํŒŒ์ดํ”„๋ผ์ธ์„ ์ž๋™ ์ฐจ๋‹จํ•ฉ๋‹ˆ๋‹ค.

import { simulation, scenario, global, rampUsers } from "@gatling.io/core";
import { http, status } from "@gatling.io/http";

export default simulation((setUp) => {
  const httpProtocol = http.baseUrl("http://localhost:8080");
  const scn = scenario("ApiSloGate").exec(http("GetItems").get("/api/items").check(status().is(200)));

  setUp(
    scn.injectOpen(rampUsers(100).during(30))
  )
    .protocols(httpProtocol)
    .assertions(
      global().responseTime().percentile(95).lt(250),    // p95 < 250ms
      global().successfulRequests().percent().gt(99.5)   // ์„ฑ๊ณต๋ฅ  > 99.5%
    );
});

๐Ÿ“Š ์›Œํฌ๋กœ๋“œ ๋ชจ๋ธ & CLI ์น˜ํŠธ์‹œํŠธ

๊ตฌ๋ถ„๋ฉ”์„œ๋“œ / ๋ช…๋ น์–ด์šฉ๋„ ๋ฐ ํŠน์ง•
Open ModelinjectOpen(constantUsersPerSec(50).during(60))์›น์‚ฌ์ดํŠธ์ฒ˜๋Ÿผ ์™ธ๋ถ€ ์‚ฌ์šฉ์ž๊ฐ€ ๊ณ„์† ๋“ค์–ด์˜ค๋Š” ํ˜„์‹ค ํŠธ๋ž˜ํ”ฝ(๋„์ฐฉ๋ฅ  ์ค‘์‹ฌ)
Closed ModelinjectClosed(constantConcurrentUsers(100).during(60))์ฝœ์„ผํ„ฐ/๋Œ€๊ธฐ์—ด์ฒ˜๋Ÿผ ๋™์‹œ ์ ‘์†์ž ์ˆ˜๋ฅผ ๊ณ ์ • ์œ ์ง€ํ•  ๋•Œ ์‚ฌ์šฉ
HTML ๋ฆฌํฌํŠธnpx gatling run --simulation <name>์‹คํ–‰ ์™„๋ฃŒ ํ›„ index.html ๋Œ€์‹œ๋ณด๋“œ ๊ฒฝ๋กœ ์ž๋™ ์ถœ๋ ฅ
Java/Kotlin Gradle./gradlew gatlingRunJVM ๋ฐฑ์—”๋“œ ํŒ€๊ณผ ๋™์ผ ์ €์žฅ์†Œ์—์„œ ์‹คํ–‰ ์‹œ ํ‘œ์ค€ ๋ช…๋ น์–ด

โœ… ์‹ค๋ฌด ์ฃผ์˜์‚ฌํ•ญ & ํ”„๋กœ๋•์…˜ ์ฒดํฌ๋ฆฌ์ŠคํŠธ

  1. Open vs Closed ๋ชจ๋ธ ๊ตฌ๋ถ„: ์ผ๋ฐ˜ ์›น/API ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ์—๋Š” ๋ฐ˜๋“œ์‹œ injectOpen์„ ์‚ฌ์šฉํ•˜์„ธ์š”. injectClosed๋Š” ์„œ๋ฒ„๊ฐ€ ๋А๋ ค์งˆ์ˆ˜๋ก ์š”์ฒญ ์†๋„๋„ ๊ฐ™์ด ์ค„์–ด๋“ค์–ด Coordinated Omission(์„ฑ๋Šฅ ์ €ํ•˜ ์€ํ) ํ˜„์ƒ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. Feeder ๋ฐ์ดํ„ฐ ์ถฉ๋ถ„์„ฑ ํ™•๋ณด: csv("users.csv").queue() ๋ชจ๋“œ์—์„œ ๋ฐ์ดํ„ฐ ํ–‰ ์ˆ˜๋ณด๋‹ค ๋งŽ์€ ๊ฐ€์ƒ ์‚ฌ์šฉ์ž๋ฅผ ํˆฌ์ž…ํ•˜๋ฉด ํ…Œ์ŠคํŠธ๊ฐ€ ์ฆ‰์‹œ ์ค‘๋‹จ๋ฉ๋‹ˆ๋‹ค. ๋Œ€๋Ÿ‰ ๋ถ€ํ•˜ ์‹œ .circular() ๋˜๋Š” .random()์„ ์‚ฌ์šฉํ•˜์„ธ์š”.
  3. ์›œ์—…(Warm-up) ๊ตฌ๊ฐ„ ๋ถ„๋ฆฌ: JVM ๊ธฐ๋ฐ˜ ์„œ๋ฒ„๋ฅผ ํ…Œ์ŠคํŠธํ•  ๋•Œ๋Š” JIT ์ปดํŒŒ์ผ๊ณผ ์ปค๋„ฅ์…˜ ํ’€ ์›Œ๋ฐ์—…์„ ์œ„ํ•ด ๋ณธ ๋ถ€ํ•˜ ์ „์— 15~30์ดˆ๊ฐ„์˜ ๋‚ฎ์€ Ramp-up ๊ตฌ๊ฐ„์„ ๋ฐ˜๋“œ์‹œ ๋‘์–ด์•ผ ์ •ํ™•ํ•œ p99 ์ง€ํ‘œ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๐Ÿ’ฌ

์˜๊ฒฌ ๋ฐ ์งˆ๋ฌธ

0
0 / 1500