JMeter, k6 หรือ Locust?
เลือกให้ถูกก่อนเริ่ม Test
ไม่มี Tool ไหนดีที่สุดในทุกสถานการณ์ และการเลือกผิดอาจทำให้เสียเวลาหลายสัปดาห์ กับ Script ที่ดูแลยาก หรือ Report ที่ไม่ตอบโจทย์ทีม บทความนี้เปรียบเทียบ 5 Tools พร้อมโค้ดตัวอย่างจริง และแนวทางเลือกตามสถานการณ์ของแต่ละทีม
→ เลือก JMeter (GUI-based, ชุมชนใหญ่, Plugin เยอะ)
→ เลือก k6 (Code-first, CI/CD friendly, Cloud support)
→ เลือก Locust (Python native, Distributed ready)
→ เลือก Gatling (Scala DSL, Real-time HTML reports)
JMeter เป็น Tool ที่ใช้กันอย่างแพร่หลายที่สุด รองรับ Protocol หลากหลาย ไม่ว่าจะเป็น HTTP, HTTPS, JDBC, LDAP, FTP, JMS มี GUI ที่ใช้งานง่าย และรองรับการรัน Script ผ่าน Command Line สำหรับ CI/CD ได้
# รัน JMeter Test Plan แบบ Non-GUI (สำหรับ CI/CD)
jmeter -n \
-t test-plan.jmx \
-l results.jtl \
-e -o ./report \
-JBASE_URL=https://api.example.com \
-JTHREADS=500 \
-JDURATION=300
- มี GUI ใช้งานง่าย ไม่ต้องเขียน Code
- รองรับ Protocol หลากหลายมากที่สุด
- Community ใหญ่มาก หา Plugin และ Support ง่าย
- Distributed Testing รองรับ Master-Slave
- HTML Report สร้างได้อัตโนมัติ
- กิน Memory สูง (Java-based)
- Script ดูแลรักษายาก (XML format)
- ไม่เหมาะกับ Modern Web App ที่ซับซ้อน
- Learning curve สูงสำหรับ Advanced Feature
k6 ออกแบบมาให้ Developer เขียน Test ได้ง่ายด้วย JavaScript โดยมี Performance overhead ต่ำมาก รองรับ Output ไปยัง Grafana, InfluxDB, Datadog และมี k6 Cloud สำหรับ Distributed Testing
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '3m', target: 200 }, // Ramp up
{ duration: '5m', target: 2000 }, // Push to limit
{ duration: '3m', target: 0 }, // Recovery
],
thresholds: {
'http_req_duration': ['p(99)<3000'],
'http_req_failed': ['rate<0.05'],
},
};
export default function main() {
const payload = JSON.stringify({
username: 'test_user',
action: 'purchase',
});
const res = http.post(
'https://api.example.com/order',
payload,
{ headers: { 'Content-Type': 'application/json' } }
);
check(res, {
'order created': (r) => r.status === 201,
});
sleep(1);
}
- JavaScript ES6 — Developer เขียนได้ทันที
- Resource ต่ำมาก รัน VU เยอะได้บน Machine เดียว
- Integrate กับ Grafana, InfluxDB, Datadog ได้
- CI/CD friendly — รัน Docker ได้เลย
- k6 Cloud สำหรับ Distributed Testing
- ไม่มี GUI ต้องเขียน Code ทั้งหมด
- รองรับ Protocol น้อยกว่า JMeter
- Browser automation ยังจำกัด
Locust ให้เขียน User Behavior เป็น Pure Python ทำให้ยืดหยุ่นมาก มี Web UI สำหรับ Monitor และรองรับ Distributed Mode ได้โดยใช้ Worker Nodes หลายเครื่อง
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 3) # Think time 1–3 วินาที
def on_start(self):
"""เรียกครั้งเดียวเมื่อ User เริ่มต้น"""
self.login()
def login(self):
self.client.post('/auth/login', json={
'username': 'testuser',
'password': 'password123'
})
@task(3) # Weight 3 — เรียกบ่อยกว่า 3 เท่า
def browse_products(self):
self.client.get('/products')
@task(1) # Weight 1
def checkout(self):
self.client.post('/checkout', json={'cart_id': 'abc123'})
- Pure Python — ยืดหยุ่น ทำ Custom Logic ได้ทุกอย่าง
- มี Web UI แบบ Real-time ใช้งานง่าย
- Distributed Testing รองรับ Worker หลายเครื่อง
- ทีม Python ใช้ได้ทันทีโดยไม่ต้องเรียนใหม่
- ต้องรู้ Python — ไม่เหมาะกับ Non-developer
- Report ไม่ละเอียดเท่า Gatling
- GIL ของ Python อาจจำกัด Performance ของ Master
Gatling ใช้ Scala DSL ที่อ่านง่ายมาก และสร้าง HTML Report แบบ Interactive ที่สวยงามที่สุดในบรรดา Tools ทั้งหมด รองรับ Async/Non-blocking ทำให้รัน Virtual User ได้มากโดยใช้ Thread น้อย
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class BasicSimulation extends Simulation {
val httpProtocol = http
.baseUrl("https://api.example.com")
.acceptHeader("application/json")
val scn = scenario("Load Test")
.exec(http("Get Products")
.get("/products")
.check(status.is(200))
.check(responseTimeInMillis.lte(2000)))
.pause(1)
setUp(
scn.inject(
rampUsers(1000).during(5 minutes)
)
).protocols(httpProtocol)
}
- HTML Report สวยงาม Interactive ที่สุด
- Non-blocking — รัน VU เยอะได้ด้วย Thread น้อย
- Scala DSL อ่านง่าย ดูแลได้ง่าย
- Async architecture — Performance สูงมาก
- ต้องรู้ Scala — Learning curve สูง
- Community เล็กกว่า JMeter และ k6
- Enterprise features ต้องซื้อ License
Artillery ใช้ YAML ในการเขียน Scenario ทำให้ non-developer เขียนได้ง่าย รองรับ HTTP, WebSocket, Socket.io และ gRPC รวมถึง Artillery Cloud สำหรับ Distributed Testing บน Cloud ได้โดยตรง
config:
target: 'https://api.example.com'
phases:
- duration: 120
arrivalRate: 10
name: 'Warm-up'
- duration: 300
arrivalRate: 100
name: 'Peak Load'
ensure:
thresholds:
- http.response_time.p99: 3000
- http.request_rate: 100
scenarios:
- name: 'Browse and Purchase'
flow:
- get:
url: '/products'
expect:
- statusCode: 200
- think: 2
- post:
url: '/cart/add'
json:
productId: 'prod_123'
quantity: 1
- YAML config — อ่านง่าย เขียนเร็ว
- รองรับ WebSocket และ Socket.io ดีที่สุด
- Artillery Cloud — Distributed Test บน AWS ได้
- Plugin Ecosystem สำหรับ Node.js ครบ
- Community เล็กกว่า k6 และ JMeter
- Complex Scenario อาจต้องเขียน JS เพิ่ม
- Report ไม่สวยเท่า Gatling
Comparison Matrix
| Feature | JMeter | k6 | Locust | Gatling | Artillery |
|---|---|---|---|---|---|
| Script Language | Groovy/XML | JavaScript | Python | Scala/Java | YAML/JS |
| GUI | ✓ Full GUI | ✗ | ◑ Web UI | ✗ | ✗ |
| CI/CD Integration | ◑ | ✓ Best | ✓ | ✓ | ✓ |
| Distributed Testing | ✓ | ✓ Cloud | ✓ | ✓ Enterprise | ✓ Cloud |
| HTML Report | ✓ | ◑ Grafana | ◑ Basic | ✓ Best | ◑ |
| Protocol Support | ✓ Most | ◑ HTTP/WS/gRPC | ◑ HTTP/Custom | ◑ HTTP/WS | ◑ HTTP/WS |
| Learning Curve | Medium | Low | Low | High | Low |
| Cost | Free | Free + Cloud | Free | Free + Enterprise | Free + Cloud |