Browse Source

Send workerstats to ckdb instead of client stats

master
Con Kolivas 10 years ago
parent
commit
5ccd3b5340
  1. 63
      src/stratifier.c

63
src/stratifier.c

@ -252,6 +252,7 @@ struct worker_instance {
int mindiff; /* User chosen mindiff */ int mindiff; /* User chosen mindiff */
bool idle; bool idle;
bool notified_idle;
}; };
/* Per client stratum instance == workers */ /* Per client stratum instance == workers */
@ -286,7 +287,6 @@ struct stratum_instance {
bool subscribed; bool subscribed;
bool authorised; bool authorised;
bool idle; bool idle;
bool notified_idle;
int reject; /* Indicator that this client is having a run of rejects int reject; /* Indicator that this client is having a run of rejects
* or other problem and should be dropped lazily if * or other problem and should be dropped lazily if
* this is set to 2 */ * this is set to 2 */
@ -344,7 +344,7 @@ static int gen_priority;
#define ID_SHARES 3 #define ID_SHARES 3
#define ID_SHAREERR 4 #define ID_SHAREERR 4
#define ID_POOLSTATS 5 #define ID_POOLSTATS 5
#define ID_USERSTATS 6 #define ID_WORKERSTATS 6
#define ID_BLOCK 7 #define ID_BLOCK 7
#define ID_ADDRAUTH 8 #define ID_ADDRAUTH 8
#define ID_HEARTBEAT 9 #define ID_HEARTBEAT 9
@ -356,7 +356,7 @@ static const char *ckdb_ids[] = {
"shares", "shares",
"shareerror", "shareerror",
"poolstats", "poolstats",
"userstats", "workerstats",
"block", "block",
"addrauth", "addrauth",
"heartbeat" "heartbeat"
@ -3177,12 +3177,11 @@ out:
/* Called every 20 seconds, we send the updated stats to ckdb of those users /* Called every 20 seconds, we send the updated stats to ckdb of those users
* who have gone 10 minutes between updates. This ends up staggering stats to * who have gone 10 minutes between updates. This ends up staggering stats to
* avoid floods of stat data coming at once. */ * avoid floods of stat data coming at once. */
static void update_userstats(ckpool_t *ckp) static void update_workerstats(ckpool_t *ckp)
{ {
stratum_instance_t *client, *tmp; user_instance_t *user, *tmp;
char cdfield[64]; char cdfield[64];
time_t now_t; time_t now_t;
json_t *val;
ts_t ts_now; ts_t ts_now;
if (++stats.userstats_cycle > 0x1f) if (++stats.userstats_cycle > 0x1f)
@ -3193,47 +3192,47 @@ static void update_userstats(ckpool_t *ckp)
now_t = ts_now.tv_sec; now_t = ts_now.tv_sec;
ck_rlock(&instance_lock); ck_rlock(&instance_lock);
HASH_ITER(hh, stratum_instances, client, tmp) { HASH_ITER(hh, user_instances, user, tmp) {
double ghs1, ghs5, ghs60, ghs1440; worker_instance_t *worker;
uint8_t cycle_mask; uint8_t cycle_mask;
int elapsed;
if (!client->authorised) /* Select users using a mask to return each user's stats once
continue;
/* Send one lot of stats once the client is idle if they have submitted
* no shares in the last 10 minutes with the idle bool set. */
if (client->idle && client->notified_idle)
continue;
/* Select clients using a mask to return each user's stats once
* every ~10 minutes */ * every ~10 minutes */
cycle_mask = client->user_id & 0x1f; cycle_mask = user->id & 0x1f;
if (cycle_mask != stats.userstats_cycle) if (cycle_mask != stats.userstats_cycle)
continue; continue;
DL_FOREACH(user->worker_instances, worker) {
double ghs1, ghs5, ghs60, ghs1440;
int elapsed;
json_t *val;
elapsed = now_t - client->start_time; /* Send one lot of stats once the worker is idle if
ghs1 = client->dsps1 * nonces; * they have submitted no shares in the last 10 minutes
ghs5 = client->dsps5 * nonces; * with the idle bool set. */
ghs60 = client->dsps60 * nonces; if (worker->idle && worker->notified_idle)
ghs1440 = client->dsps1440 * nonces; continue;
JSON_CPACK(val, "{ss,sI,si,ss,ss,sf,sf,sf,sf,sb,ss,ss,ss,ss}", elapsed = now_t - worker->start_time;
ghs1 = worker->dsps1 * nonces;
ghs5 = worker->dsps5 * nonces;
ghs60 = worker->dsps60 * nonces;
ghs1440 = worker->dsps1440 * nonces;
JSON_CPACK(val, "{ss,si,ss,ss,sf,sf,sf,sf,sb,ss,ss,ss,ss}",
"poolinstance", ckp->name, "poolinstance", ckp->name,
"instanceid", client->id,
"elapsed", elapsed, "elapsed", elapsed,
"username", client->user_instance->username, "username", user->username,
"workername", client->workername, "workername", worker->workername,
"hashrate", ghs1, "hashrate", ghs1,
"hashrate5m", ghs5, "hashrate5m", ghs5,
"hashrate1hr", ghs60, "hashrate1hr", ghs60,
"hashrate24hr", ghs1440, "hashrate24hr", ghs1440,
"idle", client->idle, "idle", worker->idle,
"createdate", cdfield, "createdate", cdfield,
"createby", "code", "createby", "code",
"createcode", __func__, "createcode", __func__,
"createinet", ckp->serverurl); "createinet", ckp->serverurl);
client->notified_idle = client->idle; worker->notified_idle = worker->idle;
ckdbq_add(ckp, ID_USERSTATS, val); ckdbq_add(ckp, ID_WORKERSTATS, val);
val = NULL; }
} }
ck_runlock(&instance_lock); ck_runlock(&instance_lock);
} }
@ -3478,7 +3477,7 @@ static void *statsupdate(void *arg)
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
cksleep_ms_r(&stats.last_update, 20000); cksleep_ms_r(&stats.last_update, 20000);
cksleep_prepare_r(&stats.last_update); cksleep_prepare_r(&stats.last_update);
update_userstats(ckp); update_workerstats(ckp);
mutex_lock(&stats_lock); mutex_lock(&stats_lock);
stats.accounted_shares += stats.unaccounted_shares; stats.accounted_shares += stats.unaccounted_shares;

Loading…
Cancel
Save