เครื่องมือประสิทธิภาพหน่วยความจำและ CPU
ใช้เครื่องมืออย่าง `vmstat`, `sar` และ `mpstat` เพื่อวินิจฉัยปัญหาประสิทธิภาพที่เกี่ยวข้องกับ CPU และหน่วยความจำ
เครื่องมือประสิทธิภาพหน่วยความจำและ CPU เป็นบทเรียน Linux Command Line Mastery ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Linux Command Line Mastery และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Diagnose Performance Issues
Understanding system performance is key to troubleshooting slow applications or an unresponsive server. CPU and memory are often the first resources to check.
In this lesson, we'll explore powerful command-line tools to monitor and diagnose issues related to your system's CPU and memory usage.
Meet `vmstat`
The vmstat (virtual memory statistics) command provides a quick, real-time snapshot of your system's activity. It reports on processes, memory, paging, block I/O, traps, and CPU activity.
It's excellent for observing current system behavior and identifying immediate bottlenecks.
`vmstat` Memory Overview
Let's run vmstat 1 1 to see a single report, then we'll break down the memory-related output. This command shows a report every 1 second, for 1 iteration.
- swpd: amount of virtual memory used.
- free: amount of idle memory.
- buff: memory used as buffers.
- cache: memory used as cache.
vmstat 1 1`vmstat` CPU Details
Now, let's look at the CPU section of vmstat. Run the command again if you like, and focus on the 'cpu' columns:
- us (user): time spent running non-kernel code.
- sy (system): time spent running kernel code.
- id (idle): time spent idle.
- wa (wait): time spent waiting for I/O.
High wa often indicates disk bottlenecks.
vmstat 1 1Introducing `sar`
The sar (System Activity Reporter) command is part of the sysstat package. Unlike vmstat, sar can collect and report historical system activity data.
This makes it invaluable for long-term analysis, identifying trends, and diagnosing intermittent problems that might not be visible with real-time tools.
`sar` for CPU Usage
To view CPU utilization with sar, we use the -u option. Run sar -u 1 1 to get a single report.
- %user: CPU usage by user-level applications.
- %system: CPU usage by kernel-level tasks.
- %iowait: Time CPU spent waiting for I/O.
- %idle: Time CPU was idle.
sar -u 1 1`sar` for Memory Usage
To get detailed memory utilization reports with sar, use the -r option. Try sar -r 1 1.
- kbmemfree: Amount of free memory.
- kbmemused: Amount of used memory.
- %memused: Percentage of used memory.
- kbbuffers: Memory used by kernel buffers.
- kbcached: Memory used by page cache.
sar -r 1 1Understanding `mpstat`
The mpstat (multi-processor statistics) command is also part of the sysstat package. Its main advantage is providing per-processor or per-core CPU activity.
This is crucial for systems with multiple CPU cores, as it helps identify if a specific core is overloaded while others are idle.
`mpstat` Per-Core Activity
To see statistics for all individual CPU cores, use mpstat -P ALL 1 1. You'll see a separate line for each core (CPU 0, CPU 1, etc.) and an 'all' line for the average.
This helps pinpoint if a single-threaded application is maxing out one core, even if overall CPU usage seems low.
mpstat -P ALL 1 1Performance Tool Check
Which of the following statements about Linux performance tools are TRUE?
Recap: CPU & Memory Tools
In this lesson, you learned about three essential tools for monitoring CPU and memory performance:
vmstat: For real-time system activity snapshots.sar: For collecting and reporting historical system activity data.mpstat: For detailed per-processor/per-core CPU usage.
Mastering these commands will significantly boost your ability to diagnose and troubleshoot Linux system performance issues.
คำถามที่พบบ่อย
บทเรียน “เครื่องมือประสิทธิภาพหน่วยความจำและ CPU” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “เครื่องมือประสิทธิภาพหน่วยความจำและ CPU” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Command Line Mastery ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “เครื่องมือประสิทธิภาพหน่วยความจำและ CPU”
ใช้เครื่องมืออย่าง `vmstat`, `sar` และ `mpstat` เพื่อวินิจฉัยปัญหาประสิทธิภาพที่เกี่ยวข้องกับ CPU และหน่วยความจำ คุณปฏิบัติ Linux Command Line Mastery ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Command Line Mastery หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Command Line Mastery บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “เครื่องมือประสิทธิภาพหน่วยความจำและ CPU” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Linux Command Line Mastery นี้ได้ไหม
ได้ บทเรียน Linux Command Line Mastery ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การตรวจสอบดิสก์ I/O: `iostat`, `iotop`
- เครื่องมือประสิทธิภาพหน่วยความจำและ CPU
- เทคนิคการบันทึกเหตุการณ์และแก้ไขปัญหาขั้นสูง
- การติดตามการเรียกระบบด้วย strace และ ltrace