These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

API rate limiter for phealng

First post
Author
Ydnari
Estrale Frontiers
#1 - 2014-07-12 12:34:11 UTC
CCP FoxFour posted a rate limit policy a while ago. Linode, which I use as a host, recently moved all their storage to SSDs, and as a result my main app started fetching from the API in bursts fast enough that I was worrying I was sailing close to the limits, at least for a minute or two at a time.

I use the excellent phealng for all API access since it honours cache timers automatically (even when they're harmful - spurious 221's I'm looking at you, see other thread).

So I've added in a basic rate limiter option to it. Commit is available here:

https://github.com/andyhassall/phealng/commit/2b0fbb7ddf1a039fe559cc3924dd7d7676bfeeb2

It's a simple leaky-bucket rate limiter allowing (by default) unthrottled bursts up to 10 requests, and then throttles to 30 requests per second from then on. It uses a file to store last request and bucket capacity, and advisory file locking for exclusive access - if you're on a file system or server setup where advisory file locking doesn't work then this isn't suitable.

It also makes no attempt at fair queueing or FIFO; rate limited requests retry with random sleeps, up to 10 seconds, after which it throws an exception.

Have tried to follow the same principle as other pheal configuration options, so by default it uses a "null" rate limiter, and you can select an implementation to use with:

Config::getInstance()->rateLimiter = new \Pheal\RateLimiter\FileLockRateLimiter()

... optionally passing in a directory where it can write the lock file.

If there's any interest in this I can have a go at contacting the author of pheal and submit a pull request.

--

CCP FoxFour
C C P
C C P Alliance
#2 - 2014-07-12 13:20:43 UTC
Awesome work and thank you for caring! :D

I am sure Peter Powers would be interested in seeing this. You can normally find him on #eve-dev if he doesn't see this directly.

Off topic, how do you like Linode?

@CCP_FoxFour // Technical Designer // Team Tech Co

Third-party developer? Check out the official developers site for dev blogs, resources, and more.

Ydnari
Estrale Frontiers
#3 - 2014-07-12 14:29:08 UTC
CCP FoxFour wrote:
Off topic, how do you like Linode?


Nothing bad to say about them really. On the couple of occasions when they seemed to be underdelivering on price for the VM specs, they've done an upgrade round and doubled memory or storage or changed storage to SSD, and I've ended up not looking for a competitor again.

They aren't quite the cheapest provider around, but I'm happy with them.

--

CCP FoxFour
C C P
C C P Alliance
#4 - 2014-07-12 15:20:20 UTC
Ydnari wrote:
CCP FoxFour wrote:
Off topic, how do you like Linode?


Nothing bad to say about them really. On the couple of occasions when they seemed to be underdelivering on price for the VM specs, they've done an upgrade round and doubled memory or storage or changed storage to SSD, and I've ended up not looking for a competitor again.

They aren't quite the cheapest provider around, but I'm happy with them.


Cool looking between them and DigitalOcean. Anyways, back on topic...

@CCP_FoxFour // Technical Designer // Team Tech Co

Third-party developer? Check out the official developers site for dev blogs, resources, and more.

Dragonaire
Here there be Dragons
#5 - 2014-07-14 21:05:39 UTC
CCP FoxFour - I just notice one API that has a bad cachedUntil time on it, api/CallList has the same time for both currentTime and cachedUntil. That will be wasting everybody's network bandwidth.
currentTime>2014-07-14 18:27:20
cachedUntil>2014-07-14 18:27:20

I know there are others but happened to be looking at that one in my cache and noticed it.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

CCP FoxFour
C C P
C C P Alliance
#6 - 2014-07-15 11:07:52 UTC
Dragonaire wrote:
CCP FoxFour - I just notice one API that has a bad cachedUntil time on it, api/CallList has the same time for both currentTime and cachedUntil. That will be wasting everybody's network bandwidth.
currentTime>2014-07-14 18:27:20
cachedUntil>2014-07-14 18:27:20

I know there are others but happened to be looking at that one in my cache and noticed it.


Thanks for the heads up. I have added it to my back log. Let me know of any others you find.

@CCP_FoxFour // Technical Designer // Team Tech Co

Third-party developer? Check out the official developers site for dev blogs, resources, and more.

Peter Powers
Terrorists of Dimensions
HORSE-KILLERS
#7 - 2014-07-16 15:37:26 UTC
Hello, i'm the maintainer of phealng, and i just looked through your changes.
If you want to put in a pull request, i'll merge this feature in.

However, there is something i noticed that i'd like you to take care of first, the code style should be psr-2, you have some brackets wrong, and at least it seems to me as if your using tab..

3rdPartyEve.net - your catalogue for 3rd party applications

Ydnari
Estrale Frontiers
#8 - 2014-07-16 19:12:44 UTC
Thanks, when I get a moment I'll lint it up to PSR-2 and then submit the request.

--