Add overloaded menthod for SdkWarmUp.prime overloaded to accept speci…#7130
Add overloaded menthod for SdkWarmUp.prime overloaded to accept speci…#7130joviegas wants to merge 3 commits into
Conversation
…fic clients that needs to be warmedUp
9a05f34 to
ccf1b3a
Compare
… that we can retry for next prime call
| @@ -71,4 +85,44 @@ public static void prime() { | |||
| primed = true; | |||
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Since this is passed between layers it probably should implement equals/hashcode/toString
Motivation and Context
SdkWarmUp.prime()warms everySdkWarmUpProvideron the classpath and the discovered HTTP transports. Applications that use a single client (for example onlyS3AsyncClient) 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@SdkPublicApioverload. Matches each requested class against the registered providers, warms the matched transport throughSdkWarmUpProvider.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'ssyncClientClassName()/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);SdkWarmUpholds one long-lived instance.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. (ThePRIME_LOCKmutex is used only by the existing no-argprime().)Testing
Testing
License