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