Browse Source

Count effective number recruited and subtract that from the recruit requests count

master
Con Kolivas 10 years ago
parent
commit
794770422d
  1. 22
      src/generator.c

22
src/generator.c

@ -109,7 +109,7 @@ struct proxy_instance {
bool reconnect; /* We need to drop and reconnect */ bool reconnect; /* We need to drop and reconnect */
bool reconnecting; /* Testing in progress */ bool reconnecting; /* Testing in progress */
bool redirecting; /* Children have received a reconnect */ bool redirecting; /* Children have received a reconnect */
int recruit; /* Recruiting in progress */ int64_t recruit; /* No of recruiting requests in progress */
bool alive; bool alive;
mutex_t notify_lock; mutex_t notify_lock;
@ -572,6 +572,7 @@ static bool parse_subscribe(connsock_t *cs, proxy_instance_t *proxi)
{ {
json_t *val = NULL, *res_val, *notify_val, *tmp; json_t *val = NULL, *res_val, *notify_val, *tmp;
bool parsed, ret = false; bool parsed, ret = false;
proxy_instance_t *parent;
int retries = 0, size; int retries = 0, size;
const char *string; const char *string;
char *buf, *old; char *buf, *old;
@ -665,14 +666,14 @@ retry:
} }
} }
proxi->nonce2len = size; proxi->nonce2len = size;
if (parent_proxy(proxi)) {
/* Set the number of clients per proxy on the parent proxy */
proxi->clients_per_proxy = 1ll << ((size - 3) * 8); proxi->clients_per_proxy = 1ll << ((size - 3) * 8);
LOGNOTICE("Proxy %ld:%s clients per proxy: %"PRId64, proxi->id, proxi->si->url, parent = proxi->parent;
proxi->clients_per_proxy);
if (proxi->clients_per_proxy == 1) mutex_lock(&parent->proxy_lock);
recruit_subproxies(proxi, 1); parent->recruit -= proxi->clients_per_proxy;
} if (parent->recruit < 0)
parent->recruit = 0;
mutex_unlock(&parent->proxy_lock);
LOGNOTICE("Found notify for new proxy %ld:%d with enonce %s nonce2len %d", proxi->id, LOGNOTICE("Found notify for new proxy %ld:%d with enonce %s nonce2len %d", proxi->id,
proxi->subid, proxi->enonce1, proxi->nonce2len); proxi->subid, proxi->enonce1, proxi->nonce2len);
@ -1733,10 +1734,9 @@ retry:
add_subproxy(parent, proxy); add_subproxy(parent, proxy);
mutex_lock(&parent->proxy_lock); mutex_lock(&parent->proxy_lock);
if (alive) { if (alive && parent->recruit > 0)
if (--parent->recruit > 0)
recruit = true; recruit = true;
} else /* Reset so the next request will try again */ else /* Reset so the next request will try again */
parent->recruit = 0; parent->recruit = 0;
mutex_unlock(&parent->proxy_lock); mutex_unlock(&parent->proxy_lock);

Loading…
Cancel
Save