tmpfs加速并降低squid负载(一)
原因:
原squid速度慢,uptime看平均負(fù)載很高!
概念:一般負(fù)載峰值設(shè)為cpu個(gè)數(shù)的5倍。Load avarage/cpu數(shù)目 <3 系統(tǒng)良好,3到5之間可以接受,大于5 則可能有嚴(yán)重的性能問(wèn)題。舉個(gè)例子:假設(shè)系統(tǒng)有兩個(gè)cpu,那么負(fù)載在10以下都是可以接受的,超過(guò)10,就說(shuō)明有嚴(yán)重問(wèn)題了。
看cpu個(gè)數(shù):grep -c processor /proc/cpuinfo??????? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 關(guān)于負(fù)載的一篇好文章:http://ssorc.tw/logsprint.php?id=59
?
處理思路:
重新編譯,2.5換到2.6
'--prefix=/opt/squid' '--enable-async-io=40' '--enable-storeio=aufs,coss,diskd,ufs' '--enable-useragent-log' '--enable-referer-log' '--enable-kill-parent-hack' '--enable-forward-log' '--enable-snmp' '--enable-cache-digests' '--enable-default-err-language=Simplify_Chinese' '--enable-epoll' '--enable-removal-policies=heap,lru' '--enable-large-cache-files' '--disable-internal-dns' '--enable-x-accelerator-vary' '--enable-follow-x-forwarded-for' '--with-large-files' '--disable-ident-lookups' '--enable-underscore' '--disable-arp-acl' '--with-maxfd=65500'
?
修改內(nèi)核參數(shù)(因?yàn)門IME_WAIT太多)
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 1024??? 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
?
發(fā)現(xiàn)錯(cuò)誤:
WARNING: Disk space over limit: 5242944 KB > 5242880 KB
修改緩存策略:
原:
cache_dir aufs /var/squid/cache/cache01 5120 16 32
現(xiàn):
cache_replacement_policy heap GDSF
memory_replacement_policy heap GDSF
cache_dir aufs /var/squid/cache/cache01 5120 16 128
cache_dir aufs /var/squid/cache/cache02 5120 16 128
?
?
等待結(jié)果……….
?
現(xiàn)在發(fā)現(xiàn)的WARNING
WARNING:squidaio_queue_request: WARNING - Queue congestion
IO的隊(duì)列滿了, ,重諞一下源代碼,加大IO的隊(duì)列或換一種IO方式。
--enable-async-io=40 (40少了)
WARNING: All dnsserver processes are busy.
WARNING: up to 5 pending requests queued
?
?
修改為:
'--prefix=/opt/squid' '--enable-async-io=160' '--enable-storeio=aufs,coss,diskd,ufs' '--enable-useragent-log' '--enable-referer-log' '--enable-kill-parent-hack' '--enable-forward-log' '--enable-snmp' '--enable-cache-digests' '--enable-default-err-language=Simplify_Chinese' '--enable-epoll' '--enable-removal-policies=heap,lru' '--enable-large-cache-files' '--disable-internal-dns' '--enable-x-accelerator-vary' '--enable-follow-x-forwarded-for' '--with-large-files' '--disable-ident-lookups' '--enable-underscore' '--disable-arp-acl' '--with-maxfd=65500'
?
?
查看平均負(fù)載并未降低:
[root@SQUID99 ~]# vmstat 2
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
?r? b?? swpd?? free?? buff? cache?? si?? so??? bi??? bo?? in??? cs us sy id wa
?0? 0????? 0 2655000 363884 3002856??? 0??? 0???? 5?? 157??? 0???? 3? 1? 1 92? 6
?0? 2????? 0 2652696 363920 3004380??? 0??? 0??? 78? 2286 7076? 3115? 3? 1 86 11
?0? 0????? 0 2652376 363972 3004588??? 0??? 0??? 26? 5246 3336? 1136? 1? 0 88 11
?0? 5????? 0 2651288 364000 3005860??? 0??? 0??? 66?? 792 5888? 3395? 3? 1 87? 9
?0? 0????? 0 2650448 364044 3007116??? 0??? 0??? 72? 1410 5600? 3265? 3? 1 92? 4
?1? 0????? 0 2648128 364092 3008888??? 0??? 0?? 110???? 0 7257? 4573? 4? 1 94? 1
?0? 4????? 0 2647952 364116 3009124??? 0??? 0??? 32? 2828 4046? 1553? 1? 0 82 16
bo,對(duì)磁盤的寫入,這個(gè)數(shù)字偏大
補(bǔ)充:查看磁盤的性能 使用 iostat -d 2這樣的命令:
Device: 設(shè)備或者分區(qū)名
tps:每秒發(fā)送到設(shè)備上的IO請(qǐng)求次數(shù) ?
Blk_read/s:設(shè)備每秒鐘讀的數(shù)據(jù)(KB/秒) ?
Blk_wrtn/s:設(shè)備每秒鐘寫的數(shù)據(jù)(KB/秒)?
Blk_read:設(shè)備讀數(shù)據(jù)的總大小(KB)
Blk_wrtn:設(shè)備寫數(shù)據(jù)的總大小(KB)
?
懷疑是磁盤cache文件太多,并且全為小文件
Store Directory #0 (aufs): /var/squid/cache/cache01
FS Block Size 4096 Bytes
First level subdirectories: 16
Second level subdirectories: 128
Maximum Size: 5242880 KB
Current Size: 4618916 KB
Percent Used: 88.10%
Current load metric: 102 / 1000
Filemap bits in use: 1037841 of 1048576 (99%)
Filesystem Space in use: 10222176/82518992 KB (12%)
Filesystem Inodes in use: 2082702/10485760 (20%)
Flags: SELECTED
Accepted object sizes: 0 - (unlimited) bytes
Removal policy: heap
?
嘗試用內(nèi)存作為cache,取消磁盤cache:
方法轉(zhuǎn)自:
http://www.5ilinux.com/blog/archives/000075.html
巧用tmpfs加速你的linux服務(wù)器
原理:使用tmpfs來(lái)實(shí)現(xiàn)虛擬磁盤來(lái)存放squid的緩存文件
默認(rèn)系統(tǒng)就會(huì)加載/dev/shm ,它就是所謂的tmpfs,有人說(shuō)跟ramdisk(虛擬磁盤),但不一樣。象虛擬磁盤一樣,tmpfs 可以使用您的 RAM,但它也可以使用您的交換分區(qū)來(lái)存儲(chǔ)。而且傳統(tǒng)的虛擬磁盤是個(gè)塊設(shè)備,并需要一個(gè) mkfs 之類的命令才能真正地使用它,tmpfs 是一個(gè)文件系統(tǒng),而不是塊設(shè)備;您只是安裝它,它就可以使用了。
tmpfs有以下優(yōu)勢(shì):
1。動(dòng)態(tài)文件系統(tǒng)的大小,
2。tmpfs 的另一個(gè)主要的好處是它閃電般的速度。因?yàn)榈湫偷?tmpfs 文件系統(tǒng)會(huì)完全駐留在 RAM 中,讀寫幾乎可以是瞬間的。
3。tmpfs 數(shù)據(jù)在重新啟動(dòng)之后不會(huì)保留,因?yàn)樘摂M內(nèi)存本質(zhì)上就是易失的。所以有必要做一些腳本做諸如加載,綁定的操作。
首先在/dev/stm建個(gè)tmp文件夾,然后與實(shí)際/tmp綁定
mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp
默認(rèn)shm是使用實(shí)際內(nèi)存的一半
1。squid的緩存目錄設(shè)置
vi /etc/squid/squid.conf
修改成
cache_dir ufs /tmp 256 16 256
這里的第一個(gè)256表示使用256M內(nèi)存,我覺(jué)得高性能LINUX雙效防火墻HOWTO使用ramdisk的方法還不如直接使用tmpfs,至少每次啟動(dòng)不用mkfs,還可以動(dòng)態(tài)改變大小。
然后重啟一下服務(wù),ok,現(xiàn)在所有的squid緩存文件都保存倒tmpfs文件系統(tǒng)里了,很快哦。
?
?運(yùn)行一天后的結(jié)果,效果還是很明顯,負(fù)載從12下降到了0.3!!并且vmstat查看也有很大變化
?
[root@SQUID95 ~]# uptime
?09:25:07 up 118 days, 21:19,? 2 users,? load average: 0.32, 0.34, 0.27
?
[root@SQUID95 ~]# vmstat 2
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
?r? b?? swpd?? free?? buff? cache?? si?? so??? bi??? bo?? in??? cs us sy id wa
?0? 0??? 208 3978912 198916 2286424??? 0??? 0??? 11??? 19??? 0???? 0? 1? 1 95? 4
?0? 0??? 208 3978784 198916 2286684??? 0??? 0???? 0??? 50 7868? 4551? 2? 1 97? 0
?0? 0??? 208 3978848 198916 2285904??? 0??? 0???? 0???? 0 6302? 3639? 2? 0 98? 0
?1? 1??? 208 3978656 198944 2286656??? 0??? 0???? 0??? 40 12740? 6353? 6? 2 92? 0
?1? 0??? 208 3978464 198956 2286644??? 0??? 0???? 0?? 154 10673? 5910? 4? 1 95? 0
?0? 0??? 208 3977952 198956 2286904??? 0??? 0???? 0???? 0 10292? 5477? 4? 1 95? 0
?0? 0??? 208 3977904 198956 2287164??? 0??? 0???? 0?? 152 8622? 5113? 3? 1 96? 0
?
[root@SQUID95 ~]# df -h
Filesystem??????????? Size? Used Avail Use% Mounted on
/dev/cciss/c0d0p2????? 29G? 1.1G?? 27G?? 4% /
/dev/cciss/c0d0p1????? 99M?? 12M?? 82M? 13% /boot
none????????????????? 4.0G? 1.4G? 2.6G? 35% /dev/shm
/dev/cciss/c0d0p3????? 20G? 1.8G?? 17G? 10% /usr
/dev/cciss/c0d0p6????? 79G?? 25G?? 51G? 33% /var
/dev/shm/tmp????????? 4.0G? 1.4G? 2.6G? 35% /tmp
?
磁盤緩存和RAM緩存比較:
1.磁盤緩存重要在緩存,機(jī)器down機(jī)或者重啟都沒(méi)有影響,但是不斷對(duì)磁盤進(jìn)行讀寫,負(fù)載會(huì)高
2.RAM緩存重要在速度,因?yàn)槭莾?nèi)存讀寫,速度很快,但是緩存的文件沒(méi)有保證,機(jī)器一旦重啟,緩存文件將丟失。
但是選擇磁盤緩存還是RAM緩存,還是應(yīng)該看自己的實(shí)際情況,對(duì)于我這邊,由于是單點(diǎn),都是本地抓取文件,速度很快,所以緩存就顯的不是那么重要。
?
實(shí)際應(yīng)用出現(xiàn)的問(wèn)題:
df -h 看
/dev/shm/tmp????????? 4.0G? 1.4G? 2.6G? 35% /tmp 明顯空間還很多
但是cache.log中大量報(bào)錯(cuò):
2009/08/11 17:06:47|/tmp/swap.state.new: (28) No space left on device
?????????????????? |FATAL: storeDirOpenTmpSwapLog: Failed to open swap log.
2009/08/11 17:06:47| storeAufsOpenDone: (28) No space left on device
2009/08/11 17:06:47|??? /tmp/0C/4B/000325CF
2009/08/11 17:06:47| storeSwapOutFileClosed: dirno 0, swapfile 000325CF, errflag=-1
??????? (28) No space left on device
2009/08/11 17:06:47| storeAufsOpenDone: (28) No space left on device
2009/08/11 17:06:47|??? /tmp/0C/4B/000325CF
2009/08/11 17:06:47| storeSwapOutFileClosed: dirno 0, swapfile 000325CF, errflag=-1
??????? (28) No space left on device
2009/08/11 17:06:47| storeAufsOpenDone: (28) No space left on device
然后df -i 發(fā)現(xiàn)問(wèn)題:
/dev/shm/tmp????????? 209923? 209923?????? 0? 100% /tmp
innodes被用光了!
查看一些資料,發(fā)現(xiàn)在mount tmp這個(gè)虛擬分區(qū)的時(shí)候可以修改inodes
mount -t tmpfs -o size=1G,nr_inodes=40k,mode=0700 tmpfs /tmp
大小為1G,inodes40K=40960
可是問(wèn)題又出現(xiàn)了,squid不會(huì)自己清cache,直到磁盤用光down掉!
棘手的問(wèn)題。
轉(zhuǎn)載于:https://www.cnblogs.com/youlechang123/archive/2012/08/10/2631169.html
總結(jié)
以上是生活随笔為你收集整理的tmpfs加速并降低squid负载(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Objective C 基础教程
- 下一篇: 1.jstl之SQL:setDataSo