-
-
Save fernandezpablo85/18d2a52797e6e3fd2be0167699f7b7ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------- MODULE throttler -------------------------------- | |
EXTENDS TLC, Integers, Sequences | |
MaxEpoch == 20 | |
RequestLimit == 5 | |
TimeSpan == 1 | |
Min(seq) == | |
LET | |
ix == 1..Len(seq) | |
i == CHOOSE x \in ix: \A y \in ix: seq[x] <= seq[y] | |
IN seq[i] | |
TooManyRequests(seq, epoch) == | |
/\ Len(seq) >= RequestLimit | |
/\ Min(seq) >= epoch - TimeSpan | |
CircularBufferAppend(seq, newElement) == | |
IF Len(seq) < RequestLimit | |
THEN Append(seq, newElement) | |
ELSE Tail(seq) \o <<newElement>> | |
(* --algorithm throttler | |
variables | |
epoch = 0; | |
mem = <<>>; | |
ready = TRUE; | |
revived = FALSE; | |
define | |
TypeOk == | |
/\ epoch \in 0..MaxEpoch | |
/\ \A i \in 1..Len(mem): mem[i] <= epoch | |
RequestsEventuallyUnblock == ~ready ~> ~[]ready | |
end define; | |
fair+ process time = 0 | |
begin | |
Tick: | |
while epoch < MaxEpoch do | |
epoch := epoch + 1; | |
end while; | |
end process; | |
fair+ process requests = 1 | |
begin | |
Request: | |
while epoch < MaxEpoch do | |
if TooManyRequests(mem, epoch) then | |
Wait: | |
ready := FALSE; | |
else | |
Act: | |
ready := TRUE; | |
mem := CircularBufferAppend(mem, epoch); | |
end if; | |
end while; | |
end process; | |
end algorithm; *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment