Mackerelãã¼ã ã®ã¨ã³ã¸ãã¢ã®id:itchynyã§ãã
ãmackerel-agentãå ¥ããã¨loadavgã7æéãã¨ã«ä¸æããã
å æ¥ããã®ãããªåãåãããè¤æ°ã®ã客ãã¾ããåãã¾ãããç§ãå®é¨ãã¦ã¿ãã¨ããã確ãã«åç¾ãã¾ãããEC2 t2.microã«mackerel-agentãå ¥ãã¦ç°¡åãªãã°ç£è¦ã¨ããã»ã¹ç£è¦ãè¨å®ããæ°æ¥æ¾ç½®ãã¾ããã 確ãã«ãç´7æéãã¨ã«loadavgãä¸æãã¦ãã¾ãããã®å¨æã®cronã®è¨å®ã¯ãã¦ããããã¾ãmackerel-agentå é¨ã§ã7æéãã¨ã«è¡ãå¦çã¯ããã¾ããããããããã©ã°ã¤ã³ãå¤ãå ¥ããã»ã©loadavgã®ãã¼ã¯å¤ãä¸ããã¾ãã
æ¬ã¨ã³ããªã¼ã§ã¯ããã®ç¾è±¡ã®åå ã«ã¤ãã¦èª¬æãã¾ãã
loadavgãä¸æããåå ã調ã¹ãã«ã¯ãã¾ãloadavgèªä½ãã©ãè¨ç®ããã¦ããããç¥ãå¿ è¦ãããã¾ãã ã¾ãã¯ãLinuxãloadavgãã©ã®ããã«è¨ç®ãã¦ãããã説æãã¾ãã
Linuxã®loadavgã¯ãrun queueã«ããããã»ã¹ (running process) ã¨ãã£ã¹ã¯I/Oãããã¯å¾ ã¡ã®ããã»ã¹ (uninterruptible process) ã®ç·æ°ã®ææ°ç§»åå¹³åå¤ã§ãã Linuxã®ããã»ã¹ã«ã¯ã以ä¸ã®ãããªç¶æ ãããã¾ãã
% man ps | grep -A 10 "^PROCESS STATE" PROCESS STATE CODES Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process: D uninterruptible sleep (usually IO) R running or runnable (on run queue) S interruptible sleep (waiting for an event to complete) T stopped, either by a job control signal or because it is being traced W paging (not valid since the 2.6.xx kernel) X dead (should never be seen) Z defunct ("zombie") process, terminated but not reaped by its parent
ãã®å
ã® R
㨠D
ã®ç¶æ
ã®ããã»ã¹ã®æ°ããææ°å éå¹³åã§å¹³æ»åããå¤ãloadavgã¨ãªãã¾ãã
loadavgã®å¯¾è±¡ã¨ãªãrunningã¨uninterruptibleãªããã»ã¹ã®ç·æ°ããæå» ã«å¯¾ããé¢æ°ã¨ã㦠ã¨è¡¨ãã¾ãããã ãµã³ããªã³ã°ééã ãæå®æ°ã ã¨ããã¨ãããã»ã¹æ°ã®ææ°ç§»åå¹³åãã¤ã¾ãææ°é¢æ°çã«æ¸è¡°ããå éå¹³åã¯ä»¥ä¸ã®ããã«æ¸ããã¨ãã§ãã¾ã 1ã
ããã¾ã§ã®æå»ã® ã®ææ°ç§»åå¹³åå¤ã¯ãåã®è¨ç®å¤ ã¨ç¾å¨ã®å¤ ã®å éå¹³åå¤ã§è¡¨ããã¨ãã§ãã¾ãã ããã¾ã§ã®ããã»ã¹æ°ã®å±¥æ´ãä¿æãã¦ããªãã¦ããååã®loadavgã¨ç¾å¨ã®ããã»ã¹æ°ããæ°ããloadavgãè¨ç®ã§ããã¨ãããã¨ã§ãã
ãã®æ¼¸åå¼ããã¨ã«ãå®æ°ãé©åã«é¸ãã§ã·ãã¥ã¬ã¼ã·ã§ã³ããå¤ () ã¨ãå®éã®Linux (EC2 t2.microä¸ã§ yes > /dev/null&
ãå®è¡ãã10åå¾ã«ãã®ããã»ã¹ãè½ã¨ã) ã§è¨æ¸¬ãããå¤ãæ¯è¼ãã¦ã¿ãã¨ã以ä¸ã®ãããªçµæãå¾ããã¾ããã
Linuxã®ã½ã¼ã¹ã³ã¼ããåç §ããªãããå®éã«ä¸è¨ã®æ¼¸åå¼ããã¨ã«loadavgãè¨ç®ããã¦ãããã¨ã確èªãã¾ãã ã¾ã㯠kernel/sched/loadavg.c ãè¦ã¦ã¿ã¾ãããã
/* Variables and functions for calc_load */ atomic_long_t calc_load_tasks; unsigned long calc_load_update; unsigned long avenrun[3]; void calc_global_load(unsigned long ticks) { unsigned long sample_window; long active, delta; sample_window = READ_ONCE(calc_load_update); if (time_before(jiffies, sample_window + 10)) return; // ... active = atomic_long_read(&calc_load_tasks); active = active > 0 ? active * FIXED_1 : 0; avenrun[0] = calc_load(avenrun[0], EXP_1, active); avenrun[1] = calc_load(avenrun[1], EXP_5, active); avenrun[2] = calc_load(avenrun[2], EXP_15, active); WRITE_ONCE(calc_load_update, sample_window + LOAD_FREQ); // ... }
loadavgã®å¤ã¯ avenrun
ã«æ ¼ç´ããã¦ãã¾ãã
ãã®å¤ã®æ´æ°ãå®æçã«è¡ãããã«ã calc_load_update
ã¨ããå¤ã LOAD_FREQ
ãã¤å¢ãããªããã jiffies
(1 tickãã¨ã«1å¢ãããæå»ã表ãå¤æ°) ã¨æ¯è¼ãã¦ãããã¨ããããã¾ãã
ã¤ã¾ãloadavgã¯æ´æ°éé㯠LOAD_FREQ
ãã¨ã«è¡ããã¦ãã¾ãã
ãã®å¤ã¯ include/linux/sched/loadavg.h ã«ãããã¦ããéãã 5*HZ+1
ãã¨ã§ãã
HZ
ã¯1ç§ã«ä½tickå¢ãããã¨ããå¤ã§ããã 2ã5ç§ã¨1 tickãã¨ã«loadavgãæ´æ°ãããã¨ãããã¨ããããã¾ãã
ã§ã¯ãå®éã«å¤ãè¨ç®ãã¦ãã calc_load
ãè¦ã¦ã¿ã¾ãã
/* * a1 = a0 * e + a * (1 - e) */ static unsigned long calc_load(unsigned long load, unsigned long exp, unsigned long active) { unsigned long newload; newload = load * exp + active * (FIXED_1 - exp); if (active >= load) newload += FIXED_1-1; return newload / FIXED_1; }
åå²ã®å¦çãç¡è¦ãã¦ä¸ã¤ã®å¼ã«æ¸ãã¦ã¿ã¾ã 3ã
avenrun[0] = ((FIXED_1 - EXP_1) * active + EXP_1 * avenrun[0]) / FIXED_1;
ãã㧠include/linux/sched/loadavg.h ã«ãã㨠EXP_1 = 1884
, FIXED_1 = (1<<11)
ã§ãã
ã¾ãä¸ã®æ¹ã§æ±ãã漸åå¼ã« ã代å
¥ããã¨æ¬¡ã®ããã«ãªãã¾ãã
æ´æ°æ¼ç®ã«ããããã«11bitã·ãããã (FIXED_1
åãã) å¤ã§è¨ç®ãã¦ãããã¨ã¨ã ãããã1884ã§ãããã¨ã確ãããã¨ã確ãã«æ¼¸åå¼ã¨Linuxã§è¡ããã¦ããè¨ç®ãä¸è´ãããã¨ããããã¾ãã
loadavg5, 15ãåæ§ã«ç¢ºèªã§ãã¾ãã
loadavgã¯ããã5ç§ãã¨ã«ããã®ç¬éã®run queueå
ã®ããã»ã¹æ° (calc_load_tasks
) ã¨æ¼¸åå¼ãç¨ãã¦æ´æ°ããã¦ãã¾ãã
æ£ç¢ºã«ã¯ 5*HZ+1
tickãã¨ã«è¨ç®ããã¦ãã¾ãã
ãã® +1
ããç´7æéãã¨ã«loadavgãä¸æããç¾è±¡ã®åå ã§ãã
mackerel-agentã¯1åãã¨ã«ã¡ããªãã¯ãåéããããã«ããã©ã°ã¤ã³ã®ããã»ã¹ãéãã¦ãã¾ãã loadavgã®åè¨ç®ã5ç§ã´ã£ããããå°ãã ãããã¦ããããã«ãmackerel-agentãã¡ããªãã¯åéãå§ããã¿ã¤ãã³ã°ã¨loadavgã®åè¨ç®ã®ã¿ã¤ãã³ã°ãå®æçã«ä¸è´ããã®ã§ãã
HZ
ã1000ã®ç°å¢ã§ã¯ãloadavgã¯5.001ç§ãã¨ã«æ´æ°ããã¾ããããã5000åãã㨠25005ç§ ããªãã¡ 6æé56å45ç§ ã¨ããå¨æã§ã+1
ã®é¨åãæºã¾ã£ã¦ 5*HZ
ã¨ä¸è´ãã¾ãããã®å¨æã¯ãmackerel-agentã®ã¡ããªãã¯åéééã§ãã60ç§ã®åæ°ã§ã¯ããã¾ããããããã»ã¹ãéãã¿ã¤ãã³ã°ã¨loadavgã®æ´æ°ã (0.003ç§ããã¾ãã) ã»ã¼éãªãç¾è±¡ã6æé57åãã¨ã«èµ·ããã®ã§ãã
HZ
ã250ã®ç°å¢ã§ã¯ã5*HZ+1
ã1250åç¹°ãè¿ã㨠6255ç§ ããªãã¡ 1æé44å15ç§ ã¨ãªãã¾ãããã®å¨æã§loadavgãä¸ãã£ã¦ãããã¯ãã§ãããmackerel-agentã®ã¡ããªãã¯åéã¿ã¤ãã³ã°ã¨0.012ç§ãã¤ããã¦ããã®ãç¡è¦ã§ãã¾ããã60ç§ã®åæ°ã¨ãªãã®ã¯ããã«4åãã¤ã¾ã6æé57åå¨æã§ãmackerel-agentã®ã¡ããªãã¯åéã®ã¿ã¤ãã³ã°ã¨ã´ã£ããéãªãã¾ããç§ã®æ¤è¨¼ç°å¢ã§ã¯ HZ=250
ã§ãããã¨ã³ããªã¼åé ã®ã°ã©ããè¦ãã¨ã確ãã«6æé57åã®å¨æã§é«ãã®æã£ããã¼ã¯ãç«ã£ã¦ãããã¨ããããã¾ããããã«ããã®ãã¼ã¯ã®1æé44ååå¾ã§å°ããªãã¼ã¯ãç«ã£ã¦ããã¨ãããããã®ãè¦ã¦åãã¾ãããã㯠HZ
ã250ã§ãããã¨ã«ç±æ¥ããç¾è±¡ã§ãã
loadavgã®æ´æ°ééã¯ãªãã´ã£ãã5ç§ééã®æ´æ°ã§ã¯ãªãã®ã§ããããã
Linuxã®ä¸ã§ã¯æ§ã
ãªããã»ã¹ãç¬èªã®å¨æã§å¦çãè¡ã£ã¦ãã¾ãã
ä¾ãã°5ç§ééã§å¦çãè¡ããããªããã»ã¹ãããã¨ãloadavgã®åè¨ç®ã¿ã¤ãã³ã°ã¨ã´ã£ããä¸è´ãããã¨ãèµ·ããå¯è½æ§ãããã¾ãã
æå³ããã¿ã¤ãã³ã°ãåè´ãã¦loadavgãä¸æããç¾è±¡ãèµ·ããã®ãé²ãããã«ãå¨æã5ç§ããå°ããããã¦ããã®ã§ãã
ãã®çµç·¯ã¯ã5*HZ
ã«1
足ããã¨ã«ãªã£ããããã®ã³ãããã¡ãã»ã¼ã¸ããã¡ã¼ãªã³ã°ãªã¹ããèªãã¨ãããã¾ãã
Linuxã«ãããloadavgã®æ´æ°ééã¯ãæå³çã«5ç§ããå°ãããã¦ãã¾ãããã®å°ãã®ãããæºã¾ã£ã¦ãããç´6æé57åã®å¨æã§60ç§ã®åæ°ã¨ãªãã¾ããmackerel-agentã¯60ç§ãã¨ã«ãã©ã°ã¤ã³ã®ããã»ã¹ãéãã¦ããããã®ã¿ã¤ãã³ã°ãloadavgã®åè¨ç®ã¿ã¤ãã³ã°ã¨åãç¾è±¡ãå¨æçã«èµ·ããã¾ããããããmackerel-agentãå ¥ããã¨loadavgãå®æçã«ä¸æããç¾è±¡ã®åå ã§ãããã®ç¾è±¡ã¯ãcollectdãTelegrafãªã©ãä»ã®ã¢ãã¿ãªã³ã°ãã¼ã«ã§ãå ±åããã¦ãã¾ãã
åèæç®
- Avast Blog: Investigation of regular high load on unused machines every 7 hours
- æ¬ç¾è±¡ã«ã¤ãã¦èª¬æãããããã°ã§ããcollectdãç¨ããç°å¢ã§åãç¾è±¡ãèµ·ãã¦ãã¾ãã
- Linux Load Averages: Solving the Mystery
- loadavgã«uninterruptible processã®æ°ãè¨ç®ã«å ¥ã£ã¦ããçç±ãæ´å²çãªçµç·¯ã追ã£ã¦èª¬æããã¦ãã¾ãã
-
ä¿æ°ã®åã1ã§ãããã¨ã確ããããã¨ãã§ãã¾ããå éå¹³åã§ããããã®å¿ è¦æ¡ä»¶ã§ããâ©
-
ãã®ã¨ã³ããªã¼ã®
HZ
ã¯ã«ã¼ãã«ã®ã¿ã¤ãã¼å¨æ³¢æ°CONFIG_HZ
ã§ãããã¦ã¼ã¶ã¼ã©ã³ãã®å¨æ³¢æ°USER_HZ
ã¨åºå¥ããå¿ è¦ãããã¾ããgetconf CLK_TCK
ã/proc/stat
ããå¾ãããå¤ã¯USER_HZ
ã§ãããx86ã§ã¯100ã¨æ±ºã¾ã£ã¦ãã¾ããã«ã¼ãã«ã®ã¿ã¤ãã¼å¨æ³¢æ°ã¯grep "CONFIG_HZ=" /boot/config-$(uname -r)
ã§èª¿ã¹ãããwatch -n1 "grep ^jiffies /proc/timer_list | head -n1"
ã®å¢ãæ¹ã§è¦ããã¨ãã§ãã¾ããâ© -
åå²ã®å¦çã¯ãã¾ã£ããããã»ã¹ããªãç¶æ 㧠0.0ãããã»ã¹ã常ã«ä¸ã¤ããç¶æ 㧠1.0 ã¨ãªãããã«ããããã®å¦çã§ãããã®å¦çãå ¨ããªããã°ãã¤ã¾ã§çµã£ã¦ãloadavgã 1.0 ã«ãªãã¾ããããåå²ãªãã«å¸¸ã«è¶³ãã¨ããå¦çã«ãã¦ãã¾ãã¨ãidleç¶æ 㧠0.0 ã«ãªãã¾ããããã¤ã¦ã¯ 0.5 ç¸å½ã足ãã¦ããå²ããã¨ã§åæ¨äºå ¥ã«ãªã£ã¦ããã®ã§ãããidleç¶æ 㧠0.0 ã«ãªããªãåé¡ãææããã¦ãããã»ã¹æ°ãå¢ãã¦ããã¨ãã ãåãä¸ãããå½¢ã«ãªã£ã¦ãã¾ãã詳ããã¯ããããã¡ã¼ãªã³ã°ãªã¹ããåç §ãã¦ãã ãããâ©