8

我在生产中使用 playframework 2.0,我看到相应的 java 进程打开的文件数量迅速增加。我将进程的默认允许打开文件数从 1024 更改为 4096,但这只是延迟了一个问题,一段时间后打开文件的数量变得如此之大,以至于服务器速度变慢,有时甚至java.net.SocketException“打开的文件太多” "出现在日志中。

我使用 ubuntu 服务器 12.04,sun jdk 1.7.0_09。

lsof命令演示了几乎所有打开的文件都是为用户连接创建的套接字,因此我得出一个结论,playframework 使用的 Netty 服务器保持大量打开的连接处于活动状态。据我了解,我应该更改 Netty 服务器的保活行为,例如,设置低保活超时。如何在 playframework 2.0 中配置它?或者可能是其他问题?如果需要,我可以提供任何配置。

UPD:这里有一点输出lsof -aPn -p 12251。我审查了 ips 的某些部分***

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF   NODE NAME
java    12251 root  324u  IPv6             279502      0t0    TCP 10.127.0.***:80->***.***.65.137:51506 (ESTABLISHED)
java    12251 root  325u  IPv6             286749      0t0    TCP 10.127.0.***:80->***.***.18.121:1624 (ESTABLISHED)
java    12251 root  327u  IPv6             287220      0t0    TCP 10.127.0.***:80->***.***.126.210:49244 (ESTABLISHED)
java    12251 root  330u  IPv6             279289      0t0    TCP 10.127.0.***:80->***.***.65.155:12444 (ESTABLISHED)
java    12251 root  331u  IPv6             285609      0t0    TCP 10.127.0.***:80->***.***.33.233:2552 (ESTABLISHED)
java    12251 root  332u  IPv6             285610      0t0    TCP 10.127.0.***:80->***.***.33.233:2554 (ESTABLISHED)
java    12251 root  333u  IPv6             287236      0t0    TCP 10.127.0.***:80->***.***.90.20:16040 (ESTABLISHED)
java    12251 root  334u  IPv6             284047      0t0    TCP 10.127.0.***:80->***.***.195.2:1175 (ESTABLISHED)
java    12251 root  335u  IPv6             279357      0t0    TCP 10.127.0.***:80->***.***.65.137:51273 (ESTABLISHED)
java    12251 root  336u  IPv6             279988      0t0    TCP 10.127.0.***:80->***.***.65.137:51287 (ESTABLISHED)
4

1 回答 1

2

If you're using Play without any HTTP server you can manipulate the response headers before sending the Result (Scala version) , otherwise you need to check settings of the front-end server.

response().setHeader(CONNECTION, "Keep-Alive");
response().setHeader("Keep-Alive", "timeout=3, max=10");
return ok(index.render());

Note, that these values are sample and I don't know if they will fit your needs.

于 2012-11-15T15:31:05.000 回答