검사, 임계값 및 메트릭
응답 검증을 위한 k6 검사와 성능 목표를 정의하는 임계값을 이해합니다.
검사, 임계값 및 메트릭은(는) CoddyKit의 무료 Load Testing & Performance Benchmarking (JMeter & k6) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Load Testing & Performance Benchmarking (JMeter & k6) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Validate Test Responses
When performance testing, simply sending requests isn't enough. We need to confirm that the server is responding correctly, not just quickly.
This is where checks come in. Checks allow you to validate the content and status of server responses.
Simple k6 Checks
A basic check in k6 confirms a condition about the response. If the condition is false, the check fails, but the test continues.
Here's how to check if an HTTP response status is 200 (OK):
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const res = http.get('https://test.k6.io');
check(res, {
'status is 200': (r) => r.status === 200,
});
console.log(`Status: ${res.status}`);
}Validate Response Content
You can also check for specific text or data within the response body. This is crucial for ensuring the server provides the expected information.
Let's check if the response body contains a specific string:
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const res = http.get('https://test.k6.io');
check(res, {
'body contains "k6.io"': (r) => r.body.includes('k6.io'),
});
console.log(`Body includes 'k6.io': ${res.body.includes('k6.io')}`);
}Combine Multiple Checks
It's common to validate several aspects of a single response. You can add multiple conditions within one check() call.
Each condition is a separate check, and k6 will report on each one individually.
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const res = http.get('https://test.k6.io');
check(res, {
'status is 200': (r) => r.status === 200,
'body size is > 0': (r) => r.body.length > 0,
'header Content-Type exists': (r) => r.headers['Content-Type'] !== undefined,
});
}Understanding k6 Metrics
k6 automatically collects various performance metrics during a test run. These metrics provide insights into your system's behavior under load.
Metrics include things like response times, data transferred, and the number of virtual users (VUs).
- Metrics are quantitative measures of performance.
- k6 aggregates these into summaries at the end of a test.
- They help identify bottlenecks and performance trends.
Common Built-in Metrics
k6 provides several built-in metrics that are always collected. Some key ones include:
http_req_duration: Total time for HTTP requests.http_req_failed: Rate of failed HTTP requests (e.g., non-2xx status).vus: Current number of active virtual users.iterations: Number of times thedefaultfunction has run.
import http from 'k6/http';
export default function () {
http.get('https://test.k6.io');
// k6 automatically collects metrics like http_req_duration
// and http_req_failed for this request.
}Create Custom Metrics
Beyond built-in metrics, you can define your own custom metrics to track specific application logic or business processes.
k6 offers various custom metric types like Counter, Gauge, Trend, and Rate.
import http from 'k6/http';
import { Trend } from 'k6/metrics';
const myCustomTrend = new Trend('my_custom_processing_time');
export default function () {
const start = Date.now();
const res = http.get('https://test.k6.io');
const end = Date.now();
myCustomTrend.add(end - start); // Add value to custom trend metric
console.log(`Request took ${end - start}ms`);
}Set Performance Goals
While checks validate individual responses, thresholds define performance goals for your entire test run, based on aggregated metrics.
If a threshold is breached, the k6 test run will fail, indicating a performance regression or unmet SLA (Service Level Agreement).
Add Thresholds to Your Test
Thresholds are defined in the options object of your k6 script. You specify a metric and a condition it must meet.
Here, we ensure the average response time is below 200ms and less than 1% of requests fail.
import http from 'k6/http';
export const options = {
thresholds: {
'http_req_duration{expected_response:true}': ['p(95)<200'], // 95th percentile response time < 200ms
'http_req_failed': ['rate<0.01'], // less than 1% of requests failed
},
};
export default function () {
http.get('https://test.k6.io');
}Quick Check: k6 Concepts
Which of the following statements about k6 checks and thresholds are TRUE?
Recap: Checks, Thresholds, Metrics
Great job! You've learned how to make your k6 tests more robust and goal-oriented.
- Checks validate individual server responses for correctness.
- Metrics are quantitative measurements collected during a test run (e.g., response time, error rate).
- Thresholds define performance goals based on aggregated metrics, failing the test if conditions aren't met.
자주 묻는 질문
“검사, 임계값 및 메트릭” 강의는 무료인가요?
네 — “검사, 임계값 및 메트릭” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Load Testing & Performance Benchmarking (JMeter & k6) 강의 전체를 잠금 해제할 수 있습니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.
“검사, 임계값 및 메트릭”에서 뭘 배우나요?
응답 검증을 위한 k6 검사와 성능 목표를 정의하는 임계값을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Load Testing & Performance Benchmarking (JMeter & k6)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Load Testing & Performance Benchmarking (JMeter & k6)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Load Testing & Performance Benchmarking (JMeter & k6)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“검사, 임계값 및 메트릭” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Load Testing & Performance Benchmarking (JMeter & k6) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- k6 설치 및 CLI
- 기본 k6 스크립트 작성
- 검사, 임계값 및 메트릭
- 시험 구성을 위한 그룹 및 태그