Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Ruby

Làm Chủ System Load: Cách Đọc Và Diễn Giải Load Averages

Cập nhật 25/02/2024 để update example screenshots và outdated links.

Monitor system's load là essential để keep app running smoothly. Host metrics của AppSignal cung cấp insights vào load average của system, showing load system chịu đựng over multiple time frames. Bạn cũng có thể check metric này dùng tools như top, uptime, và w:

$ uptime
 10:30:45 up 5 days,  3:42,  2 users,  load average: 0.44, 0.28, 0.25

Nhưng "load average" exactly nghĩa là gì, và làm sao interpret these numbers? Trong bài này, chúng ta break down system load, explain cách đọc load averages, và show cách monitor effectively.

Load Averages Là Gì?

Load averages thường displayed as three numbers, như example từ uptime trên. Ba numbers cuối result show average load trong last minute (0.44), last five minutes (0.28), và last fifteen (0.25).

Làm Chủ System Load: Cách Đọc Và Diễn Giải Load Averages

Trên AppSignal, load averages displayed by minute cho last 12 hours và per hour cho longer periods. Bạn có thể dive deeper vào any moment với Time Detective và compare hosts real time dùng Host metrics dashboards.

System Load (Tải Hệ Thống)

Để hiểu load averages tell us gì (và khi nào alarm), first cần hiểu system load nghĩa là gì và cách measure.

System load về cơ bản là số active processes tại any given time:

  • Khi idle, load = 0.
  • Khi process starts, load tăng 1.
  • Khi process completes, load giảm 1.

Load cũng include processes waiting for CPU time. Vậy, nếu one process actively using CPU và two others queued, load = 3.

Vì short-lived processes, load fluctuates rapidly — có thể jump từ 0 đến 5 trong milliseconds và drop back just as fast. Do volatility này, useful hơn look at average load over time, cung cấp clearer picture của system busy như thế nào.

Load Averages (Trung Bình Tải)

Bây giờ biết system load counted như thế nào, hãy look at load averages. Như đã thấy, load system chịu thường shown as average over time.

General rule: single-core CPU handle one process at a time. Average load 1.0 nghĩa là one core busy 100% time. Nếu load average drop to 0.5, CPU idle 50% time.

Nếu load average rise to 1.5, CPU busy all the time while (on average) one other process waiting 50% time, giving CPU more work than it can handle.

Logical Processors (Bộ Xử Lý Logic)

General rule of thumb: load average không nên exceed số processors trong machine. Nếu số processors = 4, load generally stay under 4.0.

Lưu ý relate to logical processors thay vì physical ones trên CPU. Vì software abstractions như hyper-threading, số logical processors (processing threads) có thể higher than physical processor cores.

Để check số logical processors trên Linux, count processors listed in /proc/cpuinfo, hoặc dùng:

grep -c ^processor /proc/cpuinfo

Sẽ print out số processor lines automatically. Trên Mac, bạn hỏi sysctl cho số logical processors trực tiếp:

sysctl -n hw.logicalcpu

Đối với system với multiple logical processors, load average có thể grow higher, vì run more concurrent processes. Trên máy 2 CPU cores, load average 2.0 nghĩa là both CPUs 100% utilized, while 2 processes active on average.

👋 Xem thêm Ruby (on Rails) performance articles trong Ruby performance monitoring checklist.

Đọc Load Averages

Vì là average của absolute number of processes, có thể seem difficult determine proper load average, và khi nào alarm. Nói chung, vì mỗi CPU core handle one process at a time, system không overloaded until go over 1.0 per logical processors. Trên dual-core system (without hyper-threading), đó là 2.0.

Thường thì fine nếu load average above 1.0 per core ở last minute mark, nhưng elevated load ở five hoặc fifteen-minute averages could indicate problem.

Monitor Your Hosts Với AppSignal

Hiểu load averages là key để keep app healthy. Với features như Error Tracking, Anomaly Detection, và Log Management, AppSignal giúp spot issues trước khi become problems.

Muốn monitor app với powerful insights và smart alerts? Start free 30-day trial, no credit card needed.

Có questions hoặc feedback? Let us know, experts sẵn sàng answer monitoring queries!