Skip to content
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

Implement parallel downloads for COM scenarios #1588

Merged
merged 14 commits into from
Nov 17, 2021

Conversation

florelis
Copy link
Member

@florelis florelis commented Oct 13, 2021

This changes allows multiple installer downloads to occur in parallel (and parallel to installation) on COM scenarios.

Modified the context orchestrator to have multiple queues for items to execute, each of which will handle a type of command (download & install). Items to execute will move to each queue according to the next command to execute for the item. Each queue handles execution of its items.
Adding a queue item in the orchestrator will add it to the queue corresponding to its first command. Once it is executed, it is moved to the queue for the following command and so on. Each queue knows how many commands of its type can run at the same time (n for download, 1 for install) and how many are currently running. When an item is added, if it has capacity, it starts a thread to run it. And when a thread finishes running a command (after sending it to the orchestrator to re-queue), it runs the next item.

Microsoft Reviewers: Open in CodeFlow

@florelis florelis requested a review from a team as a code owner October 13, 2021 23:43
void ContextOrchestrator::AddItemManifestToInstallingSource(const OrchestratorQueueItem& queueItem)
{
const auto& manifest = queueItem.GetContext().Get<Execution::Data::Manifest>();
m_installingWriteableSource->AddPackageVersion(manifest, std::filesystem::path{ manifest.Id + '.' + manifest.Version });
Copy link
Member

Choose a reason for hiding this comment

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

This is a pre-existing issue, but there is the potential for Id collisions from different sources here. Not an immediate concern but we might want to consider how we can store them all in the same index, or use a separate index per source. Most options are probably annoying and relatively expensive to implement, and the current potential for problems is low. Just leaving this here as a reminder to you and me both.

src/AppInstallerCLICore/ContextOrchestrator.cpp Outdated Show resolved Hide resolved
{
++m_runningThreads;
std::thread runnerThread(&OrchestratorQueue::RunItems, this);
runnerThread.detach();
Copy link
Member

Choose a reason for hiding this comment

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

We should probably be keeping the std::thread objects because I don't think that keeping tracking of running threads with a counter will work.

Copy link
Member

Choose a reason for hiding this comment

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

Basically I think that the use of a counter here is fragile; if the thread terminates abnormally it won't decrement. With proper handling you can make it safer and more robust, but you could also put that effort into using the kernel to know the answer. And it has just a bit more mileage than any code we write here 😄

So I would write a thread wrapper type and hold onto them. You can WaitForSingleObject on the native handle (probably) as suggested https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodethread

That way we could say for a fact how many threads were still running at this point.

src/AppInstallerCLICore/ContextOrchestrator.cpp Outdated Show resolved Hide resolved
src/AppInstallerCLICore/ContextOrchestrator.cpp Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback Issue needs attention from issue or PR author label Oct 21, 2021
@ghost ghost added the No-Recent-Activity Issue has no recent activity label Nov 3, 2021
@ghost
Copy link

ghost commented Nov 3, 2021

@lechacon this pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.

@JohnMcPMS
Copy link
Member

@msftbot, leave the PR open.

[Maybe that works?]

@ghost ghost removed No-Recent-Activity Issue has no recent activity Needs-Author-Feedback Issue needs attention from issue or PR author labels Nov 6, 2021
@github-actions

This comment has been minimized.

@florelis florelis merged commit 39034e1 into microsoft:master Nov 17, 2021
@florelis florelis deleted the parallelDownloads branch May 28, 2022 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants