Beispiel #1
0
static stats_count_t spill_all(socket_worker_t * self, queue_t * private_queue, queue_t * spill_queue)
{
    blob_t *cur_blob = private_queue->head;

    if (!cur_blob)
        return 0;

    stats_count_t spilled = 0;

    spill_queue->head = cur_blob;
    spill_queue->count = 1;
    while (BLOB_NEXT(cur_blob)) {
        cur_blob = BLOB_NEXT(cur_blob);
        spill_queue->count++;
    }
    spill_queue->tail = cur_blob;
    private_queue->head = BLOB_NEXT(cur_blob);
    private_queue->count -= spill_queue->count;
    BLOB_NEXT_set(cur_blob, NULL);

    spilled += spill_queue->count;

    enqueue_queue_for_disk_writing(self, spill_queue);

    return spilled;
}
Beispiel #2
0
/* shift an item out of a queue non-safely */
blob_t *q_shift_nolock(queue_t *q) {
    blob_t *b= q->head;
    if (b) {
        if (BLOB_NEXT(b))
            q->head = BLOB_NEXT(b);
        else
            q->head = q->tail = NULL;
        q->count--;
    }
    return b;
}
Beispiel #3
0
/* Peels off all the blobs which have been in the input queue for longer
 * than the spill limit, move them to the spill queue, and enqueue
 * them for eventual spilling or dropping.
 *
 * Note that the "spill queue" is used either for actual spilling (to the disk)
 * or dropping.
 *
 * Returns the number of (eventually) spilled (if spill enabled) or
 * dropped (if spill disabled) items. */
static stats_count_t spill_by_age(socket_worker_t * self, int spill_enabled, queue_t * private_queue,
                                  queue_t * spill_queue, uint64_t spill_microsec, struct timeval *now)
{
    blob_t *cur_blob = private_queue->head;

    if (!cur_blob)
        return 0;

    /* If spill is disabled, this really counts the dropped packets. */
    stats_count_t spilled = 0;

    if (elapsed_usec(&BLOB_RECEIVED_TIME(cur_blob), now) >= spill_microsec) {
        spill_queue->head = cur_blob;
        spill_queue->count = 1;
        while (BLOB_NEXT(cur_blob)
               && elapsed_usec(&BLOB_RECEIVED_TIME(BLOB_NEXT(cur_blob)), now) >= spill_microsec) {
            cur_blob = BLOB_NEXT(cur_blob);
            spill_queue->count++;
        }
        spill_queue->tail = cur_blob;
        private_queue->head = BLOB_NEXT(cur_blob);
        private_queue->count -= spill_queue->count;
        BLOB_NEXT_set(cur_blob, NULL);

        spilled += spill_queue->count;

        if (spill_enabled) {
            RELAY_ATOMIC_INCREMENT(self->counters.spilled_count, spill_queue->count);
        } else {
            RELAY_ATOMIC_INCREMENT(self->counters.dropped_count, spill_queue->count);
        }

        enqueue_queue_for_disk_writing(self, spill_queue);
    }

    return spilled;
}