简体   繁体   English

Tomcat离开time_wait连接

[英]tomcat leaves time_wait connection

we are using an Apache Sever as a front server an a Tomcat server for the backend. 我们将Apache Sever用作前端服务器,将Tomcat服务器用作后端。 The frontend client is a java swing application. 前端客户端是一个Java swing应用程序。 The protocol is hessian. 该协议是粗麻布的。

Sometimes we got a lot of small requests. 有时我们有很多小的要求。 When doing a "nestat -a" there are a lot of TIME_WAIT connections, which are blocking the server to open new connections. 当执行“ nestat -a”时,有许多TIME_WAIT连接,这些连接阻止服务器打开新连接。 Only the connections to the tomcat seem to stay. 只有与tomcat的连接似乎保持不变。 The connections to the apache seem to be closed. 与apache的连接似乎已关闭。

We are using a rewrite rule to forward the requests to the tomcat 我们正在使用重写规则将请求转发到tomcat

RewriteEngine On
RewriteCond %{REQUEST_URI} .*\.servlet.*$
RewriteRule ^/(.*)$ http://localhost:8080/$1 [P]

Any ideas? 有任何想法吗?

UPDATE: 更新:

Thanks for your advice , 感谢您的建议

but it still doesn't work. 但它仍然不起作用。 Every stream is closed and there are still these TIME_WAIT's: 每个流都关闭,并且仍然有这些TIME_WAIT:

if (conn != null) {
    try {
        IOUtils.closeQuietly(conn.getInputStream());
    } catch (IOException e) {
        // do nothing
    }
    try {
        IOUtils.closeQuietly(conn.getOutputStream());
    } catch (Exception ex) {
        // do nothing
    }
    try {
        IOUtils.closeQuietly(((HttpURLConnection) conn).getErrorStream());
    } catch (Exception ex) {
        // do nothing
    }
}

if (conn instanceof HttpURLConnection) {
    ((HttpURLConnection) conn).disconnect();
}

Most likely you don't close the Input/Output Stream in the Swing application when making the request. 发出请求时,很可能您没有在Swing应用程序中关闭输入/输出流。 From here : 这里

If the result is an InputStream, it is very important that the InputStream.close() be put in an finally block, because Hessian will not close the underlying HTTP stream until all the data is read and the input stream is closed. 如果结果是InputStream,则将InputStream.close()放在finally块中非常重要,因为在读取所有数据并且关闭输入流之前,Hessian不会关闭基础HTTP流。

TIME_WAIT is a normal state of a recently closed connection, it will remain in it for a kernel-defined timeout. TIME_WAIT是最近关闭的连接的正常状态,它将在其中保留一段内核定义的超时时间。 You did everything you can from the application's side. 您已从应用程序方面尽了一切可能。

If you have connections flicker too fast and experience a shortage of available ports, you could tweak your system's recycling of them. 如果您的连接闪烁太快并且遇到可用端口不足的情况,则可以调整系统对它们的回收利用。 Huge amount of TIME_WAIT connections gives an overview for Linux as well as basic theory, Tuning Windows for TCP/IP performance lists corresponding Windows parameters with much breifer explanation. 大量的TIME_WAIT连接提供了Linux以及基本理论的概述, 针对TCP / IP性能调整Windows列出了与Windows有关的参数,其中有很多breifer解释。

It's not Tomcat, it's your operating system. 不是Tomcat,而是您的操作系统。

The OS is leaving connection in TIME_WAIT in order to avoid interference caused by too quick port reuse. 操作系统将在TIME_WAIT中保留连接,以避免因端口重用太快而造成干扰。 Imagine packets from the old connection arriving late while a new connection is open in the same port. 想象一下,旧连接的数据包到达时晚了,而新连接在同一端口中打开了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM