-
Notifications
You must be signed in to change notification settings - Fork 36
⚡ Bolt: Throttle adaptive weights hot-reloading File I/O #490
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,3 +51,4 @@ Thumbs.db | |
| # ===================== | ||
| .vscode/ | ||
| .idea/ | ||
| .venv/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ class AdaptiveWeights: | |
| _instance = None | ||
| _weights = None | ||
| _last_loaded = 0 | ||
| _last_checked = 0 | ||
|
|
||
| def __new__(cls): | ||
| if cls._instance is None: | ||
|
|
@@ -40,8 +41,12 @@ def _load_weights(self): | |
| self._weights = {} | ||
|
|
||
| def _check_reload(self): | ||
| # Optimization: Checking mtime is fast (stat call). | ||
| self._load_weights() | ||
| # Throttle mtime checks to at most once every 5 seconds | ||
| # This prevents multiple disk I/O operations per request | ||
| current_time = time.time() | ||
| if current_time - self._last_checked > 5: | ||
| self._last_checked = current_time | ||
|
Comment on lines
+44
to
+48
|
||
| self._load_weights() | ||
|
Comment on lines
+47
to
+49
|
||
|
|
||
| def _save_weights(self): | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For interval throttling, prefer
time.monotonic()overtime.time().time.time()can jump backwards/forwards due to NTP or manual clock changes, which could cause reload checks to be skipped for longer than intended or run too frequently.