36 #define NCBI_USE_ERRCODE_X Connect_LBSM
49 assert(0.0 <= pref && pref <= 1.0);
50 assert(0.0 < gap && gap <= 1.0);
54 spread = 14.0/((double)
n + 12.0);
55 if (gap >= spread/((
double)
n))
58 return 2.0/spread * gap * pref;
65 double total = 0.0, access = 0.0, point = 0.0, p = 0.0, status = 0.0;
72 assert(iter && get_candidate);
78 if (!(cand = get_candidate(data,
n)))
84 if (latch || (!fixed && !iter->
host &&
info->coef < 0.0
90 if (iter->
pref ||
info->coef <= 0.0) {
92 if (access < status && (iter->
pref ||
info->coef < 0.0)) {
94 point = total + status;
109 (
"%d: %s %s\tR=%lf\tS=%lf\tT=%lf\tA=%lf\tP=%lf",
110 (
int)
n, name, addr,
info->rate, status, total,
117 if (fixed && iter->
pref < 0.0) {
119 cand = get_candidate(data,
i);
122 if (iter->
pref > 0.0) {
123 if (point > 0.0 && access > 0.0 && total != access) {
127 (
"(P=%lf,\tA=%lf,\tT=%lf,\tA/T=%lf,\tN=%d) "
129 iter->
pref, access, total, access/total,
133 p = total * (1.0 - p) / (total - access);
134 for (
i = 0;
i <
n; ++
i) {
135 cand = get_candidate(data,
i);
136 if (point <= cand->status)
143 for (
i = 0;
i <
n; ++
i) {
145 cand = get_candidate(data,
i);
147 p = cand->
status - status;
152 (
"%d: %s %s\tS=%lf\t%.2lf%%",
154 p, p / total * 100.0));
165 || access * (
double)(
n - 1) < p * 0.01 * (total - access)) {
166 point = (total * rand()) / (
double) RAND_MAX;
173 for (
i = 0;
i <
n; ++
i) {
174 cand = get_candidate(data,
i);
176 if (point <= cand->status) {
177 status = cand->
status - total;
size_t SOCK_HostPortToString(unsigned int host, unsigned short port, char *buf, size_t bufsize)
Print numeric string "host:port" into a buffer provided, not to exceed 'bufsize' bytes (including the...
static double s_Preference(double pref, double gap, size_t n)
size_t LB_Select(SERV_ITER iter, void *data, FGetCandidate get_candidate, double bonus)
SLB_Candidate *(* FGetCandidate)(void *data, size_t n)
#define CORE_LOGF(level, fmt_args)
const char * SERV_NameOfInfo(const SSERV_Info *info)