Shutdown VERY busy node production

I have a very, very busy node application on a production server. The application deals with real-time chat (using web maps), as well as e-commerce payment. While everything is set up so that when the server goes down, the clients will reconnect their sockets, etc., I still have a problem: whenever the server stops, using SIGINT the event loop is disconnected. This means that any pending DB record (possibly for a financial transaction) is simply discarded. There are two especially important points (when a credit card dealer gives OK, but before we write a report on db), and at the moment we close it after hours to prevent any possible problems. But this is bad.

I think of it as a solution:

  • I am sending a custom UNIX signal to a process (for example, SIGUSR2?);
  • When server.js receives a signal:
    • He stops listening to port 80
    • The event loop is expected to dry.
    • If after 10 seconds it still hangs, it forces a shutdown. This means that with each reboot the server will work for no more than 10 seconds.

Is that what people do in the real world? Any booty? How to check that the event loop is empty?

+5
source share
1 answer

Hope this raises your question, but at least hope it helps (and it takes too long for comment).

This is the goal for which load balancing is most important, you can control how much traffic a particular server receives until you need to close the server, you can safely say that it is not used anymore. Since you have websites open directly with the server, it is very likely that these connections will be stored directly on this server and cannot be proxied through the load balancer (not sure about this), but not creating new connections will eventually make these compounds eventually die off.

As an alternative, consider the option of balancing the load for the poor person and configure a proxy server on this server, which will hit other servers. If all your state is saved through a common database, no operations will be violated, and you can give enough time (whatever that is) for the event loop.

Regarding the use of the server, if you don’t have a way to tell what is happening with the event loop, all the application logs that you have on the server can help determine what your application is doing, and just fine the court will tell you how safe it is to close him at a certain point. (Again, the more you can reduce the use on it before that, the better.)

Finally, as Archimeding suggested, using process.on() to handle graceful completion is pretty much the standard across all platforms. (It makes me remember a lot of Java-based servers that take some time to close.) Depending on the severity of the effects of the application endlessly, you might want the process to hang a little longer or even perform shutdown procedures, but you have to consider that this not always possible.

Finally, try to avoid dependency on any particular server. Controlled shutdowns are easy to handle, but outages and hardware failures will not allow you to wait for a cycle of events.

+1
source

Source: https://habr.com/ru/post/1264814/


All Articles