Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jitter usage? #5

Open
hemna opened this issue Oct 1, 2024 · 1 comment
Open

Jitter usage? #5

hemna opened this issue Oct 1, 2024 · 1 comment

Comments

@hemna
Copy link

hemna commented Oct 1, 2024

Hello, I'm trying to use jitter to add a randomness to the refresh rate a bit. I want to add a random amount of time between 1 and 20 seconds for the refresh rate but it doesn't seem to do anything.

from limiter import Limiter
from rich.console import Console
from datetime import datetime


REFRESH_RATE: int = 1
BURST_RATE: int = 1
MSG_BUCKET: str = 'messages'

limiter: Limiter = Limiter(rate=REFRESH_RATE, capacity=BURST_RATE)
limit_msgs: Limiter = limiter(bucket=MSG_BUCKET)


@limit_msgs(jitter=range(1000,20000))
def send_message(console, message):
    msg = f"{datetime.now()} {message}"
    console.print(f"Sending {msg}")



def main():
    console = Console()
    x = 1
    while True:
        msg = f"MSG {x}"
        send_message(console, msg)
        x += 1


if __name__ == "__main__":
    main()
@hemna
Copy link
Author

hemna commented Oct 1, 2024

Sending 2024-10-01 09:43:06.055223 MSG 220
Sending 2024-10-01 09:43:07.060343 MSG 221
Sending 2024-10-01 09:43:08.065478 MSG 222
Sending 2024-10-01 09:43:09.070621 MSG 223
Sending 2024-10-01 09:43:10.073807 MSG 224
Sending 2024-10-01 09:43:11.076373 MSG 225
Sending 2024-10-01 09:43:12.079037 MSG 226
Sending 2024-10-01 09:43:13.082216 MSG 227
Sending 2024-10-01 09:43:14.087347 MSG 228
Sending 2024-10-01 09:43:15.090792 MSG 229
Sending 2024-10-01 09:43:16.094575 MSG 230
Sending 2024-10-01 09:43:17.096106 MSG 231
Sending 2024-10-01 09:43:18.101246 MSG 232
Sending 2024-10-01 09:43:19.104858 MSG 233
Sending 2024-10-01 09:43:20.105910 MSG 234
Sending 2024-10-01 09:43:21.110366 MSG 235
Sending 2024-10-01 09:43:22.112382 MSG 236
Sending 2024-10-01 09:43:23.114554 MSG 237
Sending 2024-10-01 09:43:24.118568 MSG 238
Sending 2024-10-01 09:43:25.123707 MSG 239
Sending 2024-10-01 09:43:26.123890 MSG 240
Sending 2024-10-01 09:43:27.125231 MSG 241
Sending 2024-10-01 09:43:28.126932 MSG 242
Sending 2024-10-01 09:43:29.128665 MSG 243
Sending 2024-10-01 09:43:30.129436 MSG 244
Sending 2024-10-01 09:43:31.134592 MSG 245
Sending 2024-10-01 09:43:32.139734 MSG 246
Sending 2024-10-01 09:43:33.143030 MSG 247
Sending 2024-10-01 09:43:34.144749 MSG 248
Sending 2024-10-01 09:43:35.149357 MSG 249
Sending 2024-10-01 09:43:36.154467 MSG 250
Sending 2024-10-01 09:43:37.158837 MSG 251
Sending 2024-10-01 09:43:38.160435 MSG 252
Sending 2024-10-01 09:43:39.162116 MSG 253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant