การตีความตัวชี้วัดของ k6
ทำความเข้าใจตัวชี้วัดโดยละเอียดของ k6 แท็กแบบกำหนดเอง และวิธีแสดงภาพข้อมูลเพื่อค้นหาข้อมูลเชิงลึก
การตีความตัวชี้วัดของ k6 เป็นบทเรียน Load Testing & Performance Benchmarking (JMeter & k6) ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Load Testing & Performance Benchmarking (JMeter & k6) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Load Testing & Performance Benchmarking (JMeter & k6) มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What are k6 Metrics?
When you run a k6 performance test, it generates various metrics. These are numerical values that describe your system's behavior under load.
Understanding these metrics is crucial for identifying performance bottlenecks, verifying service level agreements (SLAs), and ensuring your application can handle expected traffic.
Key Metric: Request Duration
One of the most important built-in k6 metrics is http_req_duration. This measures the total time it takes for an HTTP request to complete.
- It starts when the request is sent.
- It ends when the full response is received.
- It directly reflects the response time users experience.
Key Metrics: VUs & Iterations
Other fundamental metrics help you understand the load:
vus(Virtual Users): Shows the number of virtual users currently active during the test.iterations: Counts how many times your test script'sdefaultfunction has been executed.
These metrics help you see if your test is applying the intended load.
Key Metrics: Data Transfer
Understanding network usage is also vital. k6 provides metrics for data transfer:
data_sent: The total number of bytes sent by k6 during the test.data_received: The total number of bytes received by k6.
These metrics help analyze bandwidth consumption and identify potentially large responses.
Understanding Metric Aggregations
k6 doesn't just give raw values; it aggregates them. Common aggregations include:
avg(average)min(minimum)max(maximum)p(XX)(percentile, e.g.,p(90),p(95))
Percentiles are especially important as they represent the experience of a certain percentage of your users, ignoring extreme outliers.
Beyond Built-in: Custom Metrics
While k6's built-in metrics are powerful, you might need to track specific application-level events or durations. This is where custom metrics come in.
You can create your own metrics to gain deeper insights into your system's unique behavior. Common types are Counter, Gauge, Rate, and Trend.
Adding a Custom Metric
Here's how to add a Trend custom metric to measure the duration of a specific operation within your script. This helps track performance beyond just HTTP requests.
import { Trend } from 'k6/metrics';
import http from 'k6/http';
import { sleep } from 'k6';
const myCustomTrend = new Trend('custom_operation_duration');
export default function () {
const startTime = Date.now();
http.get('https://test.k6.io/contacts.php');
const endTime = Date.now();
myCustomTrend.add(endTime - startTime); // Add duration in milliseconds
sleep(1);
}Categorizing with k6 Tags
Tags are key-value pairs that provide metadata for your metrics. They allow you to categorize and filter your results for more granular analysis.
k6 automatically adds tags like url and status. You can also add custom tags to differentiate metrics for different parts of your application or specific user flows.
Applying Custom Tags
Custom tags are very useful for breaking down metrics. For example, you can tag requests based on the page or API endpoint they hit, allowing you to analyze performance per feature.
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
// Tagging requests to different pages
http.get('https://test.k6.io/', {
tags: { page_name: 'homepage' },
});
http.get('https://test.k6.io/news.php', {
tags: { page_name: 'news_page' },
});
sleep(1);
}Visualizing Your k6 Metrics
While k6's console output is useful, visualizing your metrics makes analysis much easier. Tools like Grafana (often paired with InfluxDB or Prometheus) are excellent for this.
k6 can export results directly to these systems, allowing you to create dashboards that show trends, spikes, and performance regressions over time.
Metric Interpretation Challenge
Consider the k6 output snippet below:
http_req_duration{status=200, scenario=default, my_tag=checkout}......: avg=350ms min=100ms med=300ms p(90)=550ms p(95)=600ms max=1200msWhat does p(95)=600ms primarily tell you about the checkout requests?
Recap: Interpreting k6 Metrics
You've learned how to interpret k6's powerful metrics!
- Built-in metrics like
http_req_duration,vus, anddata_sent/receivedgive foundational insights. - Aggregations, especially percentiles, provide a realistic view of user experience.
- Custom metrics and tags allow for deep, granular analysis of specific application behaviors.
- Visualization tools are essential for making sense of complex test results.
Mastering metric interpretation is key to successful performance testing!
คำถามที่พบบ่อย
บทเรียน “การตีความตัวชี้วัดของ k6” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การตีความตัวชี้วัดของ k6” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Load Testing & Performance Benchmarking (JMeter & k6) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Load Testing & Performance Benchmarking (JMeter & k6) มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การตีความตัวชี้วัดของ k6”
ทำความเข้าใจตัวชี้วัดโดยละเอียดของ k6 แท็กแบบกำหนดเอง และวิธีแสดงภาพข้อมูลเพื่อค้นหาข้อมูลเชิงลึก คุณปฏิบัติ Load Testing & Performance Benchmarking (JMeter & k6) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Load Testing & Performance Benchmarking (JMeter & k6) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Load Testing & Performance Benchmarking (JMeter & k6) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “การตีความตัวชี้วัดของ k6” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Load Testing & Performance Benchmarking (JMeter & k6) นี้ได้ไหม
ได้ บทเรียน Load Testing & Performance Benchmarking (JMeter & k6) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เครื่องมือตรวจสอบฝั่งเซิร์ฟเวอร์
- การวิเคราะห์ผลลัพธ์จาก JMeter
- การตีความตัวชี้วัดของ k6
- การเชื่อมโยงเมตริกเพื่อค้นหาสาเหตุราก