unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.46k stars 691 forks source link

spooler-max-tasks not respawning spooler in uwsgi 1.3 #32

Closed xrmx closed 11 years ago

xrmx commented 12 years ago

with uwsgi 1.3 it looks like spooler-max-tasks most of the times does not work as advertised:

[spooler /foo/spooler pid: 4185] done with task uwsgi_spoolfile_on_foo_29150_3_0_1350930600_53133 after 120 seconds [spooler /foo/spooler pid: 4185] managing request uwsgi_spoolfile_on_foo_29150_3_0_1350930600_53912 ...

I've seen one time it respawning fine against ten not respawning.

This is the relevant conf:

`

%d/spooler 1

`

unbit commented 11 years ago

i have exported spoolers data in the stats server, can you check (during work) if you note something "unexpected" ?

xrmx commented 11 years ago

I've added some debug prints to my running 1.3. After a uwsgi reload the spooler check is done once and then after the restart it is not done anymore.

[spooler] written 118 bytes to file /spooler/uwsgi_spoolfile_on_02_21637_7_0_1351852124_145796
max_tasks: 1 tasks: 0
[spooler /spooler pid: 21635] managing request uwsgi_spoolfile_on_02_21637_7_0_1351852124_145796 ...
[spooler] written 118 bytes to file /spooler/uwsgi_spoolfile_on_02_21637_7_0_1351852124_149005
[spooler] written 118 bytes to file /spooler/uwsgi_spoolfile_on_02_21637_7_0_1351852124_152407
[spooler] written 118 bytes to file /spooler/uwsgi_spoolfile_on_02_21637_7_0_1351852124_155676
spooling something!
spooler ret was -2
incrementing uspool tasks, was 0  is 1
[spooler /spooler pid: 21635] done with task uwsgi_spoolfile_on_02_21637_7_0_1351852124_145796 after 24 seconds
max_tasks: 1 tasks: 1
[spooler /spooler pid: 21635] maximum number of tasks reached (1) recycling ...
OOOPS the spooler is no more...trying respawn...
spawned the uWSGI spooler on dir /spooler with pid 22265
[spooler /spooler pid: 22265] managing request uwsgi_spoolfile_on_02_21637_7_0_1351852124_149005 ...
spooling something!
spooler ret was -2
incrementing uspool tasks, was 0  is 1
[spooler /spooler pid: 22265] done with task uwsgi_spoolfile_on_02_21637_7_0_1351852124_149005 after 21 seconds
[spooler /spooler pid: 22265] managing request uwsgi_spoolfile_on_02_21637_7_0_1351852124_152407 ...
spooling something!
spooler ret was -2
incrementing uspool tasks, was 1  is 2
[spooler /spooler pid: 22265] done with task uwsgi_spoolfile_on_02_21637_7_0_1351852124_152407 after 10 seconds
[spooler /spooler pid: 22265] managing request uwsgi_spoolfile_on_02_21637_7_0_1351852124_155676 ...

The first hunk of the patch is inside spooler for(;;) loop the other one is inside spooler_manage_task .

diff -ruN core/spooler.c.orig core/spooler.c
--- core/spooler.c.orig 2012-10-29 09:58:04.147909174 +0100
+++ core/spooler.c  2012-11-02 11:25:30.586062100 +0100
@@ -356,6 +356,7 @@
        wakeup = tmp_wakeup;

        // need to recycle ?
+                uwsgi_log("max_tasks: %d tasks: %d\n", uwsgi.spooler_max_tasks, uspool->tasks);
        if (uwsgi.spooler_max_tasks > 0 && uspool->tasks >= (uint64_t)uwsgi.spooler_max_tasks) {
            uwsgi_log("[spooler %s pid: %d] maximum number of tasks reached (%d) recycling ...\n", uspool->dir, (int) uwsgi.mypid, uwsgi.spooler_max_tasks);
            end_me(0);
@@ -530,10 +531,13 @@
                    if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
                                    set_spooler_harakiri(0);
                            }
+                                        uwsgi_log("spooler ret was %d\n", ret);
                    if (ret == 0) continue;
                    callable_found = 1;
                    // increase task counter
+                                        uwsgi_log("incrementing uspool tasks, was %d", uspool->tasks);
                    uspool->tasks++;
+                                        uwsgi_log("  is %d\n", uspool->tasks);
                    if (ret == -2) {
                        if (!uwsgi.spooler_quiet)
                            uwsgi_log("[spooler %s pid: %d] done with task %s after %d seconds\n", uspool->dir, (int) uwsgi.mypid, task, uwsgi_now()-now);

So the check of max spool tasks should be done after each call of spooler_manage_task instead?

xrmx commented 11 years ago

Fixed in 09fca72b4ce86d871c2bbef70657105933e2a385 . Thanks!