Hadoop2.7實戰v1.0之Linux參數調優

 Hadoop2.7實戰v1.0之Linux參數調優 

1.增大文件描述符nofile(查看當前的lsof |wc -l) 和 用戶最大進程nproc
a>.調整Linux的最大文件打開數。
        vi /etc/security/limits.conf
          * soft nofile 65535
          * hard nofile 65535
          * soft nproc 65535
          * hard nproc 65535
         
b>.RHEL6下引入了配置文件
vi /etc/security/limits.d/90-nproc.conf
  * soft nproc 65535

c>.pam_limits.so 文件被加入到啓動文件
        vi /etc/pam.d/login
           session    required     /lib/security/pam_limits.so
           session    required     pam_limits.so
          
d>.重啓
reboot

#######只針對當前session會話,快速設置
[testuser@xxx-01 root]$  ulimit -u
1024
[testuser@xxx-01 root]$  ulimit -u 65535
[testuser@xxx-01 root]$  ulimit -u
65535
-n <文件數目>  指定同一時間最多可打開的文件數。  
-u <進程數目>  用戶最多可啓動的進程數目。 


2.網絡(兩個網絡相關的參數可以影響Hadoop的性能。net.core.somaxconn Linux內核設置能夠支持NameNode和JobTracker的大量爆發性的HTTP請求)
a>.net.core.somaxconn是listen()的默認參數,掛起請求的最大數量.默認是128.對繁忙的服務器,增加該值有助於網絡性能,當前已經被調整到32768
more /etc/sysctl.conf |grep net.core.somaxconn
sysctl -w net.core.somaxconn=32768 
echo net.core.somaxconn=32768 >> /etc/sysctl.conf


b>.設置txqueuelen到4096及以上能夠更好地適應在Hadoop集羣中的突發流量, txqueuelen代表用來傳輸數據的緩衝區的儲存長度,
通過下面的命令可以對該參數進行設置爲4096。
[testuser@xxx-01 conf]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:02:00:2B  
 inet addr:xx.xxx.xx.x  Bcast:xx.xxx.xx.xxx  Mask:255.255.255.0
 UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 RX packets:55072078 errors:0 dropped:0 overruns:0 frame:0
 TX packets:33328184 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000 
 RX bytes:23381014283 (21.7 GiB)  TX bytes:4464530654 (4.1 GiB)
   
  ###發現當前的eth0的txqueuelen值爲1000,設置爲4096
 [testuser@xxx-01 conf]# ifconfig eth0 txqueuelen 4096

3.關閉swap分區
        more /etc/sysctl.conf | vm.swappiness
        echo vm.swappiness = 0 >> /etc/sysctl.conf

4.設置合理的預讀取緩衝區(readahead buffer)大小
調整linux文件系統中預讀緩衝區地大小,可以明顯提高順序讀文件的性能。默認buffer大小爲256 sectors,可以增大爲1024或者2408 sectors(注意,並不是越大越好)。可使用blockdev命令進行調整。

[testuser@xxx-01 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G  7.1G   31G  19% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
/dev/vdb1       197G   36G  152G  19% /data/01
[testuser@xxx-01 ~]# 
[testuser@xxx-01 ~]# blockdev --report
RO    RA   SSZ   BSZ   StartSec            Size   Device
rw   256   512  4096          0     42949672960   /dev/vda
rw   256   512  4096       2048     42947575808   /dev/vda1
rw   256   512  4096          0    214748364800   /dev/vdb
rw   256   512  4096         63    214748029440   /dev/vdb1

### 修改/dev/vdb1的readahead buffer,因爲hadoop的dfs nn等等文件夾是在這個目錄下
   [testuser@xxx-01 ~]# blockdev --setra 1024 /dev/vdb1
     
5.I/O調度器選擇(一般不調整,只會在mapreduce中調整)
主流的Linux發行版自帶了很多可供選擇的I/O調度器。在數據密集型應用中,不同的I/O調度器性能表現差別較大,
管理員可根據自己的應用特點啓用最合適的I/O調度器

6.vm.overcommit_memory設置
進程通常調用malloc()函數來分配內存,內存決定是否有足夠的可用內存,並允許或拒絕內存分配的請求。Linux支持超量分配內存,以允許分配比可用RAM加上交換內存的請求。
    vm.overcommit_memory參數有三種可能的配置:
      0 表示檢查是否有足夠的內存可用,如果是,允許分配;如果內存不夠,拒絕該請求,並返回一個錯誤給應用程序。
      1 表示根據vm.overcommit_ratio定義的值,允許分配超出物理內存加上交換內存的請求。vm.overcommit_ratio參數是一個百分比,加上內存量決定內存可以超量分配多少內存。
     例如,vm.overcommit_ratio值爲50,而內存有1GB,那麼這意味着在內存分配請求失敗前,加上交換內存,內存將允許高達1.5GB的內存分配請求。
      2 表示內核總是返回true。
     除了以上幾個常見的Linux內核調優方法外,還有一些其他的方法,管理員可根據需要進行適當調整。
         
       【查看當前值】
# sysctl -n vm.overcommit_memory
       【永久性修改內核參數】
在/etc/sysctl.conf文件裏面加入或者直接刪除也可以,因爲它缺省值就是0
vm.overcommit_memory = 0
運行使之生效
#sysctl -p


7.Transparent Huge Page
已啓用“透明大頁面”,它可能會導致重大的性能問題。版本爲“CentOS release 6.3 (Final)”且版本爲“2.6.32-279.el6.x86_64”的 Kernel 已將 enabled 設置爲“[always] never”,並將 d
efrag 設置爲“[always] never”。請運行“echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag”以禁用此設置,然後將同一命令添加到一個 init 腳本中,
如 /etc/rc.local,這樣當系統重啓時就會設置它。或者,升級到 RHEL 6.4 或更新版本,它們不存在此錯誤。將會影響到以下主機。
      [testuser@xxx-01 ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/defrag
      [always] madvise never
      [testuser@xxx-01 ~]# echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag 
      [testuser@xxx-01 ~]# echo 'echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag' >> /etc/rc.local 
 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章