<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.  <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/celery/celery/commit/90fe53f901cf2e71c570fa639aa9b39ad228fadd/hovercard" href="https://github.com/celery/celery/commit/90fe53f901cf2e71c570fa639aa9b39ad228fadd"><tt>90fe53f</tt></a></p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> This has already been asked to the <a href="https://groups.google.com/forum/#!forum/celery-users" rel="nofollow">discussion group</a> first.</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the relevant section in the<br>
<a href="http://docs.celeryproject.org/en/latest/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</p>
</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>:</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:4.4.0 (cliffs) kombu:4.6.7 py:3.7.6
            billiard:3.6.1.0 redis:3.3.11
platform -&gt; system:Linux arch:64bit
            kernel version:5.4.13-3-MANJARO imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://redis:6379/2"><pre class="notranslate"><code class="notranslate">software -&gt; celery:4.4.0 (cliffs) kombu:4.6.7 py:3.7.6
            billiard:3.6.1.0 redis:3.3.11
platform -&gt; system:Linux arch:64bit
            kernel version:5.4.13-3-MANJARO imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://redis:6379/2
</code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Celery Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Kombu Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: N/A or Unknown</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="amqp==2.5.2
apipkg==1.5
attrs==19.3.0
backcall==0.1.0
billiard==3.6.1.0
blinker==1.4
boltons==19.3.0
cachetools==4.0.0
celery==4.4.0
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
Click==7.0
cryptography==2.8
decorator==4.4.1
defusedxml==0.6.0
dnspython==1.16.0
dotted==0.1.8
elasticsearch==7.1.0
elasticsearch-dsl==7.1.0
execnet==1.7.1
Flask==1.1.1
Flask-Caching==1.4.0
Flask-Cors==3.0.8
Flask-Limiter==1.1.0
Flask-Login==0.4.1
flask-mongoengine==0.9.5
flask-shell-ipython==0.4.1
Flask-WTF==0.14.2
gevent==1.4.0
google-api-core==1.15.0
google-auth==1.10.0
google-cloud-core==1.1.0
google-cloud-pubsub==1.1.0
google-cloud-storage==1.23.0
google-resumable-media==0.5.0
googleapis-common-protos==1.6.0
greenlet==0.4.15
grpc-google-iam-v1==0.12.3
grpcio==1.26.0
httpagentparser==1.9.0
httplib2==0.15.0
idna==2.8
importlib-metadata==1.4.0
ipython==7.10.2
ipython-genutils==0.2.0
itsdangerous==1.1.0
jedi==0.15.2
Jinja2==2.10.3
kombu==4.6.7
libthumbor==1.3.2
limits==1.3
MarkupSafe==1.1.1
marshmallow==3.3.0
mixpanel==4.5.0
mmh3==2.5.1
mongoengine==0.18.2
more-itertools==8.1.0
multidict==4.7.4
ndg-httpsclient==0.5.1
newrelic==5.4.1.134
nexmo==2.4.0
oauth2client==4.1.3
oauthlib==3.1.0
packaging==20.0
parso==0.5.2
pexpect==4.7.0
phonenumbers==8.11.1
pickleshare==0.7.5
Pillow-SIMD==6.0.0.post0
pluggy==0.13.1
prompt-toolkit==3.0.2
protobuf==3.9.0
ptyprocess==0.6.0
pusher==2.1.4
py==1.8.1
py-cpuinfo==5.0.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pybase62==0.4.3
pycparser==2.19
Pygments==2.5.2
PyJWT==1.7.1
pymongo==3.10.0
PyNaCl==1.3.0
pyOpenSSL==19.1.0
pyparsing==2.4.6
pytelegraf==0.3.3
pytest==5.3.2
pytest-benchmark==3.2.3
pytest-forked==1.1.3
pytest-mock==1.13.0
pytest-sugar==0.9.2
pytest-xdist==1.31.0
python-dateutil==2.8.1
python-rapidjson==0.9.1
python3-openid==3.1.0
pytz==2019.3
PyYAML==5.2
redis==3.3.11
requests==2.22.0
requests-oauthlib==1.3.0
rsa==4.0
semantic-version==2.8.3
sentry-sdk==0.13.5
six==1.13.0
social-auth-app-flask==1.0.0
social-auth-core==3.2.0
social-auth-storage-mongoengine==1.0.1
termcolor==1.1.0
traitlets==4.3.3
twilio==6.35.1
urllib3==1.25.7
uWSGI==2.0.18
vine==1.3.0
wcwidth==0.1.8
webargs==5.5.2
Werkzeug==0.15.5
WTForms==2.2.1
yarl==1.4.2
zipp==0.6.0"><pre class="notranslate"><code class="notranslate">amqp==2.5.2
apipkg==1.5
attrs==19.3.0
backcall==0.1.0
billiard==3.6.1.0
blinker==1.4
boltons==19.3.0
cachetools==4.0.0
celery==4.4.0
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
Click==7.0
cryptography==2.8
decorator==4.4.1
defusedxml==0.6.0
dnspython==1.16.0
dotted==0.1.8
elasticsearch==7.1.0
elasticsearch-dsl==7.1.0
execnet==1.7.1
Flask==1.1.1
Flask-Caching==1.4.0
Flask-Cors==3.0.8
Flask-Limiter==1.1.0
Flask-Login==0.4.1
flask-mongoengine==0.9.5
flask-shell-ipython==0.4.1
Flask-WTF==0.14.2
gevent==1.4.0
google-api-core==1.15.0
google-auth==1.10.0
google-cloud-core==1.1.0
google-cloud-pubsub==1.1.0
google-cloud-storage==1.23.0
google-resumable-media==0.5.0
googleapis-common-protos==1.6.0
greenlet==0.4.15
grpc-google-iam-v1==0.12.3
grpcio==1.26.0
httpagentparser==1.9.0
httplib2==0.15.0
idna==2.8
importlib-metadata==1.4.0
ipython==7.10.2
ipython-genutils==0.2.0
itsdangerous==1.1.0
jedi==0.15.2
Jinja2==2.10.3
kombu==4.6.7
libthumbor==1.3.2
limits==1.3
MarkupSafe==1.1.1
marshmallow==3.3.0
mixpanel==4.5.0
mmh3==2.5.1
mongoengine==0.18.2
more-itertools==8.1.0
multidict==4.7.4
ndg-httpsclient==0.5.1
newrelic==5.4.1.134
nexmo==2.4.0
oauth2client==4.1.3
oauthlib==3.1.0
packaging==20.0
parso==0.5.2
pexpect==4.7.0
phonenumbers==8.11.1
pickleshare==0.7.5
Pillow-SIMD==6.0.0.post0
pluggy==0.13.1
prompt-toolkit==3.0.2
protobuf==3.9.0
ptyprocess==0.6.0
pusher==2.1.4
py==1.8.1
py-cpuinfo==5.0.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pybase62==0.4.3
pycparser==2.19
Pygments==2.5.2
PyJWT==1.7.1
pymongo==3.10.0
PyNaCl==1.3.0
pyOpenSSL==19.1.0
pyparsing==2.4.6
pytelegraf==0.3.3
pytest==5.3.2
pytest-benchmark==3.2.3
pytest-forked==1.1.3
pytest-mock==1.13.0
pytest-sugar==0.9.2
pytest-xdist==1.31.0
python-dateutil==2.8.1
python-rapidjson==0.9.1
python3-openid==3.1.0
pytz==2019.3
PyYAML==5.2
redis==3.3.11
requests==2.22.0
requests-oauthlib==1.3.0
rsa==4.0
semantic-version==2.8.3
sentry-sdk==0.13.5
six==1.13.0
social-auth-app-flask==1.0.0
social-auth-core==3.2.0
social-auth-storage-mongoengine==1.0.1
termcolor==1.1.0
traitlets==4.3.3
twilio==6.35.1
urllib3==1.25.7
uWSGI==2.0.18
vine==1.3.0
wcwidth==0.1.8
webargs==5.5.2
Werkzeug==0.15.5
WTForms==2.2.1
yarl==1.4.2
zipp==0.6.0
</code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
</p><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import time
from flask import Flask
from celery import Celery, group


