Browse Source

Rework client examination loop in statsupdate

master
Con Kolivas 8 years ago
parent
commit
44b03fcf29
  1. 44
      src/stratifier.c

44
src/stratifier.c

@ -7140,48 +7140,29 @@ static void *statsupdate(void *arg)
tv_time(&now); tv_time(&now);
timersub(&now, &stats->start_time, &diff); timersub(&now, &stats->start_time, &diff);
while (client) {
ck_wlock(&sdata->instance_lock); ck_wlock(&sdata->instance_lock);
if (unlikely(!client)) {
/* Grab the first entry */ /* Grab the first entry */
client = sdata->stratum_instances; client = sdata->stratum_instances;
} else {
/* Drop the reference of the last entry we examined,
* then grab the next client. */
__dec_instance_ref(client);
client = client->hh.next;
}
/* Grab a reference to this client allowing us to examine
* it without holding the lock */
if (likely(client)) if (likely(client))
__inc_instance_ref(client); __inc_instance_ref(client);
ck_wunlock(&sdata->instance_lock); ck_wunlock(&sdata->instance_lock);
/* Reached last entry */ while (client) {
if (unlikely(!client))
break;
/* Look for clients that may have been dropped which the /* Look for clients that may have been dropped which the
* stratifier has not been informed about and ask the * stratifier has not been informed about and ask the
* connector if they still exist */ * connector if they still exist */
if (client->dropped) { if (client->dropped)
connector_test_client(ckp, client->id); connector_test_client(ckp, client->id);
continue; else if (client->node || client->remote) {
} /* Do nothing to these */
} else if (!client->authorised) {
if (client->node || client->remote)
continue;
/* Test for clients that haven't authed in over a minute /* Test for clients that haven't authed in over a minute
* and drop them lazily */ * and drop them lazily */
if (!client->authorised) {
if (now.tv_sec > client->start_time + 60) { if (now.tv_sec > client->start_time + 60) {
client->dropped = true; client->dropped = true;
connector_drop_client(ckp, client->id); connector_drop_client(ckp, client->id);
} }
continue; } else {
}
per_tdiff = tvdiff(&now, &client->last_share); per_tdiff = tvdiff(&now, &client->last_share);
/* Decay times per connected instance */ /* Decay times per connected instance */
if (per_tdiff > 60) { if (per_tdiff > 60) {
@ -7192,10 +7173,21 @@ static void *statsupdate(void *arg)
client->idle = true; client->idle = true;
/* Test idle clients are still connected */ /* Test idle clients are still connected */
connector_test_client(ckp, client->id); connector_test_client(ckp, client->id);
continue;
} }
} }
ck_wlock(&sdata->instance_lock);
/* Drop the reference of the last entry we examined,
* then grab the next client. */
__dec_instance_ref(client);
client = client->hh.next;
/* Grab a reference to this client allowing us to examine
* it without holding the lock */
if (likely(client))
__inc_instance_ref(client);
ck_wunlock(&sdata->instance_lock);
}
/* Drop and regain lock to minimise lock hold time */ /* Drop and regain lock to minimise lock hold time */
ck_rlock(&sdata->instance_lock); ck_rlock(&sdata->instance_lock);
HASH_ITER(hh, sdata->user_instances, user, tmpuser) { HASH_ITER(hh, sdata->user_instances, user, tmpuser) {

Loading…
Cancel
Save