Browse Source

Create a separate hashtable for disconnected clients and only store reusable instances, adding reusable stats

master
Con Kolivas 11 years ago
parent
commit
31021f3d13
  1. 59
      src/stratifier.c

59
src/stratifier.c

@ -39,6 +39,7 @@ struct pool_stats {
int live_clients; int live_clients;
int dead_clients; int dead_clients;
int reused_clients; int reused_clients;
int reusable_clients;
/* Absolute shares stats */ /* Absolute shares stats */
int unaccounted_shares; int unaccounted_shares;
@ -173,7 +174,6 @@ struct stratum_instance {
tv_t first_share; tv_t first_share;
bool authorised; bool authorised;
bool disconnected;
char *useragent; char *useragent;
char *workername; char *workername;
@ -182,7 +182,10 @@ struct stratum_instance {
typedef struct stratum_instance stratum_instance_t; typedef struct stratum_instance stratum_instance_t;
/* Stratum_instances hashlist is stored by id, whereas disconnected_instances
* is sorted by enonce1_64. */
static stratum_instance_t *stratum_instances; static stratum_instance_t *stratum_instances;
static stratum_instance_t *disconnected_instances;
static cklock_t instance_lock; static cklock_t instance_lock;
@ -449,11 +452,11 @@ static stratum_instance_t *__stratum_add_instance(int id)
return instance; return instance;
} }
static bool sessionid_exists(const char *sessionid, int id) static bool disconnected_sessionid_exists(const char *sessionid, int id)
{ {
bool connected_exists = false, ret = false;
stratum_instance_t *instance, *tmp; stratum_instance_t *instance, *tmp;
uint64_t session64; uint64_t session64;
bool ret = false;
if (!sessionid) if (!sessionid)
goto out; goto out;
@ -468,13 +471,18 @@ static bool sessionid_exists(const char *sessionid, int id)
continue; continue;
if (instance->enonce1_64 == session64) { if (instance->enonce1_64 == session64) {
/* Only allow one connected instance per enonce1 */ /* Only allow one connected instance per enonce1 */
if (instance->disconnected) connected_exists = true;
ret = true;
break; break;
} }
} }
if (connected_exists)
goto out_unlock;
instance = NULL;
HASH_FIND(hh, disconnected_instances, &session64, sizeof(uint64_t), instance);
if (instance)
ret = true;
out_unlock:
ck_runlock(&instance_lock); ck_runlock(&instance_lock);
out: out:
return ret; return ret;
} }
@ -511,8 +519,6 @@ static void stratum_broadcast(json_t *val)
if (!instance->authorised) if (!instance->authorised)
continue; continue;
if (instance->disconnected)
continue;
msg = ckzalloc(sizeof(stratum_msg_t)); msg = ckzalloc(sizeof(stratum_msg_t));
msg->json_msg = json_deep_copy(val); msg->json_msg = json_deep_copy(val);
msg->client_id = instance->id; msg->client_id = instance->id;
@ -548,21 +554,30 @@ static void stratum_add_send(json_t *val, int client_id)
mutex_unlock(&stratum_send_lock); mutex_unlock(&stratum_send_lock);
} }
static void drop_client(int client_id) static void drop_client(int id)
{ {
stratum_instance_t *client; stratum_instance_t *client = NULL;
ck_ilock(&instance_lock);
client = __instance_by_id(id);
if (client) {
stratum_instance_t *old_client = NULL;
stats.live_clients--; stats.live_clients--;
stats.dead_clients++; stats.dead_clients++;
ck_rlock(&instance_lock); ck_ulock(&instance_lock);
client = __instance_by_id(client_id); HASH_DEL(stratum_instances, client);
ck_runlock(&instance_lock); HASH_FIND(hh, disconnected_instances, &client->enonce1_64, sizeof(uint64_t), old_client);
/* Only keep around one copy of the old client */
/* May never have been a stratum instance */ if (!old_client) {
if (unlikely(!client)) stats.reusable_clients++;
return; HASH_ADD(hh, disconnected_instances, enonce1_64, sizeof(uint64_t), client);
client->disconnected = true; } else
free(client);
ck_dwilock(&instance_lock);
}
ck_uilock(&instance_lock);
} }
static int strat_loop(ckpool_t *ckp, proc_instance_t *pi) static int strat_loop(ckpool_t *ckp, proc_instance_t *pi)
@ -698,7 +713,7 @@ static json_t *parse_subscribe(int client_id, json_t *params_val)
buf = json_string_value(json_array_get(params_val, 1)); buf = json_string_value(json_array_get(params_val, 1));
LOGDEBUG("Found old session id %s", buf); LOGDEBUG("Found old session id %s", buf);
/* Add matching here */ /* Add matching here */
if (sessionid_exists(buf, client_id)) { if (disconnected_sessionid_exists(buf, client_id)) {
hex2bin(&client->enonce1_64, buf, 8); hex2bin(&client->enonce1_64, buf, 8);
strcpy(client->enonce1, buf); strcpy(client->enonce1, buf);
old_match = true; old_match = true;
@ -1381,8 +1396,10 @@ static void *statsupdate(void *arg)
suffix_string(ghs, suffix15, 16, 0); suffix_string(ghs, suffix15, 16, 0);
ghs = stats.dsps60 * (double)4294967296; ghs = stats.dsps60 * (double)4294967296;
suffix_string(ghs, suffix60, 16, 0); suffix_string(ghs, suffix60, 16, 0);
LOGNOTICE("Pool runtime: %lus Live clients: %d Dead clients: %d Reused clients: %d", LOGNOTICE("Pool runtime: %lus Live clients: %d Dead clients: %d "
diff.tv_sec, stats.live_clients, stats.dead_clients, stats.reused_clients); "Reusable clients: %d Reused clients: %d",
diff.tv_sec, stats.live_clients, stats.dead_clients,
stats.reusable_clients, stats.reused_clients);
LOGNOTICE("Pool hashrate (1m):%s (5m):%s (15m):%s (60m):%s", LOGNOTICE("Pool hashrate (1m):%s (5m):%s (15m):%s (60m):%s",
suffix1, suffix5, suffix15, suffix60); suffix1, suffix5, suffix15, suffix60);
} }

Loading…
Cancel
Save