app = Flask(__name__)
celery = Celery('app', broker='redis://redis:6379/1', backend='redis://redis:6379/2')


@celery.task
def debug():
    return


@app.route('/', methods={'GET', 'POST'})
def hello_world():
    task = group([
        debug.si() for i in range(10)
    ]).apply_async()

    start = time.perf_counter()
    task.get(timeout=5, interval=0.01)
    print('END', (time.perf_counter() - start) * 1000)
    return {}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">time</span>
<span class="pl-k">from</span> <span class="pl-s1">flask</span> <span class="pl-k">import</span> <span class="pl-v">Flask</span>
<span class="pl-k">from</span> <span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>, <span class="pl-s1">group</span>


<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Flask</span>(<span class="pl-s1">__name__</span>)
<span class="pl-s1">celery</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(<span class="pl-s">'app'</span>, <span class="pl-s1">broker</span><span class="pl-c1">=</span><span class="pl-s">'redis://redis:6379/1'</span>, <span class="pl-s1">backend</span><span class="pl-c1">=</span><span class="pl-s">'redis://redis:6379/2'</span>)


<span class="pl-en">@<span class="pl-s1">celery</span>.<span class="pl-s1">task</span></span>
<span class="pl-k">def</span> <span class="pl-en">debug</span>():
    <span class="pl-k">return</span>


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">route</span>(<span class="pl-s">'/'</span>, <span class="pl-s1">methods</span><span class="pl-c1">=</span>{<span class="pl-s">'GET'</span>, <span class="pl-s">'POST'</span>})</span>
<span class="pl-k">def</span> <span class="pl-en">hello_world</span>():
    <span class="pl-s1">task</span> <span class="pl-c1">=</span> <span class="pl-en">group</span>([
        <span class="pl-s1">debug</span>.<span class="pl-en">si</span>() <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">10</span>)
    ]).<span class="pl-en">apply_async</span>()

    <span class="pl-s1">start</span> <span class="pl-c1">=</span> <span class="pl-s1">time</span>.<span class="pl-en">perf_counter</span>()
    <span class="pl-s1">task</span>.<span class="pl-en">get</span>(<span class="pl-s1">timeout</span><span class="pl-c1">=</span><span class="pl-c1">5</span>, <span class="pl-s1">interval</span><span class="pl-c1">=</span><span class="pl-c1">0.01</span>)
    <span class="pl-en">print</span>(<span class="pl-s">'END'</span>, (<span class="pl-s1">time</span>.<span class="pl-en">perf_counter</span>() <span class="pl-c1">-</span> <span class="pl-s1">start</span>) <span class="pl-c1">*</span> <span class="pl-c1">1000</span>)
    <span class="pl-k">return</span> {}</pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">Scheduling noop tasks and setting <code class="notranslate">interval</code> should make the response time near the set <code class="notranslate">interval</code> in ideal clean environments.</p>
