[PATCH v3 2/4] vinyl: remove extra quota check from vy_quota_use

Vladimir Davydov vdavydov.dev at gmail.com
Tue Feb 12 20:26:54 MSK 2019


Before waking up a fiber that is waiting for quota, we always first
check if it can actually consume it, see vy_quota_signal. Hence the
extra check in vy_quota_use is needed only to prevent spurious wakeups.
It doesn't seem to be wise to add such a check to a hot path as a
counter-mesaure to such an unlikely scenario. Let's remove it - after
all it isn't critical if a spuriously woken up fiber exceeds the limit.
---
 src/box/vy_quota.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/box/vy_quota.c b/src/box/vy_quota.c
index dc452adb..7d59e20d 100644
--- a/src/box/vy_quota.c
+++ b/src/box/vy_quota.c
@@ -294,27 +294,20 @@ vy_quota_use(struct vy_quota *q, enum vy_quota_consumer_type type,
 
 	/* Wait for quota. */
 	double wait_start = ev_monotonic_now(loop());
-	double deadline = wait_start + timeout;
-
 	struct vy_quota_wait_node wait_node = {
 		.fiber = fiber(),
 		.size = size,
 		.ticket = ++q->wait_ticket,
 	};
 	rlist_add_tail_entry(&q->wait_queue[type], &wait_node, in_wait_queue);
-
-	do {
-		double now = ev_monotonic_now(loop());
-		fiber_yield_timeout(deadline - now);
-		if (now >= deadline) {
-			rlist_del_entry(&wait_node, in_wait_queue);
-			diag_set(ClientError, ER_VY_QUOTA_TIMEOUT);
-			return -1;
-		}
-	} while (!vy_quota_may_use(q, type, size));
-
+	bool timed_out = fiber_yield_timeout(timeout);
 	rlist_del_entry(&wait_node, in_wait_queue);
 
+	if (timed_out) {
+		diag_set(ClientError, ER_VY_QUOTA_TIMEOUT);
+		return -1;
+	}
+
 	double wait_time = ev_monotonic_now(loop()) - wait_start;
 	if (wait_time > q->too_long_threshold) {
 		say_warn_ratelimited("waited for %zu bytes of vinyl memory "
-- 
2.11.0




More information about the Tarantool-patches mailing list