claudiowilson / LeagueJS

A Javascript Wrapper for the League of Legends API
MIT License
171 stars 45 forks source link

[rework] add method rate limiting #68

Closed Colorfulstan closed 7 years ago

Colorfulstan commented 7 years ago

Besides the App-wide rate-limiting Riot now added method-limiting too which in the current (reworked) implementation is not considered.

Info from 2017/Jul/10

500 requests / 10 sec: ~/api/lol/{region}/v2.2/match/{matchId}~ /lol/match/v3/matches/{matchId} /lol/match/v3/timelines/by-match/{matchId}

1000 requests / 10 sec: ~/api/lol/{region}/v2.2/matchlist/by-summoner/{summonerId}~ /lol/match/v3/matchlists/by-account/{accountId} /lol/match/v3/matchlists/by-account/{accountId}/recent(bearbeitet)

My initial thought for solving this would be to add this information to the Config file and create a new Ratelimiter for the respective endpoints, scheduling the call to ApiRequest.executing, where then in turn the actual request will be scheduled to fit the App-rate limit.

Reference to general rate limiting infos

Colorfulstan commented 7 years ago

rate-limiting headers are now available (app and method) and should be used for rate-limiter

All API responses now include the X-App-Rate-Limit and X-Method-Rate-Limit headers that show the API key rate limit and method endpoint rate limits that are applied to calls for your API key.

Our ask is, now that these exist, PLEASE use the headers. Do not hard code values. Use the headers and write your logic to respect what they are telling you. Note that for multi-threaded apps, it will require using a shared atomic counter across the threads to properly implement your pacing/rate limiting logic, but it is definitely doable. You should also still use the Retry-After header and implement back off logic. All the headers exist for a reason. : )

Colorfulstan commented 7 years ago

More Info on the rate-limit types

Colorfulstan commented 7 years ago

Working on a rate-limiter rework to be published independently and used as dependency for this project. Will add a link to repository here as soon as Ill set it up.

Colorfulstan commented 7 years ago

Monkey patched the static-data limit for now until finishing the rate-limiter rework https://github.com/Colorfulstan/LeagueJS/compare/v1.3.0...v1.3.1 (propably needs some more time then until aug.7 - 80% done, starting integration tests).

Colorfulstan commented 7 years ago

Will be solved when ratelimiter change got published (currently testing) https://github.com/Colorfulstan/LeagueJS/releases/tag/v1.5.0-beta.1

Using https://github.com/Colorfulstan/RiotRateLimiter-node

Colorfulstan commented 7 years ago

published in 1.5.0