tmpfs加速并降低squid负载(一)
原因:
原squid速度慢,uptime看平均負載很高!
概念:一般負載峰值設為cpu個數的5倍。Load avarage/cpu數目 <3 系統良好,3到5之間可以接受,大于5 則可能有嚴重的性能問題。舉個例子:假設系統有兩個cpu,那么負載在10以下都是可以接受的,超過10,就說明有嚴重問題了。
看cpu個數:grep -c processor /proc/cpuinfo??????? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 關于負載的一篇好文章: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'
?
修改內核參數(因為TIME_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
?
發現錯誤:
WARNING: Disk space over limit: 5242944 KB > 5242880 KB
修改緩存策略:
原:
cache_dir aufs /var/squid/cache/cache01 5120 16 32
現:
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
?
?
等待結果……….
?
現在發現的WARNING
WARNING:squidaio_queue_request: WARNING - Queue congestion
IO的隊列滿了, ,重諞一下源代碼,加大IO的隊列或換一種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'
?
?
查看平均負載并未降低:
[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,對磁盤的寫入,這個數字偏大
補充:查看磁盤的性能 使用 iostat -d 2這樣的命令:
Device: 設備或者分區名
tps:每秒發送到設備上的IO請求次數 ?
Blk_read/s:設備每秒鐘讀的數據(KB/秒) ?
Blk_wrtn/s:設備每秒鐘寫的數據(KB/秒)?
Blk_read:設備讀數據的總大小(KB)
Blk_wrtn:設備寫數據的總大小(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
?
嘗試用內存作為cache,取消磁盤cache:
方法轉自:
http://www.5ilinux.com/blog/archives/000075.html
巧用tmpfs加速你的linux服務器
原理:使用tmpfs來實現虛擬磁盤來存放squid的緩存文件
默認系統就會加載/dev/shm ,它就是所謂的tmpfs,有人說跟ramdisk(虛擬磁盤),但不一樣。象虛擬磁盤一樣,tmpfs 可以使用您的 RAM,但它也可以使用您的交換分區來存儲。而且傳統的虛擬磁盤是個塊設備,并需要一個 mkfs 之類的命令才能真正地使用它,tmpfs 是一個文件系統,而不是塊設備;您只是安裝它,它就可以使用了。
tmpfs有以下優勢:
1。動態文件系統的大小,
2。tmpfs 的另一個主要的好處是它閃電般的速度。因為典型的 tmpfs 文件系統會完全駐留在 RAM 中,讀寫幾乎可以是瞬間的。
3。tmpfs 數據在重新啟動之后不會保留,因為虛擬內存本質上就是易失的。所以有必要做一些腳本做諸如加載,綁定的操作。
首先在/dev/stm建個tmp文件夾,然后與實際/tmp綁定
mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp
默認shm是使用實際內存的一半
1。squid的緩存目錄設置
vi /etc/squid/squid.conf
修改成
cache_dir ufs /tmp 256 16 256
這里的第一個256表示使用256M內存,我覺得高性能LINUX雙效防火墻HOWTO使用ramdisk的方法還不如直接使用tmpfs,至少每次啟動不用mkfs,還可以動態改變大小。
然后重啟一下服務,ok,現在所有的squid緩存文件都保存倒tmpfs文件系統里了,很快哦。
?
?運行一天后的結果,效果還是很明顯,負載從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.磁盤緩存重要在緩存,機器down機或者重啟都沒有影響,但是不斷對磁盤進行讀寫,負載會高
2.RAM緩存重要在速度,因為是內存讀寫,速度很快,但是緩存的文件沒有保證,機器一旦重啟,緩存文件將丟失。
但是選擇磁盤緩存還是RAM緩存,還是應該看自己的實際情況,對于我這邊,由于是單點,都是本地抓取文件,速度很快,所以緩存就顯的不是那么重要。
?
實際應用出現的問題:
df -h 看
/dev/shm/tmp????????? 4.0G? 1.4G? 2.6G? 35% /tmp 明顯空間還很多
但是cache.log中大量報錯:
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 發現問題:
/dev/shm/tmp????????? 209923? 209923?????? 0? 100% /tmp
innodes被用光了!
查看一些資料,發現在mount tmp這個虛擬分區的時候可以修改inodes
mount -t tmpfs -o size=1G,nr_inodes=40k,mode=0700 tmpfs /tmp
大小為1G,inodes40K=40960
可是問題又出現了,squid不會自己清cache,直到磁盤用光down掉!
棘手的問題。
轉載于:https://www.cnblogs.com/youlechang123/archive/2012/08/10/2631169.html
總結
以上是生活随笔為你收集整理的tmpfs加速并降低squid负载(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Objective C 基础教程
- 下一篇: 1.jstl之SQL:setDataSo