From 2f5abaa47abfb9f42a26babe59965c5f26538a3f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 13 Aug 2021 12:34:40 -0400 Subject: [PATCH] Add njs token bucket gist url --- piker/data/_sampling.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/piker/data/_sampling.py b/piker/data/_sampling.py index 490ae4b0..654404ef 100644 --- a/piker/data/_sampling.py +++ b/piker/data/_sampling.py @@ -235,6 +235,8 @@ async def sample_and_broadcast( try: if tick_throttle: + # this is a send mem chan that likely + # pushes to the ``uniform_rate_send()`` below. await stream.send(quote) else: @@ -255,6 +257,10 @@ async def sample_and_broadcast( subs.remove((stream, tick_throttle)) +# TODO: a less naive throttler, here's some snippets: +# token bucket by njs: +# https://gist.github.com/njsmith/7ea44ec07e901cb78ebe1dd8dd846cb9 + async def uniform_rate_send( rate: float, @@ -292,7 +298,7 @@ async def uniform_rate_send( rate = 1 / (now - last_send) last_send = now - # print(f'{rate} Hz sending quotes\n{first_quote}') + # print(f'{rate} Hz sending quotes') # \n{first_quote}') # TODO: now if only we could sync this to the display # rate timing exactly lul