Skip to content

Add overloaded menthod for SdkWarmUp.prime overloaded to accept speci…#7130

Open
joviegas wants to merge 3 commits into
feature/master/crac_auto_priming_supportfrom
joviegas/overload-prime
Open

Add overloaded menthod for SdkWarmUp.prime overloaded to accept speci…#7130
joviegas wants to merge 3 commits into
feature/master/crac_auto_priming_supportfrom
joviegas/overload-prime

Conversation

@joviegas

@joviegas joviegas commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

SdkWarmUp.prime() warms every SdkWarmUpProvider on the classpath and the discovered HTTP transports. Applications that use a single client (for example only S3AsyncClient) pay the cost of warming clients and transports they never use. This change adds a targeted overload, SdkWarmUp.prime(Class...), that warms only the requested service clients and only the transports they need.

Modifications

  • SdkWarmUp.prime(Class<? extends SdkClient>...): new @SdkPublicApi overload. Matches each requested class against the registered providers, warms the matched transport through SdkWarmUpProvider.warmUpClient(ClientType), then runs only the HTTP warmer for the matched transports (sync, async, or both). Unmatched classes are logged at warn and skipped. Clients already primed in this JVM are skipped on later calls.
  • TargetedWarmUpInvoker (new, internal): stateless matcher that maps requested class names against each provider's syncClientClassName()/asyncClientClassName() and returns the matched transports so the caller can narrow the HTTP warm-up.
  • PrimedClientRegistry (new, internal): owns the "which clients are already primed" dedup state, so a client is warmed at most once per JVM. State is per-instance (unit-testable with fresh instances); SdkWarmUp holds one long-lived instance.
  • Concurrency: prime(Class...) is lock-free — dedup uses a thread-safe set, and warm-up (network I/O) runs outside any lock. Concurrent calls may briefly double-warm the same client, which is harmless because warming is idempotent. A run that throws before completing does not record the client as primed, so it is retried on the next call. (The PRIME_LOCK mutex is used only by the existing no-arg prime().)

Testing

  • Junits added

Testing

License

  • I confirm that this pull request can be released under the Apache 2 license

@joviegas joviegas requested a review from a team as a code owner July 10, 2026 13:47
@joviegas joviegas force-pushed the joviegas/overload-prime branch from 9a05f34 to ccf1b3a Compare July 10, 2026 17:39
@@ -71,4 +85,44 @@ public static void prime() {
primed = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we be recording/using the PRIMED_CLIENTS for the base prime case as well and/or checking primed in the prime(client...) method?

I could see a case either way and it may be complicated to do, so I don't nessecarily think we need to, but in theory if you do prime() and prime(S3Client) the s3 client would get primed twice, though thats also not terrible. Maybe prime(clients...) could check if primed is true and short circuit in that case (ie, everything has already been primed, so nothing to do for specific client?).

At minimum an update in the java docs to clarify shoudl be sufficent I think.

boolean warmFailed = false;
Set<ClientType> matched = EnumSet.noneOf(ClientType.class);
for (SdkWarmUpProvider provider : providers) {
ClientType transport = transportFor(requested, provider);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Naming nit - I found "transport" here to be a litlte confusing - this makes me think about http1.1 vs http2 rather than sync vs async. Maybe just use clientType?

* successfully.
*/
@SdkInternalApi
public final class TargetedWarmUpResult {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is passed between layers it probably should implement equals/hashcode/toString

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