您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)怎么解決redis連接超時(shí)問題的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
問題描述:
redis連接超時(shí),然后定位到redis配置文件目錄被刪除,接著嘗試重啟redis,發(fā)現(xiàn)連接中斷,未啟動(dòng)成功。
報(bào)錯(cuò):
查看redis的輸出日志。出現(xiàn)下圖所示的報(bào)錯(cuò):
根據(jù)提示在/etc/sysctl.conf文件中添加vm.overcommit_memory = 1,
修改其大透明頁,并將調(diào)整redis的timeout從300到500重啟正常;
echo never > /sys/kernel/mm/transparent_hugepage/enabled
關(guān)于vm.overcommit_memory
它是 內(nèi)存分配策略 可選值:0、1、2。0, 表示內(nèi)核將檢查是否有足夠的可用內(nèi)存供應(yīng)用進(jìn)程使用;如果有足夠的可用內(nèi)存,內(nèi)存申請?jiān)试S;否則,內(nèi)存申請失敗,并把錯(cuò)誤返回給應(yīng)用進(jìn)程。1, 表示內(nèi)核允許分配所有的物理內(nèi)存,而不管當(dāng)前的內(nèi)存狀態(tài)如何。2, 表示內(nèi)核允許分配超過所有物理內(nèi)存和交換空間總和的內(nèi)存
關(guān)于Overcommit和OOM
Linux對(duì)大部分申請內(nèi)存的請求都回復(fù)"yes",以便能跑更多更大的程序。因?yàn)樯暾垉?nèi)存后,并不會(huì)馬上使用內(nèi)存。這種技術(shù)叫做 Overcommit。 當(dāng)linux發(fā)現(xiàn)內(nèi)存不足時(shí),會(huì)發(fā)生OOM killer(OOM=out-of-memory)。它會(huì)選擇殺死一些進(jìn)程(用戶態(tài)進(jìn)程,不是內(nèi)核線程),以便釋放內(nèi)存。 當(dāng)oom-killer發(fā)生時(shí),linux會(huì)選擇殺死哪些進(jìn)程?選擇進(jìn)程的函數(shù)是oom_badness函數(shù)(在mm/oom_kill.c中),該 函數(shù)會(huì)計(jì)算每個(gè)進(jìn)程的點(diǎn)數(shù)(0~1000)。 點(diǎn)數(shù)越高,這個(gè)進(jìn)程越有可能被殺死。每個(gè)進(jìn)程的點(diǎn)數(shù)跟oom_score_adj有關(guān),而且 oom_score_adj可以被設(shè)置(-1000最低,1000最高)。
關(guān)于/sys/kernel/mm/transparent_hugepage/enabled
透明大頁介紹 Transparent Huge Pages的一些官方介紹資料: Transparent Huge Pages (THP) are enabled by default in RHEL 6 for all applications. The kernel attempts to allocate hugepages whenever possible and any Linux process will receive 2MB pages if the mmap region is 2MB naturally aligned. The main kernel address space itself is mapped with hugepages, reducing TLB pressure from kernel code. For general information on Hugepages, see: What are Huge Pages and what are the advantages of using them? The kernel will always attempt to satisfy a memory allocation using hugepages. If no hugepages are available (due to non availability of physically continuous memory for example) the kernel will fall back to the regular 4KB pages. THP are also swappable (unlike hugetlbfs). This is achieved by breaking the huge page to smaller 4KB pages, which are then swapped out normally. But to use hugepages effectively, the kernel must find physically continuous areas of memory big enough to satisfy the request, and also properly aligned. For this, a khugepaged kernel thread has been added. This thread will occasionally attempt to substitute smaller pages being used currently with a hugepage allocation, thus maximizing THP usage. In userland, no modifications to the applications are necessary (hence transparent). But there are ways to optimize its use. For applications that want to use hugepages, use of posix_memalign() can also help ensure that large allocations are aligned to huge page (2MB) boundaries. Also, THP is only enabled for anonymous memory regions. There are plans to add support for tmpfs and page cache. THP tunables are found in the /sys tree under /sys/kernel/mm/redhat_transparent_hugepage.
查看是否啟用透明大頁
cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never使用命令查看時(shí),如果輸出結(jié)果為[always]表示透明大頁啟用了。[never]表示透明大頁禁用、[madvise]表示(只在MADV_HUGEPAGE標(biāo)志的VMA中使用THP 如何HugePages_Total返回0,也意味著標(biāo)準(zhǔn)大頁禁用了(注意傳統(tǒng)/標(biāo)準(zhǔn)大頁和透明大頁的區(qū)別) 透明大頁(THP)管理和標(biāo)準(zhǔn)/傳統(tǒng)大頁(HP)管理都是操作系統(tǒng)為了減少頁表轉(zhuǎn)換消耗的資源而發(fā)布的新特性,雖然ORACLE建議利用大頁機(jī)制來提高數(shù)據(jù)庫的性能,但是ORACLE卻同時(shí)建議關(guān)閉透明大頁管理。這二者的區(qū)別在于大頁的分配機(jī)制,標(biāo)準(zhǔn)大頁管理是預(yù)分配的方式,而透明大頁管理則是動(dòng)態(tài)分配的方式。 [root@appnode001 ~]# grep -i HugePages_Total /proc/meminfo HugePages_Total: 0 cat /proc/sys/vm/nr_hugepages返回0也意味著傳統(tǒng)大頁禁用了(傳統(tǒng)大頁和透明大頁)。[root@appnode001 ~]# cat /proc/sys/vm/nr_hugepages 0
感謝各位的閱讀!關(guān)于“怎么解決redis連接超時(shí)問題”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。