diff --git a/poc/2-py-rps/stream_to_state.py b/poc/2-py-rps/stream_to_state.py index 3eb1e00..4c30d6f 100644 --- a/poc/2-py-rps/stream_to_state.py +++ b/poc/2-py-rps/stream_to_state.py @@ -14,9 +14,9 @@ def main(): def get_args(): ap = argparse.ArgumentParser() - ap.add_argument("-n", type=int, help="queue capacity", default=3) - ap.add_argument("-m", type=int, help="queue fill line", default=3) - ap.add_argument("-r", type=int, help="drain rate per second", default=2) + ap.add_argument("-n", type=float, help="queue capacity", default=3) + ap.add_argument("-m", type=float, help="queue fill line", default=3) + ap.add_argument("-r", type=float, help="drain rate per second", default=2) ap.add_argument("-p", type=str, help="path to write out to", default="/tmp/cbappend.both.txt") return ap.parse_args() @@ -65,9 +65,10 @@ class Bucket(): self.CB = CB self.__last_pop = 0 self.__last_state = False + self.__last_push = None def push(self): - result = self.__push_c(1) + result = self.__push() self.__cb() return result @@ -97,10 +98,15 @@ class Bucket(): def state(self): return self.__last_state - def __push_c(self, c): + def __push(self): self.__pop() + c = 1 + now = self.__now() + if self.__last_push: + c = min([now - self.__last_push, 1]) if self.q+c > self.N: return False + self.__last_push = now self.q += c return True diff --git a/poc/2-py-rps/test.sh b/poc/2-py-rps/test.sh index 01b889e..f9ad58a 100644 --- a/poc/2-py-rps/test.sh +++ b/poc/2-py-rps/test.sh @@ -31,6 +31,6 @@ python3 ./testdata/rand_0_n_weighted_stream.py \ -w 3 \ | peek \ | python3 ./stream_to_state.py \ - -n 7 \ - -m 6 \ - -r 6 + -n 1 \ + -m .25 \ + -r .3