一天后,Spring Boot应用程序将冻结 [英] Spring Boot application freezes after a day

查看:124
本文介绍了一天后,Spring Boot应用程序将冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在两台服务器上运行的Spring Boot应用程序.它通过Controller接收来自数千个IOT设备的文件上传请求(约1 KB).

I have a Spring Boot application running on two servers. It accepts file upload requests (approx 1 KB) via Controller from 1000s of IOT devices.

此外,还有一个 TCP侦听器,它也从这些IOT设备接收GPS数据作为流.

Additionally there is a TCP Listener which also accepts GPS data as a Stream from these IOT devices.

我已在一台服务器上将Tomcat最大线程数设置为3000,在较大的VM上将其设置为5000.

I have setup the Tomcat max thread count to 3000 on one server and 5000 on a larger VM.

一两天后,我的Spring Boot应用程序冻结,即它停止响应任何其他API调用.

After a day or two my Spring Boot application freezes, i.e. it stops responding to any further API calls.

我怀疑原因之一是,IOT设备在发送数据后未关闭 TCP套接字连接.

One reason, I suspect is that the IOT devices are not closing the TCP socket connection after sending the data.

我哪里出问题了?我的线程用完了,无法处理新的传入请求?

Where could I be going wrong? I am running out of threads to handle new incoming requests?

###########################

在研究套接字连接和关闭期间的线程转储并添加了日志之后,我发现IOT设备没有关闭连接.取而代之的是,设备每次要发送新数据时都在不关闭前一个连接的情况下创建一个新连接.

After investigating the thread dump and adding logs during during Socket connection and closure, I have discovered that the IOT device isn't closing connections. Instead the device is creating a new connection every time it wants to send new data without closing the previous one.

在应用冻结之前,会自动关闭22500个打开的连接.

Before the app froze, 22500 open connections were automatically closed.

如何处理此行为?超时后是否应该强行关闭连接?

How can I handle this behavior? Should I close the connections forcefully after a certain timeout?

推荐答案

您可以通过将服务隐藏在Nginx或HAProxy的后面来缓解空闲连接问题,该Nginx或HAProxy在给定的超时后默认关闭空闲连接.

You can mitigate the idle connections problem by hiding your service behind an Nginx or HAProxy which close idle connections by default after a given timeout.

另一个选择是在应用程序属性中设置server.connection-timeout(请参见服务器属性),但这似乎仅适用于HTTP.

Another option is to set server.connection-timeout in application properties (see server properties), but this appears to be applicable to HTTP only.

这篇关于一天后,Spring Boot应用程序将冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