Repository navigation
feat: implement concurrent NAR streaming (#619) - #621
Conversation
Implement concurrent NAR streaming to clients as soon as the download starts from an upstream cache. Previously, ncps would download the entire NAR into its store before starting to stream it back to the client. For large NAR files, this often led to client timeouts. This change refactors coordinateDownload to allow an early return (after the download starts) for jobs that support streaming, like NAR downloads. It also ensures that the distributed lock is held until the asset is fully stored in the background, preventing other instances from starting a redundant download while allowing the current instance to stream the file being downloaded. Detailed changes: - Refactored coordinateDownload to accept a waitForStorage boolean. - Updated prePullNar to call coordinateDownload with waitForStorage=false. - Updated prePullNarInfo to call coordinateDownload with waitForStorage=true. - Modified distributed lock handling in coordinateDownload to release the lock in a background goroutine when waitForStorage is false. - Updated GetNar to handle the -1 size returned during streaming and correctly stream from the temporary file using io.Pipe. - Fixed a race condition in GetNar where clients could receive EOF before the NAR was fully stored in final storage by waiting for storage completion in the streaming goroutine. - Added TestNarStreaming to verify the fix and ensured it checks for asset presence after completion. - Updated TestConcurrentDownload_CancelOneClient_OthersContinue to handle -1 size during streaming. fixes #618 (cherry picked from commit c6ce7c6)
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant performance improvement by enabling concurrent streaming of NAR files. Previously, the system would fully download large NARs before serving them, leading to client timeouts. The core change refactors the download coordination logic to allow clients to receive data as soon as the download starts, while intelligently managing distributed locks to prevent duplicate downloads and ensure eventual storage. This enhancement drastically improves the user experience for large asset transfers. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces concurrent NAR streaming, a significant performance improvement for large NAR files. The changes are well-structured, refactoring coordinateDownload to support both streaming and waiting for full storage. The distributed lock handling is correctly updated to hold the lock in the background during streaming, preventing redundant downloads while allowing clients to receive data immediately. The addition of TestNarStreaming is excellent, as it thoroughly verifies the new functionality and the fix for a potential race condition. The code is of high quality. I have one suggestion to improve maintainability by refactoring a small piece of duplicated code.

Implement concurrent NAR streaming to clients as soon as the download
starts
from an upstream cache. Previously, ncps would download the entire NAR
into its
store before starting to stream it back to the client. For large NAR
files,
this often led to client timeouts.
This change refactors coordinateDownload to allow an early return (after
the
download starts) for jobs that support streaming, like NAR downloads. It
also
ensures that the distributed lock is held until the asset is fully
stored in
the background, preventing other instances from starting a redundant
download
while allowing the current instance to stream the file being downloaded.
Detailed changes:
waitForStorage=false.
waitForStorage=true.
the lock
in a background goroutine when waitForStorage is false.
correctly
stream from the temporary file using io.Pipe.
before the
NAR was fully stored in final storage by waiting for storage completion
in the
streaming goroutine.
asset
presence after completion.
handle -1
size during streaming.
fixes #618
(cherry picked from commit c6ce7c6)