Skip to content

feat/uploader thread split - #1523

Merged
SAKURA-CAT merged 24 commits into
mainfrom
feat/uploader-thread-split
Mar 30, 2026
Merged

SAKURA-CAT merged 24 commits into
mainfrom
feat/uploader-thread-split

Conversation

@Nexisato

Copy link
Copy Markdown
Collaborator

Description

  • Uploader thread refactor for splitting task

Closes:

Nexisato added 11 commits March 17, 2026 23:33
Introduce a lightweight Timer scheduler (swanlab.sdk.internal.pkg.timer) implemented with a daemon thread, supporting fixed or dynamic intervals, optional immediate execution, cooperative cancel(), restartable start()/run() (logs a warning if already running), join(), execution_count and is_running properties, and defensive interval validation. The Timer logs task and strategy errors via console and ensures the running task is not forcibly killed. Add comprehensive unit tests covering basic scheduling, immediate run, dynamic interval strategy, cancel interrupting sleep, error resilience, double-run warning, restart behavior, and invalid interval rejection, plus a fixture that cleans up timers after each test.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a background uploading mechanism for SwanLab records, including a new Uploader component, a timer-based task scheduler, and a factory for core implementations. It also adds a cache cleaning script and associated unit tests. Feedback focuses on improving thread safety and efficiency in the Collector by replacing boolean flags and busy-waiting with proper locking mechanisms. Additionally, a bug was identified where the upload_interval parameter was ignored in the Uploader constructor, and several unit tests require corrections to their mock patch targets. Suggestions were also made to optimize the cache cleaning script and make the upload rate-limiting more flexible.

Comment thread swanlab/sdk/internal/core_python/uploader/collector.py Outdated
Comment thread swanlab/sdk/internal/core_python/uploader/collector.py Outdated
Comment thread swanlab/sdk/internal/core_python/uploader/thread.py Outdated
Comment thread tests/unit/sdk/internal/core_python/test_core_python.py Outdated
Comment thread tests/unit/sdk/internal/core_python/uploader/test_thread.py Outdated
Comment thread tests/unit/sdk/internal/core_python/uploader/test_thread.py Outdated
Comment thread tests/unit/sdk/internal/core_python/uploader/test_thread.py Outdated
Comment thread tests/unit/sdk/internal/core_python/uploader/test_upload.py Outdated
Comment thread scripts/clean_pycache.sh
Comment thread swanlab/sdk/internal/core_python/uploader/sender.py Outdated
Introduce grouping of protobuf Records by their record_type (helper.group_records_by_type) and change trace_records to batch by type and call a new upload_record_group transport API. Add an HTTP transport skeleton (HttpRecordTransport) that dispatches record groups to typed handlers and keep a NoopRecordTransport for disabled mode; create_record_transport now returns the HTTP skeleton when enabled. Adjust CoreTransportConfig default enabled behavior and make ThreadPool.upload_interval optional with a resolved default. Update tests and imports to reflect grouping, new transport methods, and protobuf timestamp import fixes.
@Nexisato

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an asynchronous record uploader for the SwanLab SDK, featuring a background thread pool for batching and uploading protobuf records. It also implements a factory pattern for core components and a new lightweight timer utility for periodic tasks. A review comment identifies a potential concurrency bottleneck in the Collector class, where network I/O is performed while holding a lock, which could block the main thread during shutdown.

Comment thread swanlab/sdk/internal/core_python/uploader/collector.py Outdated
@Nexisato

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a background uploader for the SwanLab SDK, enabling asynchronous record transmission to the cloud. Key additions include a Core factory for abstracting core implementations, an Uploader component for managing background tasks, and a lightweight Timer module. Additionally, a cache cleaning script and corresponding Makefile target were added. Feedback focuses on improving upload performance by removing a hardcoded sleep in the transport layer and optimizing queue operations through batching.

Comment thread swanlab/sdk/internal/core_python/uploader/sender.py Outdated
Comment thread swanlab/sdk/internal/core_python/uploader/thread.py Outdated
@SAKURA-CAT SAKURA-CAT self-assigned this Mar 30, 2026
@SAKURA-CAT SAKURA-CAT added the 💪 enhancement New feature or request label Mar 30, 2026
Comment thread tests/unit/sdk/internal/core_python/uploader/test_thread.py Outdated
@Nexisato
Nexisato marked this pull request as ready for review March 30, 2026 11:50
@SAKURA-CAT SAKURA-CAT assigned Nexisato and unassigned SAKURA-CAT Mar 30, 2026
Correct a typo in the module docstring: changed @file from 'test_cnmd_helper.py' to 'test_cmd_helper.py' in tests/unit/sdk/cmd/test_cmd_helper.py. This is a documentation-only change with no functional impact.
Replace '聚合器' with '采集器' in the file header and class docstring of swanlab/sdk/internal/core_python/uploader/collector.py to more accurately reflect the collector terminology.
@SAKURA-CAT
SAKURA-CAT merged commit 0b95f83 into main Mar 30, 2026
18 checks passed
@SAKURA-CAT
SAKURA-CAT deleted the feat/uploader-thread-split branch March 30, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants