> Hi,
>
> I am looking for a way to reload active (but idle) PSGI workers
> periodically
> (to keep everything fresh), but so far I found no reliable way to do so.
>
> What I need, basically, is a hook that will be called once worker
> is inactive (no activity within N seconds).
>
> Unfortunately, --idle doesn't work this way (and has a problem: #776),
> timers are plagued by #58 so could not be used in any of cheaper modes.
>
> Of course, I could monitor workers outside - using stats server, for
> instance,
> then send SIGHUP to inactive ones, but this does not look clean enough
> to me,
> especially because a worker may get (or start processing) request
> exactly when I send SIGHUP.
>
> Any ideas and suggestions are very welcome :)
>
> Thank you!
>
> --
> Best regards,
> Alexander.
>
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>

I do not have a "final" solution, as the whole "atexit" concept is a real
mess to correctly manage (just look at the python plugin where we needed
4-5 workarounds to avoid segfaults ;) Currently (thanks to Ævar Arnfjörð
Bjarmason) in 2.0.9 we have a "gentle" atexit management in the perl
plugin, but it is useless in your case as you need to manage
"cheaping/dying" workers.

Some notes that could give you some workaround/solution:

if a worker exit with:

#define UWSGI_GO_CHEAP_CODE 15

(so exit(15))

the master will treat it as a voluntary cheap request, and the process
will be no more spawned after its death.

So, the first step is having an handler that calls your cleanup functions
and exit with the 15 code (easy to do in perl).

But if understand correctly you do not want processes to remain down, you
want them to suddenly reload.

Now the true problem: when to kill

timers do not work reliably as #58 (but the fallback proposed solution
will work for you)

monitoring the stats server is always the good last-resort solution, but
it is prone to race conditions, and you cannot live with them in your
scenario.

Now, cheaper mode (without idle) will be way better for you (it gracefully
stops processes), but it is based on load algorithms, you should develop
one based on inactivity. Cheaper algorithms are pluggables, so developing
one for your needs should be a viable solution. But again, you want
processes to gracefully reload, not die.

Now adding a function to call at every master cycle will be something to
think of, as you effectively do not want to bring down workers, but to
simply reload them. The master_cycle hook will work for you:

#include <uwsgi.h>

static void check_processes_to_reload() {
    // iterate each process and send SIGHUP
    // to those you want to reload
}

struct uwsgi_plugin autoreloader_plugin = {
        .name = "autoreloader",
        .master_cycle = check_processes_to_reload,
};


save it as autoreloader.c and build it with

uwsgi --build-plugin autoreloader.c

you will end with autoreloader_plugin.so that you can load with --plugin
(and check_processes_to_reload() will be executed at every master cycle
automatically)

-- 
Roberto De Ioris
http://unbit.it
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to