apolloconfig / apollo.net

Apollo .Net Client
Apache License 2.0
481 stars 167 forks source link

导致应用程序与配置中心产生了大量的TCP连接 #143

Open alvin-su opened 3 years ago

alvin-su commented 3 years ago

导致应用程序与配置中心产生了大量的TCP连接,很多TCP连接是 timewait 状态,导致应用程序响应缓慢。如何重用tcp连接?如使用连接池?

pengweiqhca commented 3 years ago

是这个问题

alvin-su commented 3 years ago

image

alvin-su commented 3 years ago

有大量 tcp 连接 在 TimeWait ,如上图

alvin-su commented 3 years ago

只有一个 namespace

pengweiqhca commented 3 years ago

确定是apollo客户端的连接么?

alvin-su commented 3 years ago

确定是的,那个截图中的 RemoteAddress 就是配置中心的地址

pengweiqhca commented 3 years ago

启动时会使用多个连接获取配置(和namespace多少相关),后续只会保留一两个长连接。通过你的截图中已有的连接数量TimeWait数量算正常,但应该启动稳定之后TimeWait数量就会下降

alvin-su commented 3 years ago

这个是 应用程序 运行一段时间,微软Azure 后台监控到的,运行一段时间后造成大量的TCP连接在 timewait ,必须重启应用解决

pengweiqhca commented 3 years ago

客户端默认使用系统默认的配置,不会关闭连接 HttpUtil.cs#L35

alvin-su commented 3 years ago

我们昨晚 从生产系统 去掉了 与配置中心的连接,改为本地配置文件,今天Azure 后台监控 已经没有大量tcp连接了,那请问这个如何解决呢?

alvin-su commented 3 years ago

我们用的是 .net core 2.2 感觉是 HttpClient 的问题

pengweiqhca commented 3 years ago

2000多个连接正常吗?你们有1000多个应用?

nobodyiam commented 3 years ago

timewait 多应该没啥关系吧,过一段时间会关掉的,不过看截图 established 的数量很大,和这个关系更大吧,比如一直在建立新连接,关掉老连接这样。

@alvin-su 目前观测到的现象是啥?比如看看是一启动就几千个连接还是缓慢增长?

alvin-su commented 3 years ago

@nobodyiam 是的,应用程序 启动后,一直在增长,增长到 微软Azure WebApp 限制的 TCP 连接数 8096 后,就导致大量响应超时和缓慢,web 应用程序打不开

alvin-su commented 3 years ago

@pengweiqhca 2000多个连接不正常呀,这个是 apollo客户端 产生的TCP连接数,就一个web 应用

alvin-su commented 3 years ago

@pengweiqhca 微软的工程师和 Azure 世纪互联 工程师,帮忙定位到的问题,我们去掉 携程apollo 客户端后,TCP连接一切就正常了,稳定运行了几天了

alvin-su commented 3 years ago

image

pengweiqhca commented 3 years ago

建议输出一下apollo.net内部日志,看看是不是连接被断开或者超时很段之类的

nobodyiam commented 3 years ago

另外也可以在 apollo 服务器上抓下网络包看看客户端和服务端的交互情况