侧边栏壁纸
  • 累计撰写 25 篇文章
  • 累计创建 26 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

小内存机器接收大量数据导致应用被OOM

Yttrium
2024-08-30 / 0 评论 / 0 点赞 / 32 阅读 / 3434 字

小内存机器接收大量数据导致应用被OOM

Application on low memory machine has been OOM-ed by recieving amount of traffic data

如果在低内存的机器, 如 256MB, 512MB大小的内存上使用接收大量网络数据但消费较慢的软件, 如代理软件. 代理软件到源的速度通常较快, 但到客户的速度较慢, 这会让大量数据挤压在代理服务器上来不及消费而导致TCP连接占用大量内存, 系统发现内存不够用的时候大概率会杀死正在使用的软件).

If you are using a low memory machine, such as 256MB, 512MB, and running a fast recieve but slower consume software. e.g. : a proxy server. A proxy server usually has great traffic speed to source but much lower speed to user, thus makes a lot of data stay in server and squashing other softwares. When this happened, system will choose an application to kill, it most probablly your proxy software.

解决这个问题的方式就是调整连接的缓冲池大小, 应用软件中的缓冲池可查看相应的文档进行配置, 这里主要调整内核的缓冲池大小.

By adjusting the buffer pool size can solve this problem, reading the docs to configure application buffer size, we change the kernel buffer size mainly.

可以使用 sysctl net.ipv4.tcp_mem 查看系统相应的配置, 单位为字节.

Use sysctl net.ipv4.tcp_mem to check corresponding configurations, unit is Byte.

下面是可供调整的配置:

Some configurations below that we may need to change.

  • net.ipv4.tcp_mem = 6177504 8236672 16777216 # 三个值是low, pressure, high, 具体含义可以搜索, 这里主要调整high

  • net.ipv4.tcp_rmem = 4096 873800 16777216 # 三个值是 min, default, max 主要调整max

  • net.ipv4.tcp_wmem = 4096 873800 16777216 # 三个值是 min, default, max 主要调整max

将配置写入/etc/sysctl.conf文件, 然后执行sysctl -p生效.

Write into /etc/sysctl.conf file ,then execute sysctl -p to make effect.

根据系统的剩余内存进行最大值的调整, 并测试, 可以解决应用被OOM的问题. 注意: 如果缓冲区过小, 将会影响网络速度, 所以应根据实际剩余内存的大小进行测试调整.

According to available memory to change the high value, and test it, and your OOM problem will be solved. Attention: You should according to actual avaiable memory to tune the configurations, use smaller buffer size will cause slow connection speed.

0

评论区