Browse Source

Rework client examination loop in statsupdate

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

78
src/stratifier.c

@ -7140,60 +7140,52 @@ 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); /* Grab the first entry */
if (unlikely(!client)) { client = sdata->stratum_instances;
/* Grab the first entry */ if (likely(client))
client = sdata->stratum_instances; __inc_instance_ref(client);
} else { ck_wunlock(&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);
/* Reached last entry */
if (unlikely(!client))
break;
while (client) {
/* 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) /* Test for clients that haven't authed in over a minute
continue; * and drop them lazily */
/* 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) { 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);
/* Decay times per connected instance */
if (per_tdiff > 60) {
/* No shares for over a minute, decay to 0 */
decay_client(client, 0, &now);
idle_workers++;
if (per_tdiff > 600)
client->idle = true;
/* Test idle clients are still connected */
connector_test_client(ckp, client->id);
}
} }
per_tdiff = tvdiff(&now, &client->last_share); ck_wlock(&sdata->instance_lock);
/* Decay times per connected instance */ /* Drop the reference of the last entry we examined,
if (per_tdiff > 60) { * then grab the next client. */
/* No shares for over a minute, decay to 0 */ __dec_instance_ref(client);
decay_client(client, 0, &now); client = client->hh.next;
idle_workers++; /* Grab a reference to this client allowing us to examine
if (per_tdiff > 600) * it without holding the lock */
client->idle = true; if (likely(client))
/* Test idle clients are still connected */ __inc_instance_ref(client);
connector_test_client(ckp, client->id); ck_wunlock(&sdata->instance_lock);
continue;
}
} }
/* Drop and regain lock to minimise lock hold time */ /* Drop and regain lock to minimise lock hold time */

Loading…
Cancel
Save