From f54aa412b13e5a0c83b9369c2c9a4e5920476d25 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 29 Sep 2014 21:22:28 +1000 Subject: [PATCH] Create a linked list of each worker per user and decay per worker shares separately --- src/stratifier.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index f56a2314..99040cd7 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -212,6 +212,9 @@ struct user_instance { /* A linked list of all connected instances of this user */ stratum_instance_t *instances; + /* A linked list of all connected workers of this user */ + worker_instance_t *worker_instances; + int workers; double dsps1; /* Diff shares per second, 1 minute rolling average */ @@ -225,6 +228,9 @@ static user_instance_t *user_instances; /* Combined data from workers with the same workername */ struct worker_instance { + worker_instance_t *next; + worker_instance_t *prev; + double dsps1; double dsps5; double dsps60; @@ -1505,8 +1511,10 @@ static user_instance_t *generate_user(ckpool_t *ckp, stratum_instance_t *client, } /* Create one worker instance for combined data from workers of the * same name */ - if (!client->worker_instance) + if (!client->worker_instance) { client->worker_instance = ckzalloc(sizeof(worker_instance_t)); + DL_APPEND(instance->worker_instances, client->worker_instance); + } DL_APPEND(instance->instances, client); ck_wunlock(&instance_lock); @@ -2877,6 +2885,7 @@ static void *statsupdate(void *arg) if (!client->authorised) continue; + /* Decay times per connected instance */ if (now.tv_sec - client->last_share.tv_sec > 60) { /* No shares for over a minute, decay to 0 */ decay_time(&client->dsps1, 0, tdiff, 60); @@ -2890,10 +2899,21 @@ static void *statsupdate(void *arg) } HASH_ITER(hh, user_instances, instance, tmpuser) { + worker_instance_t *worker; bool idle = false; + /* Decay times per worker */ + DL_FOREACH(instance->worker_instances, worker) { + if (now.tv_sec - worker->last_share.tv_sec > 60) { + decay_time(&worker->dsps1, 0, tdiff, 60); + decay_time(&worker->dsps5, 0, tdiff, 300); + decay_time(&worker->dsps60, 0, tdiff, 3600); + decay_time(&worker->dsps1440, 0, tdiff, 86400); + } + } + + /* Decay times per user */ if (now.tv_sec - instance->last_share.tv_sec > 60) { - /* No shares for over a minute, decay to 0 */ decay_time(&instance->dsps1, 0, tdiff, 60); decay_time(&instance->dsps5, 0, tdiff, 300); decay_time(&instance->dsps60, 0, tdiff, 3600);