<p dir="auto">Example: Setting <code class="notranslate">task.get(interval=0.1)</code> with 5x noop tasks, I would expect near <code class="notranslate">100ms</code> response.</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">Regardless of the setting of <code class="notranslate">interval</code>, the response time is at least 500ms.</p>
<p dir="auto">The cause is that <code class="notranslate">interval</code> is not passed all the way to <code class="notranslate">get_many()</code> where it defaults to <code class="notranslate">500ms</code> which is where the minimum latency is comming from.<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/celery/celery/blob/cf829307991da3815e1f7b105e736d13dbc7a325/celery/result.py#L837-L840">celery/celery/result.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 837 to 840
      in
      <a data-pjax="true" class="commit-tease-sha" href="/celery/celery/commit/cf829307991da3815e1f7b105e736d13dbc7a325">cf82930</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L837" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="837"></td>
          <td id="LC837" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">def</span> <span class="pl-en">_iter_meta</span>(<span class="pl-s1">self</span>): </td>
        </tr>

        <tr class="border-0">
          <td id="L838" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="838"></td>
          <td id="LC838" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">return</span> (<span class="pl-s1">meta</span> <span class="pl-k">for</span> <span class="pl-s1">_</span>, <span class="pl-s1">meta</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">backend</span>.<span class="pl-en">get_many</span>( </td>
        </tr>

        <tr class="border-0">
          <td id="L839" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="839"></td>
          <td id="LC839" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         {<span class="pl-s1">r</span>.<span class="pl-s1">id</span> <span class="pl-k">for</span> <span class="pl-s1">r</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">results</span>}, <span class="pl-s1">max_iterations</span><span class="pl-c1">=</span><span class="pl-c1">1</span>, </td>
        </tr>

        <tr class="border-0">
          <td id="L840" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="840"></td>
          <td id="LC840" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     )) </td>
        </tr>
    </tbody></table>
  </div>
</div>
<br>
<div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/celery/celery/blob/dc03b6d342a8008d123c97cb889d19add485f8a2/celery/backends/base.py#L663-L666">celery/celery/backends/base.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 663 to 666
      in
      <a data-pjax="true" class="commit-tease-sha" href="/celery/celery/commit/dc03b6d342a8008d123c97cb889d19add485f8a2">dc03b6d</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L663" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="663"></td>
          <td id="LC663" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">def</span> <span class="pl-en">get_many</span>(<span class="pl-s1">self</span>, <span class="pl-s1">task_ids</span>, <span class="pl-s1">timeout</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">interval</span><span class="pl-c1">=</span><span class="pl-c1">0.5</span>, <span class="pl-s1">no_ack</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, </td>
        </tr>

        <tr class="border-0">
          <td id="L664" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="664"></td>
          <td id="LC664" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">              <span class="pl-s1">on_message</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">on_interval</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">max_iterations</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, </td>
        </tr>

        <tr class="border-0">
          <td id="L665" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="665"></td>
          <td id="LC665" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">              <span class="pl-v">READY_STATES</span><span class="pl-c1">=</span><span class="pl-s1">states</span>.<span class="pl-v">READY_STATES</span>): </td>
        </tr>

        <tr class="border-0">
          <td id="L666" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="666"></td>
          <td id="LC666" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-s1">interval</span> <span class="pl-c1">=</span> <span class="pl-c1">0.5</span> <span class="pl-k">if</span> <span class="pl-s1">interval</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span> <span class="pl-k">else</span> <span class="pl-s1">interval</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<h1 dir="auto">problem one: request be executed at the wrong time</h1>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    def _schedule_bucket_request(self, request, bucket, tokens):
        bucket.can_consume(tokens)
        bucket.add(request)
        pri = self._limit_order = (self._limit_order + 1) % 10
        hold = bucket.expected_time(tokens)
        self.timer.call_after(
            hold, self._on_bucket_wakeup, (bucket, tokens),
            priority=pri,
        )"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">_schedule_bucket_request</span>(<span class="pl-s1">self</span>, <span class="pl-s1">request</span>, <span class="pl-s1">bucket</span>, <span class="pl-s1">tokens</span>):
        <span class="pl-s1">bucket</span>.<span class="pl-en">can_consume</span>(<span class="pl-s1">tokens</span>)
        <span class="pl-s1">bucket</span>.<span class="pl-en">add</span>(<span class="pl-s1">request</span>)
        <span class="pl-s1">pri</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_limit_order</span> <span class="pl-c1">=</span> (<span class="pl-s1">self</span>.<span class="pl-s1">_limit_order</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>) <span class="pl-c1">%</span> <span class="pl-c1">10</span>
        <span class="pl-s1">hold</span> <span class="pl-c1">=</span> <span class="pl-s1">bucket</span>.<span class="pl-en">expected_time</span>(<span class="pl-s1">tokens</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">timer</span>.<span class="pl-en">call_after</span>(
            <span class="pl-s1">hold</span>, <span class="pl-s1">self</span>.<span class="pl-s1">_on_bucket_wakeup</span>, (<span class="pl-s1">bucket</span>, <span class="pl-s1">tokens</span>),
            <span class="pl-s1">priority</span><span class="pl-c1">=</span><span class="pl-s1">pri</span>,
        )</pre></div>
<h2 dir="auto">Actual behavior</h2>
<p dir="auto">If token bucket have enough token, <code class="notranslate">bucket.can_consume</code> will consume token, then compute the hold time and <strong>add timer</strong> to run it.</p>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">If the tokens is enough, the requests should be executed Immediate。<br>
PS: The bucket's capacity is set 1 by default, so the <code class="notranslate">hold time</code> will be tokens/fill_rate. If the fill_rate is very slow, i will wait so long time.</p>
<h1 dir="auto">problem two: may consume incorrect tokens</h1>
<h2 dir="auto">Actual behavior</h2>
<ul dir="auto">
<li><code class="notranslate">_schedule_bucket_request</code> will add request to bucket, <code class="notranslate">_on_bucket_wakeup</code>、<code class="notranslate">_schedule_oldest_bucket_request</code> will pop request from bucket.</li>
<li><code class="notranslate">bucket.add</code> add the request to right, <code class="notranslate">bucket.pop</code> pop the request from left</li>
<li><strong>the request is NOT bind with tokens</strong>, so this can cause: "execute request with incorrect tokens"</li>
</ul>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">consume the correct token when the request was executed.</p>
<h1 dir="auto">problem three: disordered schedule</h1>
<h2 dir="auto">Actual behavior</h2>
<ul dir="auto">
<li>assume that there have some request in <code class="notranslate">bucket.contents</code>, [request1, request2, ..., requestN]</li>
<li><code class="notranslate">_on_bucket_wakeup</code> will pop the <code class="notranslate">request1</code> and call <code class="notranslate">limit_move_to_pool</code> to schedule it, and call <code class="notranslate">_schedule_oldest_bucket_request</code> to schedule oldest request</li>
<li><code class="notranslate">_schedule_oldest_bucket_request</code> will pop the <code class="notranslate">request2</code>, and call <code class="notranslate">_schedule_bucket_request</code> to schedule it.  But in <code class="notranslate">_schedule_bucket_request</code>, the <code class="notranslate">request2</code> will be append to bucket's tail instead of be executed or requeued.</li>
</ul>
<h2 dir="auto">Expected behavior</h2>
<ul dir="auto">
<li>keep the order when schedule request.</li>
</ul>