Increase accuracy of percentages for connection distribution.

This commit is contained in:
Mark Riddoch
2014-06-30 16:16:27 +01:00
parent a25b757134
commit 6c1960e53b

View File

@ -238,7 +238,7 @@ char *weightby;
} }
inst->servers[n]->server = server; inst->servers[n]->server = server;
inst->servers[n]->current_connection_count = 0; inst->servers[n]->current_connection_count = 0;
inst->servers[n]->weight = 100; inst->servers[n]->weight = 1000;
n++; n++;
} }
inst->servers[n] = NULL; inst->servers[n] = NULL;
@ -267,7 +267,9 @@ char *weightby;
int perc; int perc;
backend = inst->servers[n]; backend = inst->servers[n];
perc = (atoi(serverGetParameter(backend->server, perc = (atoi(serverGetParameter(backend->server,
weightby)) * 100) / total; weightby)) * 1000) / total;
if (perc == 0)
perc = 1;
backend->weight = perc; backend->weight = perc;
if (perc == 0) if (perc == 0)
{ {
@ -444,18 +446,18 @@ BACKEND *master_host = NULL;
candidate = inst->servers[i]; candidate = inst->servers[i];
} }
else if ((inst->servers[i]->current_connection_count else if ((inst->servers[i]->current_connection_count
* 100) / inst->servers[i]->weight < * 1000) / inst->servers[i]->weight <
(candidate->current_connection_count * (candidate->current_connection_count *
100) / candidate->weight) 1000) / candidate->weight)
{ {
/* This running server has fewer /* This running server has fewer
connections, set it as a new candidate */ connections, set it as a new candidate */
candidate = inst->servers[i]; candidate = inst->servers[i];
} }
else if ((inst->servers[i]->current_connection_count else if ((inst->servers[i]->current_connection_count
* 100) / inst->servers[i]->weight == * 1000) / inst->servers[i]->weight ==
(candidate->current_connection_count * (candidate->current_connection_count *
100) / candidate->weight && 1000) / candidate->weight &&
inst->servers[i]->server->stats.n_connections < inst->servers[i]->server->stats.n_connections <
candidate->server->stats.n_connections) candidate->server->stats.n_connections)
{ {
@ -747,9 +749,9 @@ char *weightby;
for (i = 0; router_inst->servers[i]; i++) for (i = 0; router_inst->servers[i]; i++)
{ {
backend = router_inst->servers[i]; backend = router_inst->servers[i];
dcb_printf(dcb, "\t\t%-20s %3d%% %d\n", dcb_printf(dcb, "\t\t%-20s %3.1f%% %d\n",
backend->server->unique_name, backend->server->unique_name,
backend->weight, (float)backend->weight / 10,
backend->current_connection_count); backend->current_connection_count);
} }