Skip to content

Rate limiting & recovery #166

Closed
Closed

Description

@jflemer-ndp

Would it be possible to add rate limiting into GitLab._raw_get (https://github.com/gpocentek/python-gitlab/blob/5f444e4ddf1087a8c4081f9b8d8b3d87d36a0985/gitlab/__init__.py), and tie it to a config option in ~/.python-gitlab.cfg?

I keep getting gitlab.exceptions.GitlabListError from HTTP 429 caused by gitlab rate limiting. I expect that I can catch this exception, delay the code, then retry the failed command. There is no nice way though to know the number of underlying API requests made by python-gitlab, so I cannot precisely figure out the delay, nor easily pre-delay to avoid the HTTP 429. I'm using a few ....list(all=True), so even with arbitrary sleeps here and there, I still hit the limit a lot.

Activity

  1. gpocentek commented on Oct 17, 2016

    @gpocentek
    Contributor

    @jflemer-ndp did you try to pass a per_page argument to get more than 20 items per API request? I guess you have a lot of data to handle if you reach the limits, but maybe getting larger batch of data at a time would help. Something like ....list(all=True, per_page=100)

    If possible I'd like to avoid implementing an API limitation workaround.

    Let me know if this works for you.

  2. gpocentek commented on Oct 17, 2016

    @gpocentek
    Contributor

    Note: my company gitlab seems to limit the number of items per page to 100. Not sure if this is configurable on the server side.

  3. jflemer-ndp commented on Oct 17, 2016

    @jflemer-ndp
    ContributorAuthor

    With per_page=100 I get a little further, but still eventually hit the limit. I am looping over all the notes of all the tickets. Since there is no way in the GitLab API to filter what notes I want, this is going to be a lot of objects.

    proj = gl.projects.get(urllib.quote(project))
    for tix in proj.issues.list(all=True, per_page=100):
      for n in tix.notes.list(all=True, per_page=100):
        pass
    
  4. gpocentek commented on Oct 17, 2016

    @gpocentek
    Contributor

    It was worth a try... I'll see what I can do but this might take me some time (bit swamped at the moment).

  5. jflemer-ndp commented on Oct 17, 2016

    @jflemer-ndp
    ContributorAuthor

    I happened to find a kinda cool idea about using a decorator for rate limiting here http://blog.gregburek.com/2011/12/05/Rate-limiting-with-decorators/

    But that probably wouldn't fit with making it configurable.

    If I get fed up with my excessive and arbitrary sleeps, I'll try to submit a patch/merge request on this.

  6. max-wittig commented on Apr 10, 2018

    @max-wittig
    Member

    @jflemer-ndp Any progress on your implementation of rate limits, yet?

    Maybe this library could be used? https://github.com/tomasbasham/ratelimit

  7. added 3 commits that reference this issue on Apr 16, 2018
    64560ee
    6715224
    2abf9ab
  8. locked as resolved and limited conversation to collaborators on Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions