forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the same algorithm to throttle quality reports as analytics repor…
…ts (cvat-ai#7596) <!-- Raise an issue to propose your change (https://github.com/opencv/cvat/issues). It helps to avoid duplication of efforts from multiple independent contributors. Discuss your ideas with maintainers to be sure that changes will be approved and merged. Read the [Contribution guide](https://opencv.github.io/cvat/docs/contributing/). --> <!-- Provide a general summary of your changes in the Title above --> ### Motivation and context <!-- Why is this change required? What problem does it solve? If it fixes an open issue, please link to the issue here. Describe your changes in detail, add screenshots. --> See cvat-ai#7576 for more details. This patch extracts the high-level throttling functionality added in that patch and reuses it for quality reports. Note: in that patch I referred to this functionality as debouncing, but throttling seems like a more accurate description. It would be debouncing if the autoupdate job only ran after no updates occurred for a period, which is not how it actually works. ### How has this been tested? <!-- Please describe in detail how you tested your changes. Include details of your testing environment, and the tests you ran to see how your change affects other areas of the code, etc. --> ### Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. If an item isn't applicable for some reason, then ~~explicitly strikethrough~~ the whole line. If you don't do that, GitHub will show incorrect progress for the pull request. If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I submit my changes into the `develop` branch - [x] I have created a changelog fragment <!-- see top comment in CHANGELOG.md --> - ~~[ ] I have updated the documentation accordingly~~ - ~~[ ] I have added tests to cover my changes~~ - ~~[ ] I have linked related issues (see [GitHub docs]( https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))~~ - ~~[ ] I have increased versions of npm packages if it is necessary ([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning), [cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning), [cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning) and [cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))~~ ### License - [x] I submit _my code changes_ under the same [MIT License]( https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern.
- Loading branch information
Showing
4 changed files
with
71 additions
and
86 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelog.d/20240312_163919_roman_throttling_quality_reports.md
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,4 @@ | ||
### Fixed | ||
|
||
- Made quality report update job scheduling more efficient | ||
(<https://github.com/opencv/cvat/pull/7596>) |
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,48 @@ | ||
# Copyright (C) 2024 CVAT.ai Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from collections.abc import Callable | ||
from datetime import datetime | ||
|
||
import django_rq | ||
|
||
def schedule_job_with_throttling( | ||
queue_name: str, | ||
job_id_base: str, | ||
scheduled_time: datetime, | ||
func: Callable, | ||
**func_kwargs | ||
) -> None: | ||
""" | ||
This function schedules an RQ job to run at `scheduled_time`, | ||
unless it had already been used to schedule a job to run at some future time | ||
with the same values of `queue_name` and `job_id_base`, | ||
in which case it does nothing. | ||
The scheduled job will have an ID beginning with `job_id_base`, | ||
and will execute `func(**func_kwargs)`. | ||
""" | ||
with django_rq.get_connection(queue_name) as connection: | ||
# The blocker key is used to implement the throttling. | ||
# The first time this function is called for a given tuple of | ||
# (queue_name, job_id_base), we schedule the job and create a blocker | ||
# that expires at the same time as the job is supposed to start. | ||
# Until the blocker expires, we don't schedule any more jobs | ||
# with the same tuple. | ||
blocker_key = f"cvat:utils:scheduling-blocker:{queue_name}:{job_id_base}" | ||
if connection.exists(blocker_key): | ||
return | ||
|
||
queue_job_id = f"{job_id_base}-{scheduled_time.timestamp()}" | ||
|
||
# TODO: reuse the Redis connection if Django-RQ allows it. | ||
# See <https://github.com/rq/django-rq/issues/652>. | ||
django_rq.get_scheduler(queue_name).enqueue_at( | ||
scheduled_time, | ||
func, | ||
**func_kwargs, | ||
job_id=queue_job_id, | ||
) | ||
|
||
connection.set(blocker_key, queue_job_id, exat=scheduled_time) |