Avoid overly large bursts of shovelling

This commit is contained in:
Tony Garnock-Jones 2011-01-02 15:21:12 -05:00
parent 187a17ca6d
commit cc275029f7
1 changed files with 16 additions and 4 deletions

20
queue.c
View File

@ -78,6 +78,15 @@ static int send_to_waiter(subscription_t *sub, sexp_t *body) {
return post_node(sexp_data(sub->sink), sexp_data(sub->name), body, sub->uuid);
}
static void end_burst(queue_extension_t *q, size_t *burst_count_ptr, size_t total_count) {
if (*burst_count_ptr > 0) {
info("Queue <<%.*s>>: burst count %lu; total %lu\n",
sexp_data(q->name).len, sexp_data(q->name).bytes,
*burst_count_ptr, total_count);
}
*burst_count_ptr = 0;
}
static void shoveller(void *qv) {
queue_extension_t *q = qv;
@ -129,17 +138,20 @@ static void shoveller(void *qv) {
DECREF(body, sexp_destructor);
queue_append(&q->waiter_q, &examined);
enqueue(&q->waiter_q, sub);
if (burst_count > 10000) {
end_burst(q, &burst_count, total_count);
yield();
}
goto check_for_work;
wait_and_shovel:
info("Queue <<%.*s>>: burst count %lu; total %lu\n",
sexp_data(q->name).len, sexp_data(q->name).bytes,
burst_count, total_count);
end_burst(q, &burst_count, total_count);
//info("Waiting for throck\n");
q->shovel_awake = 0;
suspend();
//info("Throck received!\n");
burst_count = 0;
goto check_for_work;
}