[[PageOutline]] * [參考] http://www.ufsdump.org/ - 這個網站有許多關於效能調校的細部說明 * [工具] 以下是 http://www.ufsdump.org/ 文件中提到的幾個工具 * system & disk I/O * [http://packages.debian.org/procps procps] - /usr/bin/vmstat * [http://packages.debian.org/sysstat sysstat] - /usr/bin/mpstat, /usr/bin/pidstat, /usr/bin/iostat, /usr/bin/sar.sysstat = /usr/bin/sar (由 /etc/alternatives/sar 產生) * [http://packages.debian.org/dstat dstat] * [http://dag.wieers.com/home-made/dstat/ 官方網站] * [http://packages.debian.org/iotop iotop] * network * [http://packages.debian.org/iptraf iptraf] * [http://packages.debian.org/ethtool ethtool] * [簡介] [http://www.linux-mag.com/id/7783 Give Me Liberty or Give Me Eth] * [官網] http://sourceforge.net/projects/gkernel/ = Performance Tuning = == System Performance Tuning : CPU == * 檢查 CPU 是否為 64 位元的方法 - [http://ubuntuforums.org/archive/index.php/t-573630.html 參考自 Ubuntu 論壇] {{{ ~$ sudo lshw -C cpu | grep width width: 32 bits ---> 為 32 位元 ======= width: 64 bits ---> 為 64 位元 }}} * 檢查 CPU 是否支援虛擬化 - 旗標(flags)分別是: Intel (vmx) 與AMD (svm) ([wiki:KVM/install KVM 安裝 (rock)]) {{{ ~$ cat /proc/cpuinfo | egrep 'vmx|svm' --color }}} == System Performance Tuning : Memory == * 查詢記憶體時脈與單一條的大小 {{{ $ sudo dmidecode 搜尋 Memory Device 會看到類似的結果 Memory Device Array Handle: 0x1000 Error Information Handle: Not Provided Total Width: 64 bits Data Width: 64 bits Size: 2048 MB Form Factor: DIMM Set: None Locator: DIMM_4 Bank Locator: Not Specified Type: DDR2 Type Detail: Synchronous Speed: 800 MHz (1.2 ns) Manufacturer: 7F4F000000000000 Serial Number: 0007D1E4 Asset Tag: 540834 Part Number: TS256MLQ64V8U }}} * Share Memory - 有些程式需要用到比較多 Share Memory (共享記憶體), 如: Kerrighed ([wiki:krg_tuning 2008-03-20 (rock/rider)]) {{{ echo "kernel.shmall = 796917578" >> /etc/sysctl.conf echo "kernel.shmmax = 796917578" >> /etc/sysctl.conf echo "kernel.shmmni = 4096" >> /etc/sysctl.conf }}} * Cache Memroy - [參考] [http://www.codemud.net/~thinker/GinGin_CGI.py/show_id_doc/419 回收 Linux cached memory] * 設定 vm.drop_caches 觸發 kernel 回收用於 cache 的記憶體。 至於 1, 2, 3 的等級,可參考 [http://www.linuxinsight.com/proc_sys_vm_drop_caches.html LinuxInsight 的說明] * 1: free pagecache * 2: free dentries and inodes * 3: free pagecache, dentries and inodes {{{ echo 1 > /proc/sys/vm/drop_caches }}} {{{ sysctl -w vm.drop_caches=1 }}} * 設定 vm.vfs_cache_pressure 使 kernel 更勤於回收 cache。 {{{ sysctl -w vm.vfs_cache_pressure=n (n > 100) }}} == System Performance Tuning : File System == * 如何調整每個使用者可以開啟的檔案個數 * [參考] [http://www.xenoclast.org/doc/benchmark/HTTP-benchmarking-HOWTO/node7.html Increasing the file descriptor limit] * [參考] [http://www.netadmintools.com/art295.html GNU/Linux - How Many Open Files?] * 注意:修改 /etc/security/limits.conf 中間必須確定是 TAB ,如果有設定 vim 的 softwaretab 的話,得特別當心!!! * /proc/sys/fs/file-max - 核心預設最多可以開啟的檔案個數 {{{ ~$ cat /proc/sys/fs/file-max 743964 }}} * 修改方法: 使用 sysctl 指令或編輯 /etc/sysctl.conf {{{ sysctl -w fs.file-max=100000 }}} * /proc/sys/fs/file-nr - 目前已開啟檔案個數、可供開啟檔案個數、總開啟檔案上限 {{{ [root@srv-4 proc]# cat /proc/sys/fs/file-nr 3391 969 52427 | | | | | | | | maximum open file descriptors | total free allocated file descriptors total allocated file descriptors (the number of file descriptors allocated since boot) }}} * /etc/security/limits.conf - 每個程序(process)可以開啟檔案的個數(number limits of open files per process) - 像 HDFS 的 !DataNode 就需要調整這種參數([wiki:jazz/10-02-22#Hadoop:HDFS 2010-02-22]) {{{ #!diff --- /etc/security/limits.conf 2010-02-22 11:29:11.000000000 +0800 +++ /etc/security/limits.conf.new 2010-02-22 11:28:33.000000000 +0800 @@ -49,4 +49,6 @@ #ftp - chroot /ftp #@student - maxlogins 4 +* soft nofile 4096 +* hard nofile 743964 + # End of file }}} * /etc/pam.d/login - 告訴系統要用 /etc/security/limits.conf 來設定一些上限 {{{ # Sets up user limits according to /etc/security/limits.conf # (Replaces the use of /etc/limits in old login) session required pam_limits.so }}} * 指令: ulimit - 可以告訴你一些系統限制,並且設定想要的値 {{{ jazz@Wdebian:~$ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 72704 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 72704 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited }}} * 假設 /proc/sys/fs/file-max 跟 /etc/security/limits.conf 都有設定上限為 743964,且 /etc/pam.d/login 也有打開,但是 ulimit -a 指令仍顯示 1024 (預設),可以修改 /etc/rc.local 或 /etc/profile 強制用 ulimit -n 743964 來提高開檔個數。 {{{ ~$ ulimit -n 743964 }}} * [備註] 如果 ulimit 超出可容許範圍,會顯示 Operation not permitted,此時請檢查相關設定値 {{{ ~$ ulimit -n 7439640 -bash: ulimit: open files: cannot modify limit: Operation not permitted }}} == I/O Performance Tuning : NFS == * NFS Tuning - /etc/fstab - 加大 NFS read/write size 可以提升檔案系統的 I/O 效率 ([wiki:krg_tuning 2008-03-20 (rock/rider)]) {{{ 192.168.0.111:/home /home nfs rw,bg,soft,intr,rsize=262144,wsize=262144 0 4 192.168.0.111:/opt /opt nfs ro,bg,soft,intr,rsize=262144,wsize=262144 0 4 192.168.0.111:/usr /usr nfs ro,bg,soft,intr,rsize=262144,wsize=262144 0 4 }}} == I/O Performance Tuning : IOWait == * [wiki:jazz/10-03-31 2010-03-31] : 高 IOWait 有什麼好的解決之道呢?? * [http://www.scriptbits.net/2009/07/how-to-identify-what-processes-are-generating-io-wait-load/ How to identify what processes are generating IO Wait load?] {{{ Jun run "pidstat -d 5" and it will print the list of processes doing IO over the last 5 seconds. }}} * [http://ubuntuforums.org/showthread.php?t=1382161 Re: Major problems: High Iowait. Change filesystem from etx4 to xfs/ext3/jfs?] {{{ vm.dirty_writeback_centisecs=100 vm.dirty_expire_centisecs=100" }}} * [http://ubuntuforums.org/showthread.php?t=200004 iowait problem] - 顯示了使用 vmstat , iostat , hdparm 的技巧 == Network Performance Tuning == * TCP Tuning - ([wiki:krg_tuning 2008-03-20 (LSI)]) {{{ echo 262144 > /proc/sys/net/core/rmem_default echo 8388608 > /proc/sys/net/core/wmem_max echo 8388608 > /proc/sys/net/core/rmem_max echo "4096 87380 4194304" > /proc/sys/net/ipv4/tcp_rmem echo "4096 65536 4194304" > /proc/sys/net/ipv4/tcp_wmem }}} * TCP TIME_WAIT & Reuse - 適用網站伺服器 ([wiki:jazz/Trac_Updates#a2010-03-26 2010-03-26]) {{{ echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout sysctl net.ipv4.tcp_tw_reuse=1 sysctl net.ipv4.tcp_tw_recycle=1 }}} * 如果沒辦法 ping 224.0.0.1 的話,代表 Broadcast ICMP 封包被濾掉了,因為預設 Linux kernel 2.6 是 disable 的。解法如下:([wiki:jazz/09-09-07 2009-09-07]) {{{ echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts }}} {{{ ~# echo "net.ipv4.icmp_echo_ignore_broadcasts = 0" >> /etc/sysctl.conf ~# sysctl -p net.ipv4.ip_forward = 1 net.ipv4.icmp_echo_ignore_broadcasts = 0 }}} * [http://fourdollars.blogspot.com/2009/04/linux-system.html 如何在 Linux System 當中偵測網路線是否有接上?] ([wiki:jazz/09-05-05 2009-05-05]) {{{ $ cat /sys/class/net/eth0/carrier }}} == Power Management == * 啟動 SATA ALPM 電源管理功能 - [http://packages.debian.org/powertop powertop] 提供之建議 {{{ echo min_power > /sys/class/scsi_host/host0/link_power_management_policy }}} * 虛擬機器的 clocksource ([wiki:jazz/Trac_Updates#a2010-02-11 2010-02-11]) {{{ echo acpi_pm > /sys/devices/system/clocksource/clocksource0/current_clocksource }}} * 直接修改系統參數讓 Linux 休眠 ([wiki:rock/drbl_switch 2010-03-03 (rock)]) {{{ # echo 4 > /proc/acpi/sleep /** 適用 Kernel 2.4 (swsusp)**/ # echo disk > /sys/power/state /** 適用 Kernel 2.4 & 2.6 (swsusp)**/ }}} == Security == * 關於 /proc/sysrq-trigger ([wiki:jazz/09-11-17 2009-11-17]) * [http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference_Guide/s2-proc-sysrq-trigger.html Redhat 手冊的說明 - /proc/sysrq-trigger] * 其實除了 CTRL+ALT+DEL 外,Linux 還可以透過 [http://en.wikipedia.org/wiki/SysRq System Request (Sys Rq) 按鍵] 來做一些特殊除錯工作。這個 Sys Rq 鍵,通常跟 Print Screen 鍵做在一起。 * 要啟用這個功能,首先必須確認核心的 CONFIG_MAGIC_SYSRQ 參數是否有 enable。 * [http://en.wikipedia.org/wiki/Magic_SysRq_key 維基百科除了說明 SYSRQ 可以做哪些事情]外,還介紹了[http://julien.danjou.info/sysrqd/ sysrqd]這個軟體,讓管理者可以遠端執行 SYSRQ 的指令。PS.[http://packages.debian.org/sysrqd sysrqd 也有 debian 套件]!! * 關於 /proc/sys/kernel/sysrq ([wiki:jazz/09-11-17 2009-11-17]) * [http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference_Guide/s3-proc-sys-kernel.html Redhat 手冊的說明 - /proc/sys/kernel/ 底下的檔案意涵] * [http://lxr.linux.no/#linux+v2.6.31/Documentation/sysrq.txt Linux 核心關於 SysRq 的說明]