本文介绍了Node.js SSL服务器冻结,高CPU,没有崩溃但没有连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以帮我解决这个问题。

I hope anyone could help me with this issue.

在我们公司,我们正在建立一个连接到Java Push服务器的nod​​e.js服务器。

In our company we are setting up a node.js server, connected to a Java Push server.

我正在使用https模块而不是http和SLL证书。

I'm using https module instead of http and SLL certificates.

节点和客户端之间的连接是由socket.io,在服务器和客户端。

The connection between node and clients is made by socket.io, in server and client.

同时node.js服务器是java服务器的客户端,这个连接使用常规套接字(网络) .connect)。

At the same time the node.js server is client of the java server, this connection is being made with regular sockets (net.connect).

这个想法是用户连接到服务器,加入一些频道,当一些数据从java服务器到达时,会将其发送给相应的用户。

The idea is that users connect to the server, join some channels, and when some data arrive from java server, this is dispatched to the corresponding users.

一切似乎都运行正常,但过了一段时间,就像随机一样,有450到700个用户,服务器的CPU达到100%,所有连接都坏了,但服务器是没有坠毁。问题是,如果你去浏览器中的https:// ...,你没有得到404或类似的东西,但SSL连接错误,它真的很快。

Everything seems to work fine, but after a while, like randomly, having like between 450 and 700 users, the server's CPU reaches 100%, all the connections are broken, but the server is not crashed. The thing is that if you go to the https://... in the browser, you are not getting 404 or something like that but SSL connection error, and its really fast.

我试图在任何地方添加日志,但是没有类似模式的东西,它就像是随机的。

I tried to add logs everywhere, but there's not something like a pattern, its like random.

如果有人有同样的问题或者可以给我一个线索或者提示调试更好,我会很感激。

If anybody have the same problem or could bring me a clue, or a tip to debug better, I'll appreciate anything.

非常感谢。

推荐答案

好的,问题解决了。这是每个Linux服务器都会出现的问题。因此,如果您正在使用其中一个,则需要阅读此内容。

Okay, the problem is solved. It is a problem that will occur in every Linux server. So, if you are working with one of these, you need to read this.

原因是Linux服务器每个进程的文件的默认限制。

The reason was the default limit of files the Linux server had per each process.

似乎单个linux服务器附带了每个进程打开的1024个文件的限制,您可以通过以下方式检查您的限制:

Seems that ever single linux server comes with this limitation of 1024 files opened by each process, you can check your limit with:

# ulimit -n

增加此数量

# ulimit -n 5000 (for example)

每个套接字都会创建一个新的虚拟文件。

Each socket creates a new virtual file.

由于某些原因,我的服务器没有显示任何错误,服务器刚被冻结,停止日志,没有信号或任何证据。当我在另一台机器上设置服务器的副本时,它开始发送

For some reason my server was not displaying any error, the server just got frozen, stopping the log and no signal or evidence of anything. It was when I set up a copy of the server in another machine, when it started to send

warn: error raised: Error: accept EMFILE
warn: error raised: Error: accept EMFILE
warn: error raised: Error: accept EMFILE
...

小心,因为如果你不是root用户,你只会在当前会话中更改此权限,而不是永久更改。

Be careful because if you are not root, you will only change this for the current session and not permanently.

技巧:如果你想要计算文件的数量,在这种情况下,你的节点进程打开的文件数,记下你的进程ID并调用这个命令。

Trick: If you want to cound the number of files, in this case, the number of files opened by your node process, take note of your process id and call this command.

# ls -l /proc/XXXXX/fd | wc -l

其中XXXXX是进程ID。这将帮助您了解这是否是您的问题,一旦启动节点服务器,您可以使用此命令检查它是否到达顶部,并在冻结后停止增长。 (默认为1024或ulimit -n)。

Where XXXXX is the process id. This will help you to know if this is your problem, once you launch your node server, you can use this command to check if it reaches a top, and it stops growing after it gets frozen. (by default 1024 or "ulimit -n").

如果您只想检查过程中哪些文件是打开的:

If you only want to check which files are open by the process:

# ls -l /proc/XXXXX/fd

希望这可以帮到你。如果你正在设置一个节点js服务器,我很确定你想要这样做以确保它不会融化。

Hope this can help you. Any way if you are setting up a node js server I'm pretty sure you want to do that to be sure it won't melt.

最后如果你需要帮助在将来没有日志的错误中,您可以尝试 strace ing或 dtruss ing过程

Finally if you need help in future errors without log, you can try to straceing or dtrussing process

# strace -p <process-id> 

应该可以胜任。

这篇关于Node.js SSL服务器冻结,高CPU,没有崩溃但没有连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:32