HW4 : CPU bound vs. IO bound 1.What is CPU bound and IO bound process? A : CPU-bound(計算密集型) 在多重程式系統中,大部份時間用來做計算、邏輯判斷等CPU動作的程式稱之 CPU bound。例如一個計算圓周率至小數點一千位以下的程式,在執行的過程當中 絕大部份時間用在三角函式和開根號的計算,便是屬於CPU bound的程式。 I/O密集型 (CPU-bound) I/O bound 指的是系統的CPU效能相對硬碟/記憶體的效能要好很多,此時,系統運作,大部分的狀況是 CPU 在等 I/O (硬碟/記憶體) 的讀/寫,此時 CPU Loading 不高。 CPU bound 指的是系統的 硬碟/記憶體 效能 相對 CPU 的效能 要好很多,此時,系統運作,大部分的狀況是 CPU Loading 100%,CPU 要讀/寫 I/O (硬碟/記憶體),I/O在很短的時間就可以完成,而 CPU 還有許多運算要處理,CPU Loading 很高。 2.Use stress tool to make you own examples: Demo and explain your example in vmstat, iostat or other commands 家用電腦輸入那些指令無法查得。 CPU and memory stress tests #sudo stress -m 1 --vm-bytes 1.5G stress: info: [4407] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd #free total used free shared buffers cached Mem: 2032348 1315096 717252 16588 40468 208136 -/+ buffers/cache: 1066492 965856 Swap: 2094076 117108 1976968 #top top - 01:31:38 up 16 min, 3 users, load average: 0.89, 0.64, 0.43 Tasks: 226 total, 2 running, 222 sleeping, 2 stopped, 0 zombie %Cpu(s): 11.0 us, 89.0 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 2032348 total, 1266956 used, 765392 free, 36488 buffers KiB Swap: 2094076 total, 117104 used, 1976972 free. 208140 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4408 root 20 0 1055904 381424 784 R 95.1 18.8 0:19.78 stress #sar 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) 01:32:37 AM CPU %user %nice %system %iowait %steal %idle 01:32:38 AM all 12.00 0.00 88.00 0.00 0.00 0.00 01:32:39 AM all 5.00 0.00 95.00 0.00 0.00 0.00 #mpstat 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) 01:33:18 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle 01:33:19 AM all 9.00 0.00 91.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 IO stress test Example: 30 IO sync threads #stress --io 30 stress: info: [4435] dispatching hogs: 0 cpu, 30 io, 0 vm, 0 hdd #iostat -kx 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 6.10 2.42 36.27 4.48 0.00 50.74 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 1.38 30.35 47.83 5.99 769.71 403.65 43.60 0.73 13.48 11.39 30.25 1.24 6.68 Example: 1 thread to write disk (default: 1 GB) #stress -d 1 stress: info: [4508] dispatching hogs: 0 cpu, 0 io, 0 vm, 1 hdd #iostat -kx 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 5.75 2.23 40.08 4.54 0.00 47.40 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 1.27 29.45 44.12 6.37 709.68 1313.17 80.14 0.80 15.82 11.45 46.08 1.38 6.96 #vmstat 1 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 4 0 117032 1070944 34944 314440 2 92 707 1915 340 829 8 40 47 5 0 3 1 117032 982840 34948 400272 0 0 0 93700 136 485 3 15 0 82 0 CPU and memory stress tests #stress -m 1 --vm-bytes 1.5G stress: info: [4685] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd #free total used free shared buffers cached Mem: 2032348 1470364 561984 16588 39588 217008 -/+ buffers/cache: 1213768 818580 Swap: 2094076 116624 1977452 #top top - 02:24:50 up 1:09, 3 users, load average: 0.61, 0.18, 0.27 Tasks: 225 total, 2 running, 221 sleeping, 2 stopped, 0 zombie %Cpu(s): 9.7 us, 90.3 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 2032348 total, 1908908 used, 123440 free, 39636 buffers KiB Swap: 2094076 total, 116620 used, 1977456 free. 217012 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4686 root 20 0 1055904 0.990g 688 R 96.4 51.1 0:37.68 stress #sar 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) 02:26:46 AM CPU %user %nice %system %iowait %steal %idle 02:26:47 AM all 7.92 0.00 92.08 0.00 0.00 0.00 02:26:48 AM all 7.00 0.00 93.00 0.00 0.00 0.00 #mpstat 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) 02:26:54 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle 02:26:55 AM all 10.00 0.00 90.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 02:26:56 AM all 10.00 0.00 90.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 IO stress test Example: 30 IO sync threads #stress --io 30 stress: info: [4708] dispatching hogs: 0 cpu, 30 io, 0 vm, 0 hdd #iostat -kx 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 2.23 0.67 13.92 1.54 0.00 81.63 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.40 9.69 13.40 2.43 215.13 734.19 119.96 0.29 18.14 11.42 55.28 1.56 2.47 Example: 1 thread to write disk (default: 1 GB) #stress -d 1 stress: info: [4759] dispatching hogs: 0 cpu, 0 io, 0 vm, 1 hdd #iostat -kx 1 Linux 3.19.0-80-generic (ubuntu) 11/04/2019 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 2.23 0.66 14.90 1.65 0.00 80.56 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.39 9.98 13.20 2.59 211.86 995.03 152.90 0.33 20.74 11.42 68.24 1.66 2.62 #vmstat 1 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 1 116312 1046888 40696 328304 1 27 212 1196 227 533 3 15 80 2 0 0 1 116312 851648 40696 518548 0 0 0 184324 457 1512 1 6 0 93 0