|
在上一篇中http://maoyidao./blog/1744309,主要介紹了和系統(tǒng)資源限制相關(guān)的參數(shù)。本文是通訊系統(tǒng)經(jīng)驗(yàn)談的第三部分,繼續(xù)解讀和系統(tǒng)性能相關(guān)的內(nèi)核配置。
上篇介紹了和系統(tǒng)設(shè)置有關(guān)的幾個(gè)參數(shù),在一臺(tái)系統(tǒng)上,連接到一個(gè)服務(wù)時(shí)的本地端口是有限的。由于端口是16位整數(shù),也就只能是0到65535,而0到1023是預(yù)留端口,所以能分配的只是 1024到65534,也就是64511個(gè)。也就是說,一臺(tái)機(jī)器只能創(chuàng)建六萬多個(gè)長連接。查看本機(jī)端口設(shè)置: maoyidao 寫道
sysctl -a | grep port_range
net.ipv4.ip_local_port_range = 1024 65000 /etc/sysctl.conf配置1. syncookiesnet.ipv4.tcp_syncookies = 1 防止 SYN Flooding攻擊,詳見:http://maoyidao./admin/blogs/1744277 2. syn-ack#net.ipv4.tcp_synack_retries= maoyidao注:syn-ack握手狀態(tài)重試次數(shù),默認(rèn)5,網(wǎng)上有朋友說可改為1或2;通常我的建議是如果沒有試驗(yàn)證明在特定場(chǎng)景下明顯優(yōu)勢(shì),不要修改默認(rèn)值,因此本場(chǎng)此參數(shù)未指定 3. 內(nèi)核消息/內(nèi)存管理設(shè)置kernel.msgmnb = 65536 kernel.msgmax = 65536
指定內(nèi)核中消息隊(duì)列中消息的最大值(msgmax=64k),default:8192 所有在消息隊(duì)列中的消息總和的最大值(msgmnb=64k),默認(rèn)值:16384 即從一個(gè)進(jìn)程發(fā)送到另一個(gè)進(jìn)程的消息的最大長度(bytes),進(jìn)程間的消息傳遞是在內(nèi)核的內(nèi)存中進(jìn)行的,不會(huì)交換到磁盤上,所以如果增加該值,則將增加操作系統(tǒng)所使用的內(nèi)存數(shù)量。
maoyidao注:增大消息隊(duì)列內(nèi)存值,提高IPC效率
kernel.shmmax = 68719476736 Shmmax 是核心參數(shù)中最重要的參數(shù)之一,用于定義單個(gè)共享內(nèi)存段的最大值,shmmax 設(shè)置應(yīng)該足夠大,能在一個(gè)共享內(nèi)存段下容納下整個(gè)的SGA ,設(shè)置的過低可能會(huì)導(dǎo)致需要?jiǎng)?chuàng)建多個(gè)共享內(nèi)存段,這樣可能導(dǎo)致系統(tǒng)性能的下降 。32bit系統(tǒng)中可以設(shè)置為系統(tǒng)可支撐的最大值:4G;本系統(tǒng)中設(shè)置為64G(這個(gè)值實(shí)際上超過了前端機(jī)的最大內(nèi)存12G),內(nèi)存型服務(wù)器,比如96G,或128G服務(wù)器應(yīng)該設(shè)置的更大。
kernel.shmall = 4294967296 含義:系統(tǒng)中共享內(nèi)存頁總 getconf PAGESIZE 4096 total bytes = 4294967296 * 4096 = 16G 4. 網(wǎng)絡(luò)設(shè)置# 三個(gè)整數(shù)的向量: min, default, max net.ipv4.tcp_rmem = 8192 87380 8738000 # min = 4k (same as pagesize), default = 64k, max = 6.25m net.ipv4.tcp_wmem = 4096 65536 6553600 # # net.core.rmem_max = 16777216 net.core.wmem_max = 16777216
以上參數(shù)的配置可以參考:
http://fasterdata./host-tuning/linux/ 寫道
# increase TCP max buffer size settable using setsockopt()
net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 # increase Linux autotuning TCP buffer limit net.ipv4.tcp_rmem = 4096 87380 16777216 net.ipv4.tcp_wmem = 4096 65536 16777216 # 安全策略 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.default.arp_ignore = 1 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.ip_no_pmtu_disc = 1
# 含義:當(dāng)啟用keepalive的時(shí)候,TCP發(fā)送keepalive消息的頻度 net.ipv4.tcp_keepalive_time = 1800
# Controls IP packet forwarding # 作為前端服務(wù)器,禁制IP轉(zhuǎn)發(fā),這個(gè)沒什么好說的; net.ipv4.ip_forward = 0
# Controls source route verification # 開啟反向路徑過濾 net.ipv4.conf.default.rp_filter = 1
# 含義:記錄的那些尚未收到客戶端確認(rèn)信息的鏈接請(qǐng)求的最大值。 默認(rèn)值為4096 如果設(shè)置這個(gè)值大于4096最好同時(shí)調(diào) # 整include/net/tcp.h中的TCP_SYNQ_HSIZE,保證TCP_SYNQ_HSIZE*16 小于或等于tcp_max_syn_backlo, # 然后重新編譯內(nèi)核。 net.ipv4.tcp_max_syn_backlog = 8192 |
|
|