From: "Jim Schutt" <jaschut@sandia.gov>
To: Gregory Farnum <gregory.farnum@dreamhost.com>
Cc: ceph-devel@vger.kernel.org
Subject: Re: [RFC PATCH 3/6] common/Throttle: throttle in FIFO order
Date: Thu, 2 Feb 2012 11:31:05 -0700 [thread overview]
Message-ID: <4F2AD669.4080703@sandia.gov> (raw)
In-Reply-To: <CAF3hT9ABvoTmmA7+6KQ_rBJZdqH44nGQL+fLAXCdkYR1pbRqOQ@mail.gmail.com>
On 02/02/2012 10:53 AM, Gregory Farnum wrote:
> I went to merge this but then had a question on part of it (below).
>
> On Wed, Feb 1, 2012 at 7:54 AM, Jim Schutt<jaschut@sandia.gov> wrote:
>> Under heavy write load from many clients, many reader threads will
>> be waiting in the policy throttler, all on a single condition variable.
>> When a wakeup is signalled, any of those threads may receive the
>> signal. This increases the variance in the message processing
>> latency, and in extreme cases can significantly delay a message.
>>
>> This patch causes threads to exit a throttler in the same order
>> they entered.
>>
>> Signed-off-by: Jim Schutt<jaschut@sandia.gov>
>> ---
>> src/common/Throttle.h | 42 ++++++++++++++++++++++++++++--------------
>> 1 files changed, 28 insertions(+), 14 deletions(-)
>>
>> diff --git a/src/common/Throttle.h b/src/common/Throttle.h
>> index 10560bf..ca72060 100644
>> --- a/src/common/Throttle.h
>> +++ b/src/common/Throttle.h
>> @@ -3,23 +3,31 @@
>>
>> #include "Mutex.h"
>> #include "Cond.h"
>> +#include<list>
>>
>> class Throttle {
>> - int64_t count, max, waiting;
>> + int64_t count, max;
>> uint64_t sseq, wseq;
>> Mutex lock;
>> - Cond cond;
>> + list<Cond*> cond;
>>
>> public:
>> - Throttle(int64_t m = 0) : count(0), max(m), waiting(0), sseq(0), wseq(0),
>> + Throttle(int64_t m = 0) : count(0), max(m), sseq(0), wseq(0),
>> lock("Throttle::lock") {
>> assert(m>= 0);
>> }
>> + ~Throttle() {
>> + while (!cond.empty()) {
>> + Cond *cv = cond.front();
>> + delete cv;
>> + cond.pop_front();
>> + }
>> + }
>>
>> private:
>> void _reset_max(int64_t m) {
>> - if (m< max)
>> - cond.SignalOne();
>> + if (m< max&& !cond.empty())
>> + cond.front()->SignalOne();
>> max = m;
>> }
>> bool _should_wait(int64_t c) {
>> @@ -28,19 +36,24 @@ private:
>> ((c< max&& count + c> max) || // normally stay under max
>> (c>= max&& count> max)); // except for large c
>> }
>> +
>> bool _wait(int64_t c) {
>> bool waited = false;
>> - if (_should_wait(c)) {
>> - waiting += c;
>> + if (_should_wait(c) || !cond.empty()) { // always wait behind other waiters.
>> + Cond *cv = new Cond;
>> + cond.push_back(cv);
>> do {
>> + if (cv != cond.front())
>> + cond.front()->SignalOne(); // wake up the oldest.
>
> What's this extra wakeup for? Unless I'm missing something it's always
> going to be gratuitous. :/
I think it was a poorly thought-out attempt at
defensive programming. Now that I'm thinking about
it harder, I agree it is gratuitous.
Thanks -- Jim
>
>> waited = true;
>> - cond.Wait(lock);
>> - } while (_should_wait(c));
>> - waiting -= c;
>> + cv->Wait(lock);
>> + } while (_should_wait(c) || cv != cond.front());
>> + delete cv;
>> + cond.pop_front();
>>
>> // wake up the next guy
>> - if (waiting)
>> - cond.SignalOne();
>> + if (!cond.empty())
>> + cond.front()->SignalOne();
>> }
>> return waited;
>> }
>> @@ -101,7 +114,7 @@ public:
>> bool get_or_fail(int64_t c = 1) {
>> assert (c>= 0);
>> Mutex::Locker l(lock);
>> - if (_should_wait(c)) return false;
>> + if (_should_wait(c) || !cond.empty()) return false;
>> count += c;
>> return true;
>> }
>> @@ -110,7 +123,8 @@ public:
>> assert(c>= 0);
>> Mutex::Locker l(lock);
>> if (c) {
>> - cond.SignalOne();
>> + if (!cond.empty())
>> + cond.front()->SignalOne();
>> count -= c;
>> assert(count>= 0); //if count goes negative, we failed somewhere!
>> }
>> --
>> 1.7.1
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
next prev parent reply other threads:[~2012-02-02 18:31 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-01 15:54 [RFC PATCH 0/6] Understanding delays due to throttling under very heavy write load Jim Schutt
2012-02-01 15:54 ` [RFC PATCH 1/6] msgr: print message sequence number and tid when receiving message envelope Jim Schutt
2012-02-01 15:54 ` [RFC PATCH 2/6] common/Throttle: track sleep/wake sequences in Throttle, report them for policy throttler Jim Schutt
2012-02-01 15:54 ` [RFC PATCH 3/6] common/Throttle: throttle in FIFO order Jim Schutt
2012-02-02 17:53 ` Gregory Farnum
2012-02-02 18:31 ` Jim Schutt [this message]
2012-02-02 19:01 ` Gregory Farnum
2012-02-01 15:54 ` [RFC PATCH 4/6] common/Throttle: FIFO throttler doesn't need to signal waiters when max changes Jim Schutt
2012-02-01 15:54 ` [RFC PATCH 5/6] common/Throttle: make get() report number of waiters on entry/exit Jim Schutt
2012-02-01 15:54 ` [RFC PATCH 6/6] msg: log Message interactions with throttler Jim Schutt
2012-02-01 22:33 ` [RFC PATCH 0/6] Understanding delays due to throttling under very heavy write load Gregory Farnum
2012-02-02 15:38 ` Jim Schutt
[not found] ` <4F29CDAA.408@sandia.gov>
[not found] ` <CAF3hT9BZEP_FWS=qt8ivA++aDpPGGFzuD_PtMcvDRS2aDEN+hw@mail.gmail.com>
[not found] ` <4F2AABF5.6050803@sandia.gov>
2012-02-02 17:52 ` Gregory Farnum
2012-02-02 19:06 ` [EXTERNAL] " Jim Schutt
2012-02-02 19:15 ` Sage Weil
2012-02-02 19:33 ` Jim Schutt
2012-02-02 19:32 ` Gregory Farnum
2012-02-02 20:22 ` Jim Schutt
2012-02-02 20:31 ` Jim Schutt
2012-02-03 0:28 ` [EXTERNAL] " Gregory Farnum
2012-02-03 16:17 ` Jim Schutt
2012-02-03 17:06 ` Gregory Farnum
2012-02-03 23:33 ` Jim Schutt
[not found] ` <CAC-hyiHSNv_VgLcyVCrJ66HxTGFNBONrmmBddJk5326dLTKgkw@mail.gmail.com>
2012-02-04 0:04 ` Yehuda Sadeh Weinraub
2012-02-06 16:20 ` Jim Schutt
2012-02-06 17:22 ` Yehuda Sadeh Weinraub
2012-02-06 18:20 ` Jim Schutt
2012-02-06 18:35 ` Gregory Farnum
2012-02-09 20:53 ` Jim Schutt
2012-02-09 22:40 ` sridhar basam
2012-02-09 23:15 ` Jim Schutt
2012-02-10 0:34 ` Tommi Virtanen
2012-02-10 1:26 ` sridhar basam
2012-02-10 15:32 ` [EXTERNAL] " Jim Schutt
2012-02-10 17:13 ` sridhar basam
2012-02-10 23:09 ` Jim Schutt
2012-02-11 0:05 ` sridhar basam
2012-02-13 15:26 ` Jim Schutt
2012-02-03 17:07 ` Sage Weil
2012-02-24 15:38 ` Jim Schutt
2012-02-24 18:31 ` Tommi Virtanen
2012-02-24 18:38 ` Tommi Virtanen
2013-02-21 0:12 ` Sage Weil
2013-02-26 19:16 ` Jim Schutt
2013-02-26 19:36 ` Sage Weil
2013-02-28 19:37 ` Jim Schutt
2013-02-28 21:06 ` Sage Weil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F2AD669.4080703@sandia.gov \
--to=jaschut@sandia.gov \
--cc=ceph-devel@vger.kernel.org \
--cc=gregory.farnum@dreamhost.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.