Пример #1
0
/* Just return the number of queued messages.
 */
int thorium_worker_get_message_production_score(struct thorium_worker *worker)
{
    int score;

    score = 0;

    score += core_fast_ring_size_from_producer(&worker->outbound_message_queue);

    score += core_fast_queue_size(&worker->outbound_message_queue_buffer);

    return score;
}
Пример #2
0
int main(int argc, char **argv)
{
    BEGIN_TESTS();

    struct core_fast_ring ring;
    int capacity = 64;
    int i;
    int value;
    int elements;

    elements = 0;

#if 0
    printf("Required %d\n", capacity);
#endif
    core_fast_ring_init(&ring, capacity, sizeof(int));

    capacity = core_fast_ring_capacity(&ring);

#if 0
    printf("Provided %d\n", capacity);
#endif

    TEST_BOOLEAN_EQUALS(core_fast_ring_is_empty_from_consumer(&ring), 1);

    for (i = 0; i < capacity; i++) {
        TEST_BOOLEAN_EQUALS(core_fast_ring_push_from_producer(&ring, &i), 1);
        elements++;

        TEST_INT_EQUALS(core_fast_ring_size_from_producer(&ring), elements);
        TEST_INT_EQUALS(core_fast_ring_size_from_consumer(&ring), elements);
    }

    TEST_BOOLEAN_EQUALS(core_fast_ring_is_full_from_producer(&ring), 1);

    for (i = 0; i < capacity; i++) {
        TEST_BOOLEAN_EQUALS(core_fast_ring_pop_from_consumer(&ring, &value), 1);
        elements--;
        TEST_INT_EQUALS(value, i);
        TEST_INT_EQUALS(core_fast_ring_size_from_producer(&ring), elements);
        TEST_INT_EQUALS(core_fast_ring_size_from_consumer(&ring), elements);
    }
    core_fast_ring_destroy(&ring);

    {
        struct core_fast_ring ring;
        int capacity = 64;
        struct thorium_message message;
        int action;
        int count;
        void *buffer;
        int inserted;
        int pulled;

        action = 1234;
        count = 0;
        buffer = NULL;

        thorium_message_init(&message, action, count, buffer);

        core_fast_ring_init(&ring, capacity, sizeof(struct thorium_message));
        core_fast_ring_use_multiple_producers(&ring);

        inserted = 0;

        while (core_fast_ring_push_from_producer(&ring, &message)) {
            ++inserted;
        }

        /*
         * 64 + 1 = 65, 128 is the next power of 2 for the mask.
         */
        /*
        TEST_INT_EQUALS(inserted, capacity);
        */

        pulled = 0;

        while (core_fast_ring_pop_from_consumer(&ring, &message)) {
            ++pulled;
        }

        TEST_INT_EQUALS(inserted, pulled);

        core_fast_ring_destroy(&ring);

        thorium_message_destroy(&message);
    }

    END_TESTS();

    return 0;
}
Пример #3
0
int core_fast_ring_empty(struct core_fast_ring *self)
{
    return core_fast_ring_size_from_producer(self) == 0;
}
Пример #4
0
void thorium_worker_print_actors(struct thorium_worker *worker, struct thorium_balancer *scheduler)
{
    struct core_map_iterator iterator;
    int name;
    int count;
    struct thorium_actor *actor;
    int producers;
    int consumers;
    int received;
    int difference;
    int script;
    struct core_map distribution;
    int frequency;
    struct thorium_script *script_object;
    int dead;
    int node_name;
    int worker_name;
    int previous_amount;

    node_name = thorium_node_name(worker->node);
    worker_name = worker->name;

    core_map_iterator_init(&iterator, &worker->actors);

    printf("node/%d worker/%d %d queued messages, received: %d busy: %d load: %f ring: %d scheduled actors: %d/%d\n",
                    node_name, worker_name,
                    thorium_worker_get_scheduled_message_count(worker),
                    thorium_worker_get_sum_of_received_actor_messages(worker),
                    thorium_worker_is_busy(worker),
                    thorium_worker_get_scheduling_epoch_load(worker),
                    core_fast_ring_size_from_producer(&worker->actors_to_schedule),
                    thorium_scheduler_size(&worker->scheduler),
                    (int)core_map_size(&worker->actors));

    core_map_init(&distribution, sizeof(int), sizeof(int));

    while (core_map_iterator_get_next_key_and_value(&iterator, &name, NULL)) {

        actor = thorium_node_get_actor_from_name(worker->node, name);

        if (actor == NULL) {
            continue;
        }

        dead = thorium_actor_dead(actor);

        if (dead) {
            continue;
        }

        count = thorium_actor_get_mailbox_size(actor);
        received = thorium_actor_get_sum_of_received_messages(actor);
        producers = core_map_size(thorium_actor_get_received_messages(actor));
        consumers = core_map_size(thorium_actor_get_sent_messages(actor));
        previous_amount = 0;

        core_map_get_value(&worker->actor_received_messages, &name,
                        &previous_amount);
        difference = received - previous_amount;;

        if (!core_map_update_value(&worker->actor_received_messages, &name,
                        &received)) {
            core_map_add_value(&worker->actor_received_messages, &name, &received);
        }

        printf("  [%s/%d] mailbox: %d received: %d (+%d) producers: %d consumers: %d\n",
                        thorium_actor_script_name(actor),
                        name, count, received,
                       difference,
                       producers, consumers);

        script = thorium_actor_script(actor);

        if (core_map_get_value(&distribution, &script, &frequency)) {
            ++frequency;
            core_map_update_value(&distribution, &script, &frequency);
        } else {
            frequency = 1;
            core_map_add_value(&distribution, &script, &frequency);
        }
    }

    /*printf("\n");*/
    core_map_iterator_destroy(&iterator);

    core_map_iterator_init(&iterator, &distribution);

    printf("node/%d worker/%d Frequency list\n", node_name, worker_name);

    while (core_map_iterator_get_next_key_and_value(&iterator, &script, &frequency)) {

        script_object = thorium_node_find_script(worker->node, script);

        CORE_DEBUGGER_ASSERT(script_object != NULL);

        printf("node/%d worker/%d Frequency %s => %d\n",
                        node_name,
                        worker->name,
                        thorium_script_name(script_object),
                        frequency);
    }

    core_map_iterator_destroy(&iterator);
    core_map_destroy(&distribution);
}
Пример #5
0
void thorium_worker_destroy(struct thorium_worker *worker)
{
    void *buffer;

    thorium_load_profiler_destroy(&worker->profiler);

    if (core_bitmap_get_bit_uint32_t(&worker->flags, FLAG_ENABLE_ACTOR_LOAD_PROFILER)) {
        core_buffered_file_writer_destroy(&worker->load_profile_writer);
    }

    core_map_destroy(&worker->actor_received_messages);

    /*
    thorium_worker_print_balance(worker);
    */
    while (thorium_worker_fetch_clean_outbound_buffer(worker, &buffer)) {

        core_memory_pool_free(&worker->outbound_message_memory_pool, buffer);

#ifdef THORIUM_WORKER_DEBUG_INJECTION
        ++worker->counter_freed_outbound_buffers_from_other_workers;
#endif
    }

#ifdef THORIUM_WORKER_DEBUG_INJECTION
    printf("AFTER COLLECTION\n");
    thorium_worker_print_balance(worker);

    printf("THORIUM-> clean_message_queue_for_triage has %d items\n",
                    core_fast_queue_size(&worker->clean_message_queue_for_triage));
    printf("THORIUM-> clean_message_ring_for_triage has %d items\n",
                    core_fast_ring_size_from_producer(&worker->clean_message_ring_for_triage));
    printf("THORIUM-> injected_clean_outbound_buffers has %d items\n",
                    core_fast_ring_size_from_producer(&worker->injected_clean_outbound_buffers));
#endif

    core_timer_destroy(&worker->timer);

#ifdef THORIUM_WORKER_ENABLE_LOCK
    core_lock_destroy(&worker->lock);
#endif

    core_fast_ring_destroy(&worker->actors_to_schedule);

#ifdef THORIUM_NODE_INJECT_CLEAN_WORKER_BUFFERS
    core_fast_ring_destroy(&worker->injected_clean_outbound_buffers);

    core_fast_ring_destroy(&worker->clean_message_ring_for_triage);
    core_fast_queue_destroy(&worker->clean_message_queue_for_triage);
#endif

    thorium_scheduler_destroy(&worker->scheduler);
    core_fast_ring_destroy(&worker->outbound_message_queue);
    core_fast_queue_destroy(&worker->outbound_message_queue_buffer);

    core_map_destroy(&worker->actors);
    core_map_iterator_destroy(&worker->actor_iterator);
    core_set_destroy(&worker->evicted_actors);

    worker->node = NULL;

    worker->name = -1;
    core_bitmap_set_bit_uint32_t(&worker->flags, FLAG_DEAD);

    core_memory_pool_destroy(&worker->ephemeral_memory);
    core_memory_pool_destroy(&worker->outbound_message_memory_pool);

    thorium_priority_assigner_destroy(&worker->assigner);
}