From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 1 Oct 2018 13:31:51 +0300 From: Vladimir Davydov Subject: Re: [PATCH v2 02/11] vinyl: factor load regulator out of quota Message-ID: <20181001103151.rdlqflcn7sp7vxky@esperanza> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: On Fri, Sep 28, 2018 at 08:40:00PM +0300, Vladimir Davydov wrote: > +static void > +vy_regulator_update_write_rate(struct vy_regulator *regulator) > +{ > + size_t used_curr = regulator->quota->used; > + size_t used_last = regulator->used_last; > + > + /* > + * Memory can be dumped between two subsequent timer > + * callback invocations, in which case memory usage > + * will decrease. Ignore such observations - it's not > + * a big deal, because dump is a rare event. > + */ > + if (used_curr < used_last) > + return; There's a bug here: we must update regulator->used_last in this case, otherwise we may stop updating the rate at all if used_last happens to be close to the limit. The fix is below. I updated the commit on the branch. > + > + size_t rate_avg = regulator->write_rate; > + size_t rate_curr = (used_curr - used_last) / VY_REGULATOR_TIMER_PERIOD; > + > + double weight = 1 - exp(-VY_REGULATOR_TIMER_PERIOD / > + VY_WRITE_RATE_AVG_WIN); > + rate_avg = (1 - weight) * rate_avg + weight * rate_curr; > + > + regulator->write_rate = rate_avg; > + regulator->used_last = used_curr; > +} diff --git a/src/box/vy_regulator.c b/src/box/vy_regulator.c index da35cc74..0d633abe 100644 --- a/src/box/vy_regulator.c +++ b/src/box/vy_regulator.c @@ -108,8 +108,10 @@ vy_regulator_update_write_rate(struct vy_regulator *regulator) * will decrease. Ignore such observations - it's not * a big deal, because dump is a rare event. */ - if (used_curr < used_last) + if (used_curr < used_last) { + regulator->used_last = used_curr; return; + } size_t rate_avg = regulator->write_rate; size_t rate_curr = (used_curr - used_last) / VY_REGULATOR_TIMER_PERIOD;