S
S
snake-yava2016-06-27 08:12:38
Node.js
snake-yava, 2016-06-27 08:12:38

How to make the server on node.js not freeze?

After a long period of non-use, the node.js server hangs. When you click on the link, it just takes a long time to load in the browser, but nothing happens.
How to catch what's the problem. There is an assumption that the database closes the connection after a long time of not using it. The database connection is created only once, when the server is initialized. Perhaps this is the problem.
Maybe increase some wait_time in postgres settings?
Node uses ORM: https://www.npmjs.com/package/orm

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Shemsedinov, 2016-06-27
@snake-yava

Well, there may be different reasons:
1. Check if memory is leaking, because processes often hang without any messages from leaks
2. Replace the cluster library with child_process, cluster has big reliability problems, hangs
3. Switch to normal firewood to postgres: https://www.npmjs.com/package/pg
4. Use connection pooling https://www.npmjs.com/package/pg#client-pooling
memory, if the base is not large
6. Do not use the middleware principle and frameworks based on it such as connect, express, koa
7. Analyze the code on the callback chain, it may turn out that there is no return in some branches

Y
Yustas Alexu, 2016-06-27
@Yuxus

There is an assumption that the database closes the connection after a long time of not using it.

You don't need to assume anything, but you need to debug. Just look at the logs.
If the problem is precisely in closing the connection, then everything is simple: at the time of the request, we determine that the connection is closed, or if it cannot be determined, then we can simply catch the error and create a new connection).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question