Home > Database > Redis > How to solve the redis connection timeout problem

How to solve the redis connection timeout problem

王林
Release: 2021-03-01 09:39:54
forward
9656 people have browsed it

How to solve the redis connection timeout problem

Problem description:

The redis connection timed out, and then the redis configuration file directory was located and deleted. Then I tried to restart redis, and found that the connection was interrupted and the startup was not successful.

Error report:

View the redis output log. The error message shown in the figure below appears:

How to solve the redis connection timeout problem

Add vm.overcommit_memory = 1 in the /etc/sysctl.conf file according to the prompts,

How to solve the redis connection timeout problem

How to solve the redis connection timeout problem

Modify its large transparent page and adjust the timeout of redis from 300 to 500 to restart normally;

(Learning video sharing: redis video Tutorial)

echo never > /sys/kernel/mm/transparent_hugepage/enabled
Copy after login

How to solve the redis connection timeout problem

About vm.overcommit_memory

它是 内存分配策略
可选值:0、1、2。0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。2, 表示内核允许分配超过所有物理内存和交换空间总和的内存
Copy after login

About Overcommit and OOM

Linux对大部分申请内存的请求都回复"yes",以便能跑更多更大的程序。因为申请内存后,并不会马上使用内存。这种技术叫做 Overcommit。
当linux发现内存不足时,会发生OOM killer(OOM=out-of-memory)。它会选择杀死一些进程(用户态进程,不是内核线程),以便释放内存。
当oom-killer发生时,linux会选择杀死哪些进程?选择进程的函数是oom_badness函数(在mm/oom_kill.c中),该 函数会计算每个进程的点数(0~1000)。
点数越高,这个进程越有可能被杀死。每个进程的点数跟oom_score_adj有关,而且 oom_score_adj可以被设置(-1000最低,1000最高)。
Copy after login

About /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.
Copy after login

Check whether transparent huge pages are enabled

cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never使用命令查看时,如果输出结果为[always]表示透明大页启用了。[never]表示透明大页禁用、[madvise]表示(只在MADV_HUGEPAGE标志的VMA中使用THP
如何HugePages_Total返回0,也意味着标准大页禁用了(注意传统/标准大页和透明大页的区别)
透明大页(THP)管理和标准/传统大页(HP)管理都是操作系统为了减少页表转换消耗的资源而发布的新特性,虽然ORACLE建议利用大页机制来提高数据库的性能,但是ORACLE却同时建议关闭透明大页管理。这二者的区别在于大页的分配机制,标准大页管理是预分配的方式,而透明大页管理则是动态分配的方式。
[root@appnode001 ~]# grep -i HugePages_Total /proc/meminfo 
HugePages_Total:       0

cat /proc/sys/vm/nr_hugepages返回0也意味着传统大页禁用了(传统大页和透明大页)。[root@appnode001 ~]# cat /proc/sys/vm/nr_hugepages
0
Copy after login

Related recommendations: redis database tutorial

The above is the detailed content of How to solve the redis connection timeout problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template