alibaba / tengine

A distribution of Nginx with some advanced features
https://tengine.taobao.org
BSD 2-Clause "Simplified" License
12.75k stars 2.52k forks source link

tengine实现tcp proxy,内存持续增长问题! #1444

Open yangtaoThirdBoy opened 4 years ago

yangtaoThirdBoy commented 4 years ago

试图使用tengine实现TCP Proxy, 在工作过程中client与server之间必须通过proxy维持tcp长连接

error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;

worker_rlimit_nofile 65535;

error_log /dev/stdout error;

events { use epoll; worker_connections 65535; multi_accept on; }

stream { tcp_nodelay on; upstream backend_chash { server 10.0.3.220:30022;

keepalive 1024;

    }

    server {
            listen 80 so_keepalive=on;
            proxy_socket_keepalive on;  #和so_keepalive配合使用

            access_log off;

            proxy_pass      backend_chash;
    }

}


- 测试过程记录如下
![image](https://user-images.githubusercontent.com/18020588/77874614-072d2180-7280-11ea-8bf0-24a4a32336c4.png)
![image](https://user-images.githubusercontent.com/18020588/77876315-2a0e0480-7285-11ea-89ca-bb332c310284.png)
- 如此反复断开tcp连接、新建tcp连接流程,内存会持续性增长
mrpre commented 4 years ago

使用你的配置文件,没有发现内存泄漏。 1、确定连接全部断开后再统计你的内存。 2、统计内存,请使用 ps -aux | grep nginx 看 tengine worker的内存占用是否持续增长即可。

yangtaoThirdBoy commented 4 years ago

实际的业务场景会有部分tcp连接重连的情景(上下线),所以模拟测试的过程,有一半的tcp连接一直保持连接,另外一半不断重连。 如果全部tcp连接断开之后,内存确实释放了

yangtaoThirdBoy commented 4 years ago

内存统计信息还看了nginx work进程的详细信息(/proc/nginx_work_pid/status);和free -m 查看到的内存使用情况基本一致