Mailing List Archive

Ticket #13325: tmdb3 python bindings wait too long for the API rate limit to expire
#13325: tmdb3 python bindings wait too long for the API rate limit to expire
-----------------------------------+----------------------------
Reporter: jasongillis | Owner: Raymond Wagner
Type: Patch - Bug Fix | Status: new
Priority: trivial | Milestone: needs_triage
Component: Bindings - Python | Version: Master Head
Severity: medium | Keywords:
Ticket locked: 0 |
-----------------------------------+----------------------------
For a long time now, I've been noticing that fetching video metadata
became really slow. I put up with it (for three years!) until this
weekend when I had some time to dig in. In looking at the debug for
tmdb3.py, it notes that after 40 queries, it sleeps for 10 seconds. It
should be sleeping until the current 40 reqs / 10 seconds rate window is
closed instead of waiting 10 seconds. I was seeing 40 requests in about 9
seconds due to network latency, so it should have been sleeping 1 second
or so.

It turns out that when handling of the rate limiting was put in, max() was
used instead of min(). The section of code that changed should have used
min() since it needs to wait for up to 10 seconds to comply with the rate
limit guidelines set by tmdb (https://www.themoviedb.org/faq/api).

Pull request for this trivial change is:

https://github.com/MythTV/mythtv/pull/171

This is my first ever pull request, so let me know if I've done this
wrong.

Thanks,
Jason

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13325>
MythTV <http://www.mythtv.org>
MythTV Media Center
Re: Ticket #13325: tmdb3 python bindings wait too long for the API rate limit to expire [ In reply to ]
#13325: tmdb3 python bindings wait too long for the API rate limit to expire
-------------------------------+--------------------------------
Reporter: jasongillis | Owner: Raymond Wagner
Type: Patch - Bug Fix | Status: new
Priority: trivial | Milestone: needs_triage
Component: Bindings - Python | Version: Master Head
Severity: medium | Resolution:
Keywords: | Ticket locked: 0
-------------------------------+--------------------------------

Comment (by ijc):

I'm not a mythtv dev but IMHO it'd be good if some of the verbiage from
above made its way into the commit message (I'm thinking perhaps
everything from "It should be sleeping..." in the first para to the end of
the second paragraph).

Part of me wonders why we don't just wait for whatever the `Retry-After`
header says if it is present, without either the `min` or `max` clamping.
Presumably with a 10s fallback if the header is not present.

Which lead me to wonder if the behaviour here has changed when the header
is missing since `min`/`max` on `(None,10)` do different things (likewise
calling them on `("", 10)`). But actually I suppose/assume that `e.headers
['retry-after']` will raise a key-not-found exception of some sort in that
case so `min`/`max` never gets called and there's no change from this
commit.

So, LGTM modulo the commit message.

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13325#comment:1>
MythTV <http://www.mythtv.org>
MythTV Media Center
Re: Ticket #13325: tmdb3 python bindings wait too long for the API rate limit to expire [ In reply to ]
#13325: tmdb3 python bindings wait too long for the API rate limit to expire
-------------------------------+--------------------------------
Reporter: jasongillis | Owner: Raymond Wagner
Type: Patch - Bug Fix | Status: new
Priority: trivial | Milestone: needs_triage
Component: Bindings - Python | Version: Master Head
Severity: medium | Resolution:
Keywords: | Ticket locked: 0
-------------------------------+--------------------------------

Comment (by rcrdnalor):

Note: tmdb3 removed rate limiting.
See

https://developers.themoviedb.org/3/getting-started/request-rate-limiting

https://www.themoviedb.org/talk/5e4d87b41e92250018c924b9

--
Ticket URL: <https://code.mythtv.org/trac/ticket/13325#comment:2>
MythTV <http://www.mythtv.org>
MythTV Media Center