{{ message }}
refactor(agent): Gather dashboard and deployment data concurrently#162
Merged
Conversation
The dashboard stats and the deployment list previously ran each docker and OS call one after another, so load time grew with the number of deployments, networks, and services. These independent calls now run concurrently, so the dashboard responds in roughly the time of the slowest call instead of the sum of all of them.
| networkCount = len(networks) | ||
| } | ||
| }) | ||
| run(func() { |
There was a problem hiding this comment.
The variable portCount is being modified inside a goroutine without synchronization (e.g., atomic or mutex). While each closure is intended to write to its own variable, this loop iterates over containers and increments a shared portCount across the outer scope. If the slice were processed concurrently, this would be a data race. In the current specific structure, only one goroutine touches portCount, so it is technically safe, but it is fragile if other concurrent tasks are added or if this block is refactored.
Suggested change
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The agent assembled the dashboard stats and the deployment list by running every docker and OS call in sequence. Each deployment's status check shells out to
docker compose, so a host with many deployments paid that cost once per deployment, and the dashboard endpoint stacked another dozen independent docker/OS calls on top, all serial. Both add up to noticeably slow dashboard loads, which is the substance of #154.The independent calls now run concurrently. Deployment status checks and network inspections use a bounded worker pool (12); the dashboard endpoint fans its independent lookups out and waits for all of them. Output is identical: each worker writes only its own slot, and results stay in their original order. Load time drops from the sum of the calls toward the slowest single call.
One thing a reviewer should weigh: a single dashboard request can now spawn up to roughly 35 concurrent
dockerprocesses at peak (the endpoint's own fan-out plus the nested pools inside the deployment and network lookups). On a small host that's a transient spike. If it shows up under load, a shared cap across the docker-calling managers is the follow-up; the per-site bound of 12 is the floor for now.