Browse Source

Find any subproxy with headroom to take more clients if we do not have enough upstream connections yet to service new clients

master
Con Kolivas 10 years ago
parent
commit
dba4f02fae
  1. 47
      src/stratifier.c

47
src/stratifier.c

@ -321,6 +321,7 @@ struct proxy_base {
int64_t clients; int64_t clients;
int64_t max_clients; int64_t max_clients;
int64_t headroom;
enonce1_t enonce1u; enonce1_t enonce1u;
proxy_t *parent; /* Parent proxy - set to self on parent itself */ proxy_t *parent; /* Parent proxy - set to self on parent itself */
@ -396,6 +397,7 @@ struct stratifier_data {
/* Generator message priority */ /* Generator message priority */
int gen_priority; int gen_priority;
int proxy_count;
proxy_t *proxy; /* Current proxy in use */ proxy_t *proxy; /* Current proxy in use */
proxy_t *proxies; /* Hashlist of all proxies */ proxy_t *proxies; /* Hashlist of all proxies */
proxy_t *old_proxies; /* Hashlist of proxies now no longer in user */ proxy_t *old_proxies; /* Hashlist of proxies now no longer in user */
@ -1047,6 +1049,7 @@ static proxy_t *__generate_proxy(sdata_t *sdata, const int id)
/* subid == 0 on parent proxy */ /* subid == 0 on parent proxy */
HASH_ADD(sh, proxy->subproxies, subid, sizeof(int), proxy); HASH_ADD(sh, proxy->subproxies, subid, sizeof(int), proxy);
HASH_ADD_INT(sdata->proxies, id, proxy); HASH_ADD_INT(sdata->proxies, id, proxy);
sdata->proxy_count++;
return proxy; return proxy;
} }
@ -1103,19 +1106,6 @@ static proxy_t *__subproxy_by_id(sdata_t *sdata, proxy_t *proxy, const int subid
return subproxy; return subproxy;
} }
#if 0
static proxy_t *proxy_by_id(sdata_t *sdata, const int id)
{
proxy_t *proxy;
mutex_lock(&sdata->proxy_lock);
proxy = __proxy_by_id(sdata, id);
mutex_unlock(&sdata->proxy_lock);
return proxy;
}
#endif
static proxy_t *subproxy_by_id(sdata_t *sdata, const int id, const int subid) static proxy_t *subproxy_by_id(sdata_t *sdata, const int id, const int subid)
{ {
proxy_t *proxy, *subproxy; proxy_t *proxy, *subproxy;
@ -2342,41 +2332,52 @@ static void stratum_send_message(sdata_t *sdata, const stratum_instance_t *clien
* running out of room. */ * running out of room. */
static sdata_t *select_sdata(const ckpool_t *ckp, sdata_t *ckp_sdata) static sdata_t *select_sdata(const ckpool_t *ckp, sdata_t *ckp_sdata)
{ {
proxy_t *proxy, *subproxy, *best = NULL, *tmp; proxy_t *current, *proxy, *subproxy, *best = NULL, *tmp, *tmpsub;
int64_t headroom = 0, most_headroom = 0; int best_id, best_subid = 0;
if (!ckp->proxy || ckp->passthrough) if (!ckp->proxy || ckp->passthrough)
return ckp_sdata; return ckp_sdata;
proxy = ckp_sdata->proxy; current = ckp_sdata->proxy;
if (!proxy) { if (!current) {
LOGWARNING("No proxy available yet to generate subscribes"); LOGWARNING("No proxy available yet to generate subscribes");
return NULL; return NULL;
} }
best_id = ckp_sdata->proxy_count;
mutex_lock(&ckp_sdata->proxy_lock); mutex_lock(&ckp_sdata->proxy_lock);
HASH_ITER(sh, proxy->subproxies, subproxy, tmp) { HASH_ITER(hh, ckp_sdata->proxies, proxy, tmp) {
int most_headroom;
proxy->headroom = most_headroom = 0;
HASH_ITER(sh, proxy->subproxies, subproxy, tmpsub) {
int64_t subproxy_headroom; int64_t subproxy_headroom;
if (subproxy->dead) if (subproxy->dead)
continue; continue;
subproxy_headroom = subproxy->max_clients - subproxy->clients; subproxy_headroom = subproxy->max_clients - subproxy->clients;
headroom += subproxy_headroom; proxy->headroom += subproxy_headroom;
if (subproxy_headroom > most_headroom) { if (subproxy_headroom > most_headroom) {
best = subproxy; best = subproxy;
most_headroom = subproxy_headroom; most_headroom = subproxy_headroom;
} }
} }
if (best && best->id < best_id) {
best_id = best->id;
best_subid = best->subid;
}
}
mutex_unlock(&ckp_sdata->proxy_lock); mutex_unlock(&ckp_sdata->proxy_lock);
if (headroom < 42) { if (best_id != current->id || current->headroom < 42) {
LOGNOTICE("Stratifer requesting more proxies from generator"); LOGNOTICE("Stratifer requesting more proxies from generator");
send_generator(ckp, "recruit", GEN_PRIORITY); send_generator(ckp, "recruit", GEN_PRIORITY);
} }
if (!best) { if (best_id == ckp_sdata->proxy_count) {
LOGNOTICE("Temporarily insufficient subproxies of proxy %d to accept more clients", LOGNOTICE("Temporarily insufficient subproxies to accept more clients");
proxy->id);
return NULL; return NULL;
} }
best = subproxy_by_id(ckp_sdata, best_id, best_subid);
return best->sdata; return best->sdata;
} }

Loading…
Cancel
Save