记一次MySQL5初始化被kill的问题排查 | 京东云技术团队

news2024/11/24 13:42:42

写在前面

由于测试环境JED申请比较繁琐,所以Eone提供了单机版Mysql供用户使用,近期Eone搭建Mysql5的时候发现莫名被kill了,容器规格是4C8G,磁盘30G

这不科学,之前都是可以的,镜像没变,配置没变,咋就不行了呢,一定不是我的问题,是机器的问题

问题排查

重现

通过多次搭建mysql5进行采样,发现并不是稳定复现,有一些容器是可以正常启动提供服务的,找到被mysql服务被kill的容器日志,发现是MySQL初始化被kill了,

/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/export/data/mysql/data --user=admin --initialize-insecure

mysql配置文件:

[client]
socket=/tmp/mysql.sock

[mysqld]
basedir=/usr/local/mysql
datadir=/export/data/mysql/data
port=3306
server_id=1
socket=/tmp/mysql.sock
log-error=/tmp/mysqld.err
pid-file=/tmp/mysqld.pid

skip-host-cache
skip-name-resolve
skip-grant-tables



问题排查

初始化为什么被kill?

手动执行了下初始化的命令,发现直接被kill了

通过dmesg命令发现,貌似oom了

纳尼?怎么用了这么多内存?容器都没这么大内存诶

通过排查,发现MySQL有一个8G的匿名内存,这是哪来的???

将容器规格调整为32G内存,再次尝试,发现成功启动了,但是内存占用貌似不太正常

这不科学,正常的容器内存使用情况是这样的👇

MySQL配置不合理?

难道是因为mysql设置的大小不合理?默认不设置innodb_buffer_pool_size按理说应该是128M才对,抱着侥幸心理设置下试下

然而问题依旧,改了配置也没有效果,看来不是配置的问题

真是机器的问题?

对比了一下正常启动的机器,拿着ip找到运维,发现异常的机器是近期添加的云舰系统的机器,之前centos系统宿主机是正常的,新加的云舰系统宿主机都是异常的,看来真是机器的问题,这两台机器有啥差别呢,接下来运维同学开启了排查之路:

1. 首先,看看两台宿主机是不是物理CPU总数不一样

2. 再确认下CentOS是否开启了富容器功能

对比了下两台宿主机的资源配置,发现好像是资源配置的问题

正常的机器配置是这样的

或许真的有可能,修改下open files限制再试下

ulimit -n 1048576

竟然可以了!!!MySQL正常提供服务了,真的是机器的问题

问题分析

strace log分析
28139 execve("/usr/local/mysql/bin/mysqld-debug", ["/usr/local/mysql/bin/mysqld-debu"..., "--initialize-insecure", "--basedir=/usr/local/mysql", "--datadir=/export/data/mysql/dat"..., "--user=admin"], 0x7ffe74bdcbe8 /* 294 vars */) = 0
28139 brk(NULL)                         = 0x4b50000
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bf6000
28139 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
28139 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
28139 fstat(3, {st_mode=S_IFREG|0644, st_size=16580, ...}) = 0
28139 mmap(NULL, 16580, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f93d3bf1000
28139 close(3)                          = 0
28139 open("/lib64/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240l\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=142304, ...}) = 0
28139 mmap(NULL, 2208864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d37ba000
28139 mprotect(0x7f93d37d0000, 2097152, PROT_NONE) = 0
28139 mmap(0x7f93d39d0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16000) = 0x7f93d39d0000
28139 mmap(0x7f93d39d2000, 13408, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f93d39d2000
28139 close(3)                          = 0
28139 open("/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\16\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=19520, ...}) = 0
28139 mmap(NULL, 2109744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d35b6000
28139 mprotect(0x7f93d35b9000, 2093056, PROT_NONE) = 0
28139 mmap(0x7f93d37b8000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f93d37b8000
28139 close(3)                          = 0
28139 open("/lib64/libaio.so.1", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\5\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=6264, ...}) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bf0000
28139 mmap(NULL, 2101328, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d33b4000
28139 mprotect(0x7f93d33b5000, 2093056, PROT_NONE) = 0
28139 mmap(0x7f93d35b4000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x7f93d35b4000
28139 close(3)                          = 0
28139 open("/lib64/libnuma.so.1", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0004\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=50704, ...}) = 0
28139 mmap(NULL, 2144448, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d31a8000
28139 mprotect(0x7f93d31b2000, 2097152, PROT_NONE) = 0
28139 mmap(0x7f93d33b2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa000) = 0x7f93d33b2000
28139 close(3)                          = 0
28139 open("/lib64/libcrypt.so.1", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\16\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=40816, ...}) = 0
28139 mmap(NULL, 2318912, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d2f71000
28139 mprotect(0x7f93d2f79000, 2093056, PROT_NONE) = 0
28139 mmap(0x7f93d3178000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7000) = 0x7f93d3178000
28139 mmap(0x7f93d317a000, 184896, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f93d317a000
28139 close(3)                          = 0
28139 open("/lib64/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\"\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=44096, ...}) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bef000
28139 mmap(NULL, 2128952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d2d69000
28139 mprotect(0x7f93d2d70000, 2093056, PROT_NONE) = 0
28139 mmap(0x7f93d2f6f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f93d2f6f000
28139 close(3)                          = 0
28139 open("/lib64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\264\5\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=995840, ...}) = 0
28139 mmap(NULL, 3175456, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d2a61000
28139 mprotect(0x7f93d2b4a000, 2097152, PROT_NONE) = 0
28139 mmap(0x7f93d2d4a000, 40960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe9000) = 0x7f93d2d4a000
28139 mmap(0x7f93d2d54000, 82976, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f93d2d54000
28139 close(3)                          = 0
28139 open("/lib64/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260T\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=1141560, ...}) = 0
28139 mmap(NULL, 3150168, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d275f000
28139 mprotect(0x7f93d2860000, 2093056, PROT_NONE) = 0
28139 mmap(0x7f93d2a5f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x100000) = 0x7f93d2a5f000
28139 close(3)                          = 0
28139 open("/lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320*\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=88720, ...}) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bee000
28139 mmap(NULL, 2184192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d2549000
28139 mprotect(0x7f93d255e000, 2093056, PROT_NONE) = 0
28139 mmap(0x7f93d275d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x7f93d275d000
28139 close(3)                          = 0
28139 open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \34\2\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=2112384, ...}) = 0
28139 mmap(NULL, 3936832, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d2187000
28139 mprotect(0x7f93d233e000, 2097152, PROT_NONE) = 0
28139 mmap(0x7f93d253e000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b7000) = 0x7f93d253e000
28139 mmap(0x7f93d2544000, 16960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f93d2544000
28139 close(3)                          = 0
28139 open("/lib64/libfreebl3.so", O_RDONLY|O_CLOEXEC) = 3
28139 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\v\0\0\0\0\0\0"..., 832) = 832
28139 fstat(3, {st_mode=S_IFREG|0755, st_size=11376, ...}) = 0
28139 mmap(NULL, 2105536, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f93d1f84000
28139 mprotect(0x7f93d1f86000, 2093056, PROT_NONE) = 0
28139 mmap(0x7f93d2185000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f93d2185000
28139 close(3)                          = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bed000
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bec000
28139 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bea000
28139 arch_prctl(ARCH_SET_FS, 0x7f93d3bea740) = 0
28139 mprotect(0x7f93d253e000, 16384, PROT_READ) = 0
28139 mprotect(0x7f93d37b8000, 4096, PROT_READ) = 0
28139 mprotect(0x7f93d2185000, 4096, PROT_READ) = 0
28139 mprotect(0x7f93d275d000, 4096, PROT_READ) = 0
28139 mprotect(0x7f93d2a5f000, 4096, PROT_READ) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3be9000
28139 mprotect(0x7f93d2d4a000, 32768, PROT_READ) = 0
28139 mprotect(0x7f93d39d0000, 4096, PROT_READ) = 0
28139 mprotect(0x7f93d2f6f000, 4096, PROT_READ) = 0
28139 mprotect(0x7f93d3178000, 4096, PROT_READ) = 0
28139 mprotect(0x7f93d33b2000, 4096, PROT_READ) = 0
28139 mprotect(0x7f93d35b4000, 4096, PROT_READ) = 0
28139 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3be7000
28139 mprotect(0x7f93d3bf7000, 4096, PROT_READ) = 0
28139 munmap(0x7f93d3bf1000, 16580)     = 0
28139 set_tid_address(0x7f93d3beaa10)   = 28139
28139 set_robust_list(0x7f93d3beaa20, 24) = 0
28139 rt_sigaction(SIGRTMIN, {sa_handler=0x7f93d37c0780, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7f93d37c9100}, NULL, 8) = 0
28139 rt_sigaction(SIGRT_1, {sa_handler=0x7f93d37c0810, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f93d37c9100}, NULL, 8) = 0
28139 rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
28139 getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
28139 brk(NULL)                         = 0x4b50000
28139 brk(0x4b71000)                    = 0x4b71000
28139 open("/proc/self/status", O_RDONLY) = 3
28139 fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bf5000
28139 read(3, "Name:\tmysqld-debug\nUmask:\t0022\nS"..., 1024) = 1024
28139 read(3, "0,00000000,00000000,00000000,000"..., 1024) = 334
28139 close(3)                          = 0
28139 munmap(0x7f93d3bf5000, 4096)      = 0
28139 openat(AT_FDCWD, "/sys/devices/system/node", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
28139 getdents(3, /* 11 entries */, 32768) = 360
28139 open("/sys/devices/system/node/node0/meminfo", O_RDONLY) = 4
28139 fstat(4, {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bf5000
28139 read(4, "Node 0 MemTotal:       226242196"..., 4096) = 1175
28139 stat("/etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned", 0x7ffda2f609d0) = -1 ENOENT (No such file or directory)
28139 stat("/etc/sysconfig/64bit_strstr_via_64bit_strstr_sse2_unaligned", 0x7ffda2f609d0) = -1 ENOENT (No such file or directory)
28139 read(4, "", 4096)                 = 0
28139 close(4)                          = 0
28139 munmap(0x7f93d3bf5000, 4096)      = 0
28139 getdents(3, /* 0 entries */, 32768) = 0
28139 close(3)                          = 0
28139 sched_getaffinity(0, 512, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]) = 8
28139 openat(AT_FDCWD, "/sys/devices/system/cpu", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
28139 getdents(3, /* 77 entries */, 32768) = 2368
28139 getdents(3, /* 0 entries */, 32768) = 0
28139 close(3)                          = 0
28139 open("/proc/self/status", O_RDONLY) = 3
28139 fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bf5000
28139 read(3, "Name:\tmysqld-debug\nUmask:\t0022\nS"..., 1024) = 1024
28139 read(3, "0,00000000,00000000,00000000,000"..., 1024) = 334
28139 read(3, "", 1024)                 = 0
28139 close(3)                          = 0
28139 munmap(0x7f93d3bf5000, 4096)      = 0
28139 futex(0x7f93d2d6696c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
28139 futex(0x7f93d2d66978, FUTEX_WAKE_PRIVATE, 2147483647) = 0
28139 stat("/etc/my.cnf", {st_mode=S_IFREG|0644, st_size=370, ...}) = 0
28139 open("/etc/my.cnf", O_RDONLY)     = 3
28139 fstat(3, {st_mode=S_IFREG|0644, st_size=370, ...}) = 0
28139 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93d3bf5000
28139 read(3, "[client]\nsocket=/tmp/mysql.sock\n"..., 4096) = 370
28139 read(3, "", 4096)                 = 0
28139 close(3)                          = 0
28139 munmap(0x7f93d3bf5000, 4096)      = 0
28139 stat("/etc/mysql/my.cnf", 0x7ffda2f5c8d0) = -1 ENOENT (No such file or directory)
28139 stat("/usr/local/mysql/etc/my.cnf", 0x7ffda2f5c8d0) = -1 ENOENT (No such file or directory)
28139 stat("/root/.my.cnf", 0x7ffda2f5c8d0) = -1 ENOENT (No such file or directory)
28139 getrlimit(RLIMIT_NOFILE, {rlim_cur=1073741816, rlim_max=1073741816}) = 0
28139 mmap(NULL, 17179869184, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8fd1f84000
28139 +++ killed by SIGKILL +++



可以看到最后用 mmap 一次分配了 16G 内存,然后就被杀了。

mmap 前调用了 getrlimit , 猜测是 mysql 会根据系统资源限制来分配内存

MySQL源码分析

MySQL 源码中直接调用 getrlimit 的地方不多,排除了 ndb、innodb_memcached、libevent 之后,只有一处直接调用:

static uint set_max_open_files(uint max_file_limit)
{
  struct rlimit rlimit;
  uint old_cur;
  DBUG_ENTER("set_max_open_files");
  DBUG_PRINT("enter",("files: %u", max_file_limit));

  if (!getrlimit(RLIMIT_NOFILE,&rlimit))
  {
    old_cur= (uint) rlimit.rlim_cur;
    DBUG_PRINT("info", ("rlim_cur: %u  rlim_max: %u",
                        (uint) rlimit.rlim_cur,
                        (uint) rlimit.rlim_max));
    if (rlimit.rlim_cur == (rlim_t) RLIM_INFINITY)
      rlimit.rlim_cur = max_file_limit;
    if (rlimit.rlim_cur >= max_file_limit)
      DBUG_RETURN(rlimit.rlim_cur);                /* purecov: inspected */
    rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
    if (setrlimit(RLIMIT_NOFILE, &rlimit))
      max_file_limit= old_cur;                        /* Use original value */
    else
    {
      rlimit.rlim_cur= 0;                        /* Safety if next call fails */
      (void) getrlimit(RLIMIT_NOFILE,&rlimit);
      DBUG_PRINT("info", ("rlim_cur: %u", (uint) rlimit.rlim_cur));
      if (rlimit.rlim_cur)                        /* If call didn't fail */
        max_file_limit= (uint) rlimit.rlim_cur;
    }
  }
  DBUG_PRINT("exit",("max_file_limit: %u", max_file_limit));
  DBUG_RETURN(max_file_limit);



其中逻辑是:如果系统的文件打开限制是 RLIM_INFINITY 或者比要设置的 max_file_limit 大,都返回系统的限制。

这个函数也只被直接调用一次:

uint my_set_max_open_files(uint files)
{
  struct st_my_file_info *tmp;
  DBUG_ENTER("my_set_max_open_files");
  DBUG_PRINT("enter",("files: %u  my_file_limit: %u", files, my_file_limit));

  files+= MY_FILE_MIN;
  files= set_max_open_files(MY_MIN(files, OS_FILE_LIMIT)); // 获取最大打开文件数
  if (files <= MY_NFILE)
    DBUG_RETURN(files);

  // 分配内存
  if (!(tmp= (struct st_my_file_info*) my_malloc(key_memory_my_file_info,
                                                 sizeof(*tmp) * files,
                                                 MYF(MY_WME))))
    DBUG_RETURN(MY_NFILE);

  // 初始化
  /* Copy any initialized files */
  memcpy((char*) tmp, (char*) my_file_info,
         sizeof(*tmp) * MY_MIN(my_file_limit, files));
  memset((tmp + my_file_limit), 0,
        MY_MAX((int) (files - my_file_limit), 0) * sizeof(*tmp));
  my_free_open_file_info();                        /* Free if already allocated */
  my_file_info= tmp;
  my_file_limit= files;
  DBUG_PRINT("exit",("files: %u", files));
  DBUG_RETURN(files);
}



原来 MySQL5 会根据最大可打开文件数,提前为每个文件分配和初始化内存,在这个时候就可能分配过多内存,导致 OOM。MySQL8修复了这个问题。

解决

启动前设置ulimit
ENTRYPOINT ["ulimit -n 1048576 && /home/admin/start.sh"]

写在后面

在linux中,open files设置过大会出现很多问题,应该合理控制open files数量

参考文献

https://learnku.com/articles/34598

作者:京东零售 杨云龙

来源:京东云开发者社区 转载请注明来源

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1100556.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

分享大数据培训班班型

泰迪大数据培训班有VIP就业保障班&#xff0c;项目实战班&#xff0c;技能进阶班&#xff0c;技能提升班。不同班型对应不同学习服务。 一、VIP 就业保障班 二、大数据分析/开发项目实战班 三、技能进阶班 四、技能提升班

RabbitMQ 安装和使用Demo

同步是阻塞 MQ&#xff1a;消息队列&#xff0c;基础数据结构中"先进先出"的数据结构。用来解决应用解耦&#xff0c;异步消息&#xff0c;流量消峰等问题。 RabbitMQ、RocketMQ、Kafka RocketMQ 是阿里的 应用层开发使用RabbitMQ 大数据开发Kafka MQ是不是微服务都…

【MATLAB源码-第49期】基于蚁群算法(ACO)算法的栅格路径规划,输出最佳路径图和算法收敛曲线图。

操作环境&#xff1a; MATLAB 2022a 1、算法描述 蚁群算法是一种模拟自然界蚂蚁觅食行为的启发式优化算法。在蚁群系统中&#xff0c;通过模拟蚂蚁之间通过信息素沟通的方式来寻找最短路径。 在栅格路径规划中&#xff0c;蚁群算法的基本步骤如下&#xff1a; 1. 初始化: …

【Redis】Redis持久化策略

目录 策略RDBbgsave执行流程RDB效果演示RDB优缺点 AOFAOF缓冲区刷新策略AOF的重写机制AOF重写机制的触发机制AOF重写流程 混合持久化同时存在aof和rdb快照&#xff0c;以谁为主&#xff1f;信号 策略 RDB > Redis DataBase 相当于定期的方式实现持久化AOF > Append Only…

Python网络编程改良版客户端

在《Python中套接字实现客户端和服务端3-3》中提到&#xff0c;客户端可以通过connect()方法连接服务端&#xff0c;而连接成功的前提是服务端在必须客户端连接之前就要等待连接。 1 当客户端连接时&#xff0c;服务端没有打开 如果客户端连接服务端时&#xff0c;服务端并没…

通过商品ID查询淘宝商品详情数据,可以拿到商品标题,商品价格,商品库存,商品销量,商品sku数据等,淘宝API接口

通过商品ID查询淘宝商品详情数据可以参考以下步骤&#xff1a; 进入淘宝网站&#xff0c;搜索需要查询的商品ID&#xff0c;例如&#xff1a;652874751412。复制该商品的ID号。点击获取请求key和secret地址&#xff0c;请求参数为num_iid商品ID&is_promotion1。发送请求&a…

企业立案信息API的优势与应用场景

引言 随着科技的不断进步&#xff0c;创业者和企业家们在创办新企业时愈发依赖数字化工具。其中&#xff0c;企业立案信息API成为了一项重要的资源&#xff0c;它提供了有关企业立案的关键信息&#xff0c;为企业家们提供了许多优势和丰富的应用场景。本文将探讨企业立案信息A…

【API篇】四、物理分区算子API

文章目录 1、 分区算子&#xff1a;随机分区2、分区算子&#xff1a;轮询分区3、分区算子&#xff1a;重缩放分区4、分区算子&#xff1a;广播5、分区算子&#xff1a;全局分区6、自定义分区 重分区&#xff0c;即数据"洗牌"&#xff0c;将数据分配到下游算子的并行子…

【日志与守护进程】

文章目录 1 :peach:日志:peach:1.1 :apple:对日志的基本理解:apple:1.2 :apple:对日志系统代码的基本编写:apple:1.2.1 :lemon:messageLog.hpp:lemon:1.2.2 :lemon:tcpServer:lemon: 1.3 :lemon:验证:lemon: 2 :peach:守护进程:peach:2.1 :apple:进程组与会话:apple:2.2 :apple…

Rabbitmq 的管理配置

1、Rabbitmq管理 1.1、多租户与权限 每一个RabbitMQ 服务器都能创建虚拟的消息服务器&#xff0c;我们称之为虚拟主机(virtual host) ,简称为vhost 。每一个vhost 本质上是一个独立的小型RabbitMQ 服务器&#xff0c;拥有自己独立的队列、交换器及绑定关系等&#xff0c;井且它…

用PHP爬取视频代码示例详细教程

以下是一个使用Symfony Panther和PHP进行爬虫的示例程序&#xff0c;用于爬虫企鹅上的视频。请注意&#xff0c;这个示例需要使用https://www.duoip.cn/get_proxy这段代码获取爬虫IP。 <?php // 引入所需的库 require vendor/autoload.php;use Symfony\Component\Panther\P…

多媒体应用设计师 第7章 多媒体数字压缩编码技术基础

1.多媒体数据压缩技术理论基础及压缩编码方法分类 必要性:大数据量的图像信息会给存储器的存储容量&#xff0c;通信线路的带宽&#xff0c;以及计算机的处理速度增加极大压力。如果没有多媒体编码压缩技术的发展&#xff0c;大容量图像&#xff0c;视频信息的存储和传输就难以…

林旅强 | AI+开源时代 - 开发者与治理者的机遇与挑战

点击以下链接收听本期 “大咖访谈” 播客&#xff0c;与大咖面对面&#xff1a; 大咖访谈链接&#xff1a;EP15&#xff1a;林旅强 | AI开源时代 - 开发者与治理者的机遇与挑战 刘天栋&#xff1a;访谈主持&#xff0c;开源雨林顾问&#xff0c;开源社联合创始人&#xff0c;Ap…

人工智能应该怎么学?

人工智能这个词炙手可热&#xff0c;为了跟上时代的步伐&#xff0c;有许多小伙伴就想学习人工智能&#xff0c;今天来介绍一下人工智能究竟是什么&#xff1f;应该怎么学&#xff1f;怎么入门&#xff1f; 首先来看一下什么是人工智能&#xff1f; 人工智能 人工智能 人工智能…

puppeteer学习笔记

目录 介绍启动方法功能一、爬虫优势如何实现爬虫小demo 功能二、执行脚本百度搜索脚本demo 功能三、获取cookie&#xff08;这个只能是模拟浏览器当前进入网页的cookie不是平时用的下载的的浏览器的cookie&#xff09;功能四、监控网页&#xff0c;进行性能分析 介绍 puppetee…

文旅部发布《旅游电子合同管理与服务规范》,推动旅游企业转型升级

日前&#xff0c;文化和旅游部批准发布了旅游电子合同领域的行业标准《旅游电子合同管理与服务规范》&#xff08;以下简称《标准》&#xff09;&#xff0c;将于2023年12月9日起实施。 《标准》聚焦旅游电子合同的适用范围、基本要素、操作规范、载体要求、安全保密等方面进…

【编译原理】对++*p++操作理解

目录 1. 代码段执行结果 2. *p的结合过程 3. 通过汇编代码判断执行结果 1. 代码段执行结果 对于以下代码&#xff1a; int main() { int i 0;int *p &i; *p ; return i; }输出结果为&#xff1a; ASM generation compiler returned: 0 Execution build compiler re…

隐写术--python隐写

0x00 背景 何为隐写术&#xff1f; 隐写术是一类可以隐藏自己写的一些东西的方法&#xff0c;是一门关于信息隐藏的技巧与科学。指的是采取一些不让除预期的接收者之外的任何人知晓信息的传递事件或者信息的内容的方法。 可参考 一文让你完全弄懂Stegosaurus - 知乎 本文要…