swoole-src
swoole-src copied to clipboard
Safely server reload
Server reload function does not work as needed, I can not update workers from new sources in Symfony app using k911/swoole-bundle. Sometimes it works in controllers, sometimes not. And never works in other services. I use full server restart, but it can to interrupt current worker processes. Is it possible to send every worker stop signal, if worker handles request wait it, else restart it fully with new source code and start handling new requests while other workers finishing current requests?
Hi, you can set max_wait_time and reload_async to reload or stop worker softly.
Hi, you can set max_wait_time and reload_async to reload or stop worker softly.
With max_wait_time server waits requests when reloading, but it does not accept new requests, so they need to wait too. And reloading is not works as needed, it does not load all project files. When shutdown occurs it waits 5-10 seconds, and setting more max_wait_time not helps. But it is not needed if new clients will be waiting such a lot time.
It would be great, if server, when restarting, could wait while current requests will be finished, and at the same time accept new requests. But in now solution is to move any long processes someway to background or doing deploy rarely at the certain time.
I think it is hard to achieve it. This is an endless loop.
I see another way to implement zero downtime deploy using nginx, like this https://syshero.org/2016-06-09-zero-downtime-deployments-using-nginx/
Steps:
- Deploy second instance of application with another port opened and optionally warmup it.
- Switch nginx proxy to the second instance, so new requests are going to it.
- Wait for finishing requests of the first instance using max_wait_time and shutdown it (kill -15 master_pid)
It would be great, if server, when restarting, could wait while current requests will be finished, and at the same time accept new requests. But in now solution is to move any long processes someway to background or doing deploy rarely at the certain time.
It may seem logical at the application level. But for the database layer, you must shut down the system. The new application may fail before the database migrations are complete.