1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-11 07:17:58 +00:00

Find the greatest common denominator in quotas and use the smallest number of consecutive work items per pool in quota load balance mode to smooth hashrate across pools with large quotas. Give excess quota to priority pool 0 instead of pool 0.

This commit is contained in:
Con Kolivas 2013-09-13 13:51:15 +10:00
parent 8ac4fa202d
commit a76b09e4fc
4 changed files with 54 additions and 6 deletions

6
README
View File

@ -517,9 +517,9 @@ If all pools are set to zero quota or all pools with quota are dead, it will
fall back to a failover mode. See quota below for more information. fall back to a failover mode. See quota below for more information.
The failover-only flag has special meaning in combination with load-balance The failover-only flag has special meaning in combination with load-balance
mode and it will distribute quota back to pool 0 from any pools that are mode and it will distribute quota back to priority pool 0 from any pools that
unable to provide work for any reason so as to maintain quota ratios between are unable to provide work for any reason so as to maintain quota ratios
the rest of the pools. between the rest of the pools.
BALANCE: BALANCE:
This strategy monitors the amount of difficulty 1 shares solved for each pool This strategy monitors the amount of difficulty 1 shares solved for each pool

1
api.c
View File

@ -2661,6 +2661,7 @@ static void poolquota(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
} }
pool->quota = quota; pool->quota = quota;
adjust_quota_gcd();
message(io_data, MSG_SETQUOTA, quota, pool->rpc_url, isjson); message(io_data, MSG_SETQUOTA, quota, pool->rpc_url, isjson);
} }

View File

@ -100,6 +100,7 @@ int opt_scantime = -1;
int opt_expiry = 120; int opt_expiry = 120;
static const bool opt_time = true; static const bool opt_time = true;
unsigned long long global_hashrate; unsigned long long global_hashrate;
unsigned long global_quota_gcd = 1;
#if defined(HAVE_OPENCL) || defined(USE_USBUTILS) #if defined(HAVE_OPENCL) || defined(USE_USBUTILS)
int nDevs; int nDevs;
@ -488,6 +489,47 @@ static char *getwork_req = "{\"method\": \"getwork\", \"params\": [], \"id\":0}\
static char *gbt_req = "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"]}]}\n"; static char *gbt_req = "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"]}]}\n";
/* Adjust all the pools' quota to the greatest common denominator after a pool
* has been added or the quotas changed. */
void adjust_quota_gcd(void)
{
unsigned long gcd, lowest_quota = ~0UL, quota;
struct pool *pool;
int i;
for (i = 0; i < total_pools; i++) {
pool = pools[i];
quota = pool->quota;
if (!quota)
continue;
if (quota < lowest_quota)
lowest_quota = quota;
}
if (likely(lowest_quota < ~0UL)) {
gcd = lowest_quota;
for (i = 0; i < total_pools; i++) {
pool = pools[i];
quota = pool->quota;
if (!quota)
continue;
while (quota % gcd)
gcd--;
}
} else
gcd = 1;
for (i = 0; i < total_pools; i++) {
pool = pools[i];
pool->quota_used *= global_quota_gcd;
pool->quota_used /= gcd;
pool->quota_gcd = pool->quota / gcd;
}
global_quota_gcd = gcd;
applog(LOG_DEBUG, "Global quota greatest common denominator set to %lu", gcd);
}
/* Return value is ignored if not called from add_pool_details */ /* Return value is ignored if not called from add_pool_details */
struct pool *add_pool(void) struct pool *add_pool(void)
{ {
@ -513,6 +555,7 @@ struct pool *add_pool(void)
pool->rpc_req = getwork_req; pool->rpc_req = getwork_req;
pool->rpc_proxy = NULL; pool->rpc_proxy = NULL;
pool->quota = 1; pool->quota = 1;
adjust_quota_gcd();
return pool; return pool;
} }
@ -759,6 +802,7 @@ static char *set_quota(char *arg)
setup_url(pool, url); setup_url(pool, url);
pool->quota = quota; pool->quota = quota;
applog(LOG_INFO, "Setting pool %d to quota %d", pool->pool_no, pool->quota); applog(LOG_INFO, "Setting pool %d to quota %d", pool->pool_no, pool->quota);
adjust_quota_gcd();
return NULL; return NULL;
} }
@ -2840,16 +2884,16 @@ static inline struct pool *select_pool(bool lagging)
tested = 0; tested = 0;
while (!pool && tested++ < total_pools) { while (!pool && tested++ < total_pools) {
pool = pools[rotating_pool]; pool = pools[rotating_pool];
if (pool->quota_used++ >= pool->quota) { if (pool->quota_used++ >= pool->quota_gcd) {
pool->quota_used = 0; pool->quota_used = 0;
pool = NULL; pool = NULL;
} else { } else {
if (!pool_unworkable(pool)) if (!pool_unworkable(pool))
break; break;
/* Failover-only flag for load-balance means distribute /* Failover-only flag for load-balance means distribute
* unused quota to pool 0. */ * unused quota to priority pool 0. */
if (opt_fail_only) if (opt_fail_only)
pools[0]->quota++; priority_pool(0)->quota_used--;
} }
pool = NULL; pool = NULL;
if (++rotating_pool >= total_pools) if (++rotating_pool >= total_pools)
@ -4547,6 +4591,7 @@ retry:
goto retry; goto retry;
} }
pool->quota = selected; pool->quota = selected;
adjust_quota_gcd();
goto updated; goto updated;
} else if (!strncasecmp(&input, "f", 1)) { } else if (!strncasecmp(&input, "f", 1)) {
opt_fail_only ^= true; opt_fail_only ^= true;

View File

@ -973,6 +973,7 @@ extern int enabled_pools;
extern void get_intrange(char *arg, int *val1, int *val2); extern void get_intrange(char *arg, int *val1, int *val2);
extern bool detect_stratum(struct pool *pool, char *url); extern bool detect_stratum(struct pool *pool, char *url);
extern void print_summary(void); extern void print_summary(void);
extern void adjust_quota_gcd(void);
extern struct pool *add_pool(void); extern struct pool *add_pool(void);
extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass); extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
@ -1121,6 +1122,7 @@ struct pool {
int diff1; int diff1;
char diff[8]; char diff[8];
int quota; int quota;
int quota_gcd;
int quota_used; int quota_used;
double diff_accepted; double diff_accepted;