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);
timersub(&now, &stats->start_time, &diff);
while (client) {
ck_wlock(&sdata->instance_lock);
if (unlikely(!client)) {
/* Grab the first entry */
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))
__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
* stratifier has not been informed about and ask the
* connector if they still exist */
if (client->dropped) {
if (client->dropped)
connector_test_client(ckp, client->id);
continue;
}
if (client->node || client->remote)
continue;
else if (client->node || client->remote) {
/* Do nothing to these */
} else if (!client->authorised) {
/* 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;
}
} else {
per_tdiff = tvdiff(&now, &client->last_share);
/* Decay times per connected instance */
if (per_tdiff > 60) {
@ -7192,10 +7173,21 @@ static void *statsupdate(void *arg)
client->idle = true;
/* Test idle clients are still connected */
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 */
ck_rlock(&sdata->instance_lock);
HASH_ITER(hh, sdata->user_instances, user, tmpuser) {

Loading…
Cancel
Save