Skip to content

Add warning if poor performance is detected #145

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

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Using the following categories, list your changes in this order:

## [Unreleased]

- Nothing (yet)
### Added

- Added warning if poor system/cache/database performance is detected.

## [3.1.0] - 2023-05-06

Expand Down
10 changes: 10 additions & 0 deletions src/reactpy_django/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def db_cleanup(immediate: bool = False):
from .config import REACTPY_CACHE, REACTPY_DATABASE, REACTPY_RECONNECT_MAX
from .models import ComponentSession

clean_started_at = datetime.now()
cache_key: str = create_cache_key("last_cleaned")
now_str: str = datetime.strftime(timezone.now(), DATE_FORMAT)
cleaned_at_str: str = caches[REACTPY_CACHE].get(cache_key)
Expand All @@ -340,3 +341,12 @@ def db_cleanup(immediate: bool = False):
last_accessed__lte=expires_by
).delete()
caches[REACTPY_CACHE].set(cache_key, now_str, timeout=None)

# Check if cleaning took abnormally long
clean_duration = datetime.now() - clean_started_at
if clean_duration.total_seconds() > 1:
_logger.warning(
"ReactPy has taken %s seconds to clean up expired component sessions. "
"This may indicate a performance issue with your system, cache, or database.",
clean_duration.total_seconds(),
)
2 changes: 1 addition & 1 deletion src/reactpy_django/websocket/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def _run_dispatch_loop(self):
carrier=ComponentWebsocket(self.close, self.disconnect, dotted_path),
)
now = timezone.now()
component_args: Sequence[Any] = tuple()
component_args: Sequence[Any] = ()
component_kwargs: MutableMapping[str, Any] = {}

# Verify the component has already been registered
Expand Down