1. Con Kolivas
  2. ckpool

Commits

Con Kolivas  committed d15abbe

Keep track of in-progress connections to a proxy to minimise the number rejected from a full proxy concurrently.

Comments (1)

Files changed (1)

File src/stratifier.c Modified

View file
  • Ignore whitespace
  • Hide word diff
 	int64_t bound_clients; /* Currently actively bound clients */
 	int64_t combined_clients; /* Total clients of all subproxies of a parent proxy */
 	int64_t headroom; /* Temporary variable when calculating how many more clients can bind */
+	int connecting; /* New clients in the process of connecting */
 
 	int subproxy_count; /* Number of subproxies */
 	proxy_t *parent; /* Parent proxy of each subproxy */
 		mutex_unlock(&ckp_sdata->proxy_lock);
 
 		if (proxy->clients >= proxy->max_clients) {
-			LOGWARNING("Proxy reached max clients %"PRId64, proxy->max_clients);
+			LOGWARNING("Proxy %d reached max clients %"PRId64, proxy->id,
+				   proxy->max_clients);
 			return false;
 		}
 	}
 		proxy->clients++;
 		proxy->bound_clients++;
 		proxy->parent->combined_clients++;
+		proxy->connecting--;
 	}
 	ck_wunlock(&ckp_sdata->instance_lock);
 
 			continue;
 		if (!subproxy->sdata->current_workbase)
 			continue;
-		subproxy_headroom = subproxy->max_clients - subproxy->clients;
+		/* This subproxy data is checked without holding the correct
+		 * instance_lock but an incorrect value here is harmless */
+		subproxy_headroom = subproxy->max_clients - subproxy->clients - subproxy->connecting;
 
 		proxy->headroom += subproxy_headroom;
 		if (subproxy_headroom > max_headroom) {
 			LOGNOTICE("Temporarily insufficient proxies for userid %d to accept more clients", userid);
 		return NULL;
 	}
+
+	/* Keep track of in-progress connecting clients. This will overestimate
+	 * if they go on to fail but that's inherently safer */
+	ck_wlock(&ckp_sdata->instance_lock);
+	best->connecting++;
+	ck_wunlock(&ckp_sdata->instance_lock);
+
 	if (!userid) {
 		if (best->id != global->id || current_headroom(ckp_sdata, &proxy) < 2)
 			generator_recruit(ckp, global->id, 1);