Browse Source

Move testing clients to the stats update thread to decrease overhead in stratum_broadcast and handling disconnects in node mode, testing idle clients as well.

master
Con Kolivas 9 years ago
parent
commit
991f6b02e4
  1. 43
      src/stratifier.c

43
src/stratifier.c

@ -2649,7 +2649,6 @@ static void stratum_broadcast(sdata_t *sdata, json_t *val, const int msg_type)
sdata_t *ckp_sdata = ckp->data; sdata_t *ckp_sdata = ckp->data;
stratum_instance_t *client, *tmp; stratum_instance_t *client, *tmp;
ckmsg_t *bulk_send = NULL; ckmsg_t *bulk_send = NULL;
time_t now_t = time(NULL);
int messages = 0; int messages = 0;
if (unlikely(!val)) { if (unlikely(!val)) {
@ -2662,7 +2661,6 @@ static void stratum_broadcast(sdata_t *sdata, json_t *val, const int msg_type)
return; return;
} }
/* Use this locking as an opportunity to test other clients. */
ck_rlock(&ckp_sdata->instance_lock); ck_rlock(&ckp_sdata->instance_lock);
HASH_ITER(hh, ckp_sdata->stratum_instances, client, tmp) { HASH_ITER(hh, ckp_sdata->stratum_instances, client, tmp) {
ckmsg_t *client_msg; ckmsg_t *client_msg;
@ -2671,26 +2669,7 @@ static void stratum_broadcast(sdata_t *sdata, json_t *val, const int msg_type)
if (sdata != ckp_sdata && client->sdata != sdata) if (sdata != ckp_sdata && client->sdata != sdata)
continue; continue;
/* Look for clients that may have been dropped which the stratifer has if (!client_active(client) || client->node || client->remote)
* not been informed about and ask the connector of they still exist */
if (client->dropped) {
connector_test_client(ckp, client->id);
continue;
}
if (client->node || client->remote)
continue;
/* Test for clients that haven't authed in over a minute and drop them */
if (!client->authorised) {
if (now_t > client->start_time + 60) {
client->dropped = true;
connector_drop_client(ckp, client->id);
}
continue;
}
if (!client_active(client))
continue; continue;
/* Only send messages to whitelisted clients */ /* Only send messages to whitelisted clients */
@ -6733,10 +6712,26 @@ static void *statsupdate(void *arg)
tv_time(&now); tv_time(&now);
timersub(&now, &stats->start_time, &diff); timersub(&now, &stats->start_time, &diff);
/* Use this locking as an opportunity to test clients. */
ck_rlock(&sdata->instance_lock); ck_rlock(&sdata->instance_lock);
HASH_ITER(hh, sdata->stratum_instances, client, tmp) { HASH_ITER(hh, sdata->stratum_instances, client, tmp) {
if (!client_active(client)) /* Look for clients that may have been dropped which the
* stratifier has not been informed about and ask the
* connector if they still exist */
if (client->dropped) {
connector_test_client(ckp, client->id);
continue;
}
/* Test for clients that haven't authed in over a minute
* and drop them lazily */
if (!client->authorised) {
if (now.tv_sec > client->start_time + 60) {
client->dropped = true;
connector_drop_client(ckp, client->id);
}
continue; continue;
}
per_tdiff = tvdiff(&now, &client->last_share); per_tdiff = tvdiff(&now, &client->last_share);
/* Decay times per connected instance */ /* Decay times per connected instance */
@ -6746,6 +6741,8 @@ static void *statsupdate(void *arg)
idle_workers++; idle_workers++;
if (per_tdiff > 600) if (per_tdiff > 600)
client->idle = true; client->idle = true;
/* Test idle clients are still connected */
connector_test_client(ckp, client->id);
continue; continue;
} }
} }

Loading…
Cancel
Save