From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 09/18] vinyl: cache dump bandwidth for timer invocation Date: Thu, 16 Aug 2018 19:12:03 +0300 Message-Id: <96f47fd882aa68aa315ce90d77e5c40ca471ffdf.1534432819.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: We don't need to compute a percentile of dump bandwidth histogram on each invocation of quota timer callback, because it may only be updated on dump completion. Let's cache it. Currently, it isn't that important, because the timer period is set to 1 second. However, once we start using the timer for throttling, we'll have to make it run more often and so caching the dump bandwidth value will make sense. --- src/box/vinyl.c | 2 +- src/box/vy_quota.c | 26 ++++++++++++++------------ src/box/vy_quota.h | 6 ++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index a07f661f..8d315e87 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -255,7 +255,7 @@ vy_info_append_quota(struct vy_env *env, struct info_handler *h) info_append_int(h, "limit", q->limit); info_append_int(h, "watermark", q->watermark); info_append_int(h, "use_rate", q->use_rate); - info_append_int(h, "dump_bandwidth", vy_quota_dump_bandwidth(q)); + info_append_int(h, "dump_bandwidth", q->dump_bw); info_table_end(h); } diff --git a/src/box/vy_quota.c b/src/box/vy_quota.c index bcdc4c44..dfe336c6 100644 --- a/src/box/vy_quota.c +++ b/src/box/vy_quota.c @@ -57,6 +57,12 @@ enum { }; /** + * Histogram percentile used for estimating dump bandwidth. + * For details see the comment to vy_quota::dump_bw_hist. + */ +enum { VY_DUMP_BANDWIDTH_PCT = 10 }; + +/** * Wake up the next fiber in the line waiting for quota * provided quota is available. */ @@ -95,9 +101,8 @@ vy_quota_timer_cb(ev_loop *loop, ev_timer *timer, int events) * ----------------- = -------------- * use_rate dump_bandwidth */ - size_t dump_bandwidth = vy_quota_dump_bandwidth(q); - q->watermark = ((double)q->limit * dump_bandwidth / - (dump_bandwidth + q->use_rate + 1)); + q->watermark = ((double)q->limit * q->dump_bw / + (q->dump_bw + q->use_rate + 1)); if (q->used >= q->watermark) q->quota_exceeded_cb(q); } @@ -128,7 +133,8 @@ vy_quota_create(struct vy_quota *q, vy_quota_exceeded_f quota_exceeded_cb) * Until we dump anything, assume bandwidth to be 10 MB/s, * which should be fine for initial guess. */ - histogram_collect(q->dump_bw_hist, 10 * MB); + q->dump_bw = 10 * MB; + histogram_collect(q->dump_bw_hist, q->dump_bw); q->limit = SIZE_MAX; q->watermark = SIZE_MAX; @@ -154,13 +160,6 @@ vy_quota_destroy(struct vy_quota *q) fiber_cond_destroy(&q->cond); } -size_t -vy_quota_dump_bandwidth(struct vy_quota *q) -{ - /* See comment to vy_quota::dump_bw_hist. */ - return histogram_percentile(q->dump_bw_hist, 10); -} - void vy_quota_set_limit(struct vy_quota *q, size_t limit) { @@ -187,8 +186,11 @@ vy_quota_dump(struct vy_quota *q, size_t size, double duration) vy_quota_signal(q); /* Account dump bandwidth. */ - if (duration > 0) + if (duration > 0) { histogram_collect(q->dump_bw_hist, size / duration); + q->dump_bw = histogram_percentile(q->dump_bw_hist, + VY_DUMP_BANDWIDTH_PCT); + } } int diff --git a/src/box/vy_quota.h b/src/box/vy_quota.h index 0a7427f0..33672a39 100644 --- a/src/box/vy_quota.h +++ b/src/box/vy_quota.h @@ -91,6 +91,8 @@ struct vy_quota { * moving average of use_curr. */ size_t use_rate; + /** Current dump bandwidth estimate. */ + size_t dump_bw; /** * Dump bandwidth is needed for calculating the quota watermark. * The higher the bandwidth, the later we can start dumping w/o @@ -111,10 +113,6 @@ vy_quota_create(struct vy_quota *q, vy_quota_exceeded_f quota_exceeded_cb); void vy_quota_destroy(struct vy_quota *q); -/** Return quota dump bandwidth. */ -size_t -vy_quota_dump_bandwidth(struct vy_quota *q); - /** * Set memory limit. If current memory usage exceeds * the new limit, invoke the callback. -- 2.11.0