forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement sliding window rate limiter and enhance online store …
…tag retrieval
- Loading branch information
Bhargav Dodla
committed
Feb 5, 2025
1 parent
6c42453
commit 09302d1
Showing
7 changed files
with
103 additions
and
148 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import time | ||
|
||
|
||
class SlidingWindowRateLimiter: | ||
def __init__(self, max_calls, period): | ||
self.max_calls = max_calls | ||
self.period = period | ||
self.timestamps = [0] * max_calls | ||
self.index = 0 | ||
|
||
def acquire(self): | ||
if self.max_calls == 0: | ||
return True | ||
now = time.time() | ||
window_start = now - self.period | ||
|
||
if self.timestamps[self.index] <= window_start: | ||
self.timestamps[self.index] = now | ||
self.index = (self.index + 1) % self.max_calls | ||
return True | ||
return False |
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
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
Oops, something went wrong.