davedevelopment / stiphle

A simple PHP library for throttling or rate limiting

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

queuing explanation

quazardous opened this issue · comments

hi,

i'm using your package in a mutli process env.

It's working as it. But could you explain how you are handling queuing to ensure FIFO (if you do so) ?

yeah the analogy is messy

say you have process A and process B racing for the same throttling resource, process A triggers throttle() and process B triggers it too.

how can we ensure that the throttling will be fair between process A and B ? (the tests I have made shows it seams to work but...)

Hi @quazardous, most (maybe all) of the storage engines have a locking mechanism so only one process/thread can write at once, but also the leaky bucket implementation attempts to do as much as it can without locking. So it works out how long it should sleep for, sleeps, gets a lock, records the necessary info, releases the lock. It's not perfect, but it's worked well enough for my projects.

ok thx

I will give it a try ;p