From 581cd6279013a80d21ae36f06e483910d8db55c2 Mon Sep 17 00:00:00 2001
From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
Date: Thu, 22 Oct 2026 23:21:52 -0400
Subject: [PATCH] perf(codeartifact): parallelize per-version metadata fetches
in ListPackageVersions (#6262)
Qodo follow-up from #6204: PypiserverSidecarClient and ReposiliteSidecarClient each made
one sequential HTTP request per version (a HEAD per pypi release, a details GET per Maven
version) before CodeArtifactService paginated, so even a one-result page waited on every
version's own round trip.
Both now run their per-version requests through a new shared SidecarConcurrency.mapBounded,
capped at 8 concurrent requests per sidecar container. The cap is enforced by a shared,
per-container permit (keyed by pypiserver's repositoryContainerId, or a single constant for
Reposilite's one shared container) rather than a per-call-only limit, so two simultaneous
listPackageVersions calls against the same container still can't exceed 8 requests between
them. Tasks run on a virtual-thread-per-task executor, not a platform-thread pool: mapBounded
submits every item up front and lets the semaphore do the real gating, so a package with
thousands of versions doesn't start that many platform threads per call, each just parked in
Semaphore.acquire(). A failure (or the caller being interrupted) also cancels the rest of the
call's work, instead of leaving it running against the sidecar after the call has already
failed. Results stay in input order and a failing item still fails the whole call, matching
the original sequential behavior exactly.
Verified with unit tests for the helper (ordering, the per-container concurrency cap, the
cap holding across two simultaneous calls sharing a container, exception propagation,
cancellation of the rest of the work after an early failure) and a 12-version Docker-gated
test per format against the real pypiserver and Reposilite sidecars, on top of the existing
single-version coverage.
---
.../codeartifact/PypiserverSidecarClient.java | 14 +-
.../codeartifact/ReposiliteSidecarClient.java | 26 ++-
.../codeartifact/SidecarConcurrency.java | 131 +++++++++++++
...odeArtifactMavenDockerIntegrationTest.java | 42 +++++
...CodeArtifactPypiDockerIntegrationTest.java | 43 +++++
.../codeartifact/SidecarConcurrencyTest.java | 177 ++++++++++++++++++
6 files changed, 422 insertions(+), 11 deletions(-)
create mode 100644 src/main/java/io/github/hectorvent/floci/services/codeartifact/SidecarConcurrency.java
create mode 100644 src/test/java/io/github/hectorvent/floci/services/codeartifact/SidecarConcurrencyTest.java
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java
index a0dcc7cdd3..dc6b2ae8ff 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java
@@ -149,6 +149,12 @@ public class PypiserverSidecarClient implements RepositorySidecarManager {
* lands on disk within the same upload, close enough that picking "the first one" over "the
* most recently modified one" makes no practical difference, and the JSON listing gives no
* way to know which upload order they actually arrived in regardless.
+ *
+ *
The per-version {@code HEAD} requests run through {@link SidecarConcurrency#mapBounded},
+ * not a plain sequential loop: a package with many versions used to make every one of those
+ * requests one at a time before returning even a single-result page. Keyed by {@code
+ * repositoryContainerId} so the concurrency cap holds across simultaneous calls against the
+ * same pypiserver container, not just within one of them.
*/
@Override
public List listPackageVersions(String repositoryContainerId, String domain,
@@ -178,13 +184,13 @@ public class PypiserverSidecarClient implements RepositorySidecarManager {
} catch (Exception e) {
throw new IllegalStateException("Could not parse pypiserver's version listing for " + packageName, e);
}
- List result = new ArrayList<>();
- releases.fieldNames().forEachRemaining(version -> {
+ List versions = new ArrayList<>();
+ releases.fieldNames().forEachRemaining(versions::add);
+ return SidecarConcurrency.mapBounded(repositoryContainerId, versions, version -> {
JsonNode files = releases.path(version);
String fileUrl = files.isEmpty() ? "" : files.get(0).path("url").asText("");
- result.add(new PackageVersionTimestamp(version, fileUrl.isEmpty() ? null : lastModified(fileUrl)));
+ return new PackageVersionTimestamp(version, fileUrl.isEmpty() ? null : lastModified(fileUrl));
});
- return result;
}
private Instant lastModified(String fileUrl) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java
index 5f455c821f..b7463f097c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java
@@ -42,6 +42,13 @@ public class ReposiliteSidecarClient implements RepositorySidecarManager {
private static final String FORMAT = "maven";
private static final Logger LOG = Logger.getLogger(ReposiliteSidecarClient.class);
private static final String MAVEN_SETTINGS_PATH = "/api/settings/domain/maven";
+ /**
+ * {@link SidecarConcurrency#mapBounded}'s key for every {@code listPackageVersions} call: one
+ * shared constant, since {@link ReposiliteSidecarManager} backs every CodeArtifact Maven
+ * repository with the same single container, unlike pypiserver's one-container-per-repository
+ * shape.
+ */
+ private static final String SHARED_CONTAINER_KEY = "reposilite";
private static final int REPOSITORY_READY_POLL_MAX_MS = 3_000;
private static final int REPOSITORY_READY_POLL_INTERVAL_MS = 50;
/** Real Maven metadata's own documented {@code lastUpdated} shape: UTC, {@code yyyyMMddHHmmss}. */
@@ -274,6 +281,12 @@ public class ReposiliteSidecarClient implements RepositorySidecarManager {
* "when this version became complete." A version directory with no {@code FILE} entries at
* all (never happens through a real deploy, but not assumed impossible) reports no timestamp
* rather than guessing one.
+ *
+ *
The per-version details requests run through {@link SidecarConcurrency#mapBounded}, not a
+ * plain sequential loop: an artifact with many versions used to make every one of those
+ * requests one at a time before returning even a single-result page. Keyed by {@link
+ * #SHARED_CONTAINER_KEY} so the concurrency cap holds across simultaneous calls too, since
+ * every Maven repository shares the one Reposilite container.
*/
@Override
public List listPackageVersions(String repositoryContainerId, String domain,
@@ -295,16 +308,15 @@ public class ReposiliteSidecarClient implements RepositorySidecarManager {
throw new IllegalStateException("Could not list versions of " + packageName + " on the Reposilite "
+ "sidecar: upstream returned " + artifactResponse.statusCode());
}
- List result = new ArrayList<>();
+ List versions = new ArrayList<>();
for (JsonNode entry : readTree(artifactResponse.body()).path("files")) {
- if (!"DIRECTORY".equals(entry.path("type").asText())) {
- continue;
+ if ("DIRECTORY".equals(entry.path("type").asText())) {
+ versions.add(entry.path("name").asText());
}
- String version = entry.path("name").asText();
- result.add(new PackageVersionTimestamp(version, latestFileTimestamp(baseUrl,
- versionDetailsPath(repositoryContainerId, namespace, packageName, version))));
}
- return result;
+ return SidecarConcurrency.mapBounded(SHARED_CONTAINER_KEY, versions, version -> new PackageVersionTimestamp(
+ version, latestFileTimestamp(baseUrl, versionDetailsPath(repositoryContainerId, namespace,
+ packageName, version))));
}
private Instant latestFileTimestamp(String baseUrl, String versionDetailsPath) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/SidecarConcurrency.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/SidecarConcurrency.java
new file mode 100644
index 0000000000..70358fe482
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/SidecarConcurrency.java
@@ -0,0 +1,131 @@
+package io.github.hectorvent.floci.services.codeartifact;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.Semaphore;
+import java.util.function.Function;
+
+/**
+ * Bounds the fan-out {@code listPackageVersions} needs when a sidecar has no single call that
+ * returns every version's publish time at once: pypiserver answers with no timestamp field at
+ * all (one {@code HEAD} per version), and Reposilite's per-version details page is the only way
+ * to read a version's own file timestamps (one {@code GET} per version). Running those
+ * sequentially means a one-result page still waits on every version in the package; running them
+ * all at once risks opening as many sockets against the sidecar container as the package has
+ * versions. Package-private: both callers live in this package, and the ordering/exception
+ * guarantees below are shaped around what {@code listPackageVersions} specifically needs, not a
+ * general-purpose utility.
+ */
+final class SidecarConcurrency {
+
+ /**
+ * How many per-item requests run against one sidecar container at once, no matter how many
+ * {@code listPackageVersions} calls against that same container are in flight at the same
+ * time: large enough that a package with a realistic number of versions sees a real speedup,
+ * small enough that the container backing a sidecar can't be flooded with hundreds of
+ * simultaneous connections.
+ */
+ private static final int MAX_CONCURRENT_REQUESTS = 8;
+
+ /**
+ * One {@link Semaphore} per sidecar container, shared across every {@code mapBounded} call for
+ * that container so {@link #MAX_CONCURRENT_REQUESTS} holds in aggregate: a per-call-only limit
+ * would let two simultaneous {@code listPackageVersions} calls against the same container each
+ * open that many connections, doubling the real cap. The key is whatever identity a caller
+ * already has for "which container": pypiserver's own {@code repositoryContainerId} (one
+ * container per CodeArtifact repository), or a single shared constant for Reposilite (one
+ * container for every Maven repository).
+ */
+ private static final Map