Skip to content

Commit

Permalink
In-progress
Browse files Browse the repository at this point in the history
- `dnsperf`: Do in-progress check before rate and in-flight limiting
  • Loading branch information
jelu committed Aug 22, 2023
1 parent 059619d commit bbc48db
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions src/dnsperf.c
Expand Up @@ -900,6 +900,16 @@ do_send(void* arg)
now = perf_get_time();
}

/* Some sock might still be sending, try flush all of them */
if (any_inprogress) {
any_inprogress = 0;
for (i = 0; i < tinfo->nsocks; i++) {
if (!perf_net_sockready(tinfo->socks[i], threadpipe[0], TIMEOUT_CHECK_TIME)) {
any_inprogress = 1;
}
}
}

/* Rate limiting */
if (tinfo->max_qps > 0) {
/* the 1 second time slice where q_sent is calculated over */
Expand All @@ -910,58 +920,54 @@ do_send(void* arg)
}
/* limit QPS over the 1 second slice */
if (q_sent >= tinfo->max_qps) {
wait_us = q_slice - now;
if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) {
wait_us -= config->qps_threshold_wait;
struct timespec ts = { 0, 0 };
if (wait_us >= MILLION) {
ts.tv_sec = wait_us / MILLION;
ts.tv_nsec = (wait_us % MILLION) * 1000;
} else {
ts.tv_sec = 0;
ts.tv_nsec = wait_us * 1000;
if (!any_inprogress) { // only if nothing is in-progress
wait_us = q_slice - now;
if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) {
wait_us -= config->qps_threshold_wait;
struct timespec ts = { 0, 0 };
if (wait_us >= MILLION) {
ts.tv_sec = wait_us / MILLION;
ts.tv_nsec = (wait_us % MILLION) * 1000;
} else {
ts.tv_sec = 0;
ts.tv_nsec = wait_us * 1000;
}
nanosleep(&ts, NULL);
}
nanosleep(&ts, NULL);
}
now = perf_get_time();
continue;
}
/* handle stepping to the next window to send a query on */
if (req_time > now) {
wait_us = req_time - now;
if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) {
wait_us -= config->qps_threshold_wait;
struct timespec ts = { 0, 0 };
if (wait_us >= MILLION) {
ts.tv_sec = wait_us / MILLION;
ts.tv_nsec = (wait_us % MILLION) * 1000;
} else {
ts.tv_sec = 0;
ts.tv_nsec = wait_us * 1000;
if (!any_inprogress) { // only if nothing is in-progress
wait_us = req_time - now;
if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) {
wait_us -= config->qps_threshold_wait;
struct timespec ts = { 0, 0 };
if (wait_us >= MILLION) {
ts.tv_sec = wait_us / MILLION;
ts.tv_nsec = (wait_us % MILLION) * 1000;
} else {
ts.tv_sec = 0;
ts.tv_nsec = wait_us * 1000;
}
nanosleep(&ts, NULL);
}
nanosleep(&ts, NULL);
}
now = perf_get_time();
continue;
}
req_time += q_step;
}

/* Some sock might still be sending, try flush all of them */
if (any_inprogress) {
any_inprogress = 0;
for (i = 0; i < tinfo->nsocks; i++) {
if (!perf_net_sockready(tinfo->socks[i], threadpipe[0], TIMEOUT_CHECK_TIME)) {
any_inprogress = 1;
}
}
}

PERF_LOCK(&tinfo->lock);

/* Limit in-flight queries */
if (num_outstanding(stats) >= tinfo->max_outstanding) {
PERF_TIMEDWAIT(&tinfo->cond, &tinfo->lock, &times->stop_time_ns, NULL);
if (!any_inprogress) { // only if nothing is in-progress
PERF_TIMEDWAIT(&tinfo->cond, &tinfo->lock, &times->stop_time_ns, NULL);
}
PERF_UNLOCK(&tinfo->lock);
now = perf_get_time();
continue;
Expand Down

0 comments on commit bbc48db

Please sign in to comment.