featzhang commented on code in PR #27561:
URL: https://github.com/apache/flink/pull/27561#discussion_r3143630500


##########
flink-models/flink-model-triton/src/main/java/org/apache/flink/model/triton/TritonOptions.java:
##########
@@ -253,4 +253,75 @@ private TritonOptions() {
                             "Number of successful test requests required in 
HALF_OPEN state to close the circuit. "
                                     + "If any request fails in HALF_OPEN 
state, the circuit immediately reopens. "
                                     + "Defaults to 3 requests. Only effective 
when circuit-breaker-enabled is true.");
+
+    // ==================== Retry and Default Value Fallback Options 
====================
+
+    @Documentation.Section({Documentation.Sections.MODEL_TRITON_ADVANCED})
+    public static final ConfigOption<Integer> MAX_RETRIES =
+            ConfigOptions.key("max-retries")
+                    .intType()
+                    .defaultValue(0)
+                    .withDescription(
+                            "Maximum number of retries (additional attempts 
beyond the first) "
+                                    + "for failed inference requests. With 
max-retries=2 the "
+                                    + "request will be attempted up to 3 times 
in total "
+                                    + "(1 initial attempt + 2 retries). When 
set to 0 (default), "
+                                    + "no retry is performed. Only transient 
failures are "
+                                    + "retried: network errors, 5xx responses, 
and response "
+                                    + "parsing failures. Client-side 4xx 
errors and circuit "
+                                    + "breaker OPEN failures are never retried 
because they "
+                                    + "indicate a persistent condition. Must 
be >= 0.");
+
+    @Documentation.Section({Documentation.Sections.MODEL_TRITON_ADVANCED})
+    public static final ConfigOption<Duration> RETRY_BACKOFF =
+            ConfigOptions.key("retry-backoff")

Review Comment:
   Renamed to `retry-initial-backoff` in the latest push (commit bb17448e936). 
Matches the `*.exponential-delay.initial-backoff` naming used by 
cleanup-strategy / restart-strategy. Fixed in TritonOptions + 
AbstractTritonModelFunction + tests + regenerated docs HTML.



##########
flink-models/flink-model-triton/src/main/java/org/apache/flink/model/triton/TritonOptions.java:
##########
@@ -253,4 +253,75 @@ private TritonOptions() {
                             "Number of successful test requests required in 
HALF_OPEN state to close the circuit. "
                                     + "If any request fails in HALF_OPEN 
state, the circuit immediately reopens. "
                                     + "Defaults to 3 requests. Only effective 
when circuit-breaker-enabled is true.");
+
+    // ==================== Retry and Default Value Fallback Options 
====================
+
+    @Documentation.Section({Documentation.Sections.MODEL_TRITON_ADVANCED})
+    public static final ConfigOption<Integer> MAX_RETRIES =
+            ConfigOptions.key("max-retries")
+                    .intType()
+                    .defaultValue(0)
+                    .withDescription(
+                            "Maximum number of retries (additional attempts 
beyond the first) "
+                                    + "for failed inference requests. With 
max-retries=2 the "
+                                    + "request will be attempted up to 3 times 
in total "
+                                    + "(1 initial attempt + 2 retries). When 
set to 0 (default), "
+                                    + "no retry is performed. Only transient 
failures are "
+                                    + "retried: network errors, 5xx responses, 
and response "
+                                    + "parsing failures. Client-side 4xx 
errors and circuit "
+                                    + "breaker OPEN failures are never retried 
because they "
+                                    + "indicate a persistent condition. Must 
be >= 0.");
+
+    @Documentation.Section({Documentation.Sections.MODEL_TRITON_ADVANCED})
+    public static final ConfigOption<Duration> RETRY_BACKOFF =
+            ConfigOptions.key("retry-backoff")
+                    .durationType()
+                    .defaultValue(Duration.ofMillis(100))
+                    .withDescription(
+                            "Initial backoff duration between retry attempts. 
Uses exponential "
+                                    + "backoff: first retry waits this 
duration, second retry "
+                                    + "waits 2x, third waits 4x, and so on, 
capped at "
+                                    + "retry-backoff-max. Defaults to 100ms. 
Must be > 0.");
+
+    @Documentation.Section({Documentation.Sections.MODEL_TRITON_ADVANCED})
+    public static final ConfigOption<Duration> RETRY_BACKOFF_MAX =
+            ConfigOptions.key("retry-backoff-max")

Review Comment:
   Renamed to `retry-max-backoff` in the latest push (commit bb17448e936) for 
consistency with `cleanup-strategy.exponential-delay.max-backoff` and 
`restart-strategy.exponential-delay.max-backoff`. Thanks for the suggestion.



##########
flink-models/flink-model-triton/src/main/java/org/apache/flink/model/triton/AbstractTritonModelFunction.java:
##########
@@ -143,6 +188,28 @@ public void open(FunctionContext context) throws Exception 
{
         LOG.debug("Creating Triton HTTP client.");
         this.httpClient = TritonUtils.createHttpClient(timeout.toMillis());
 
+        // Provision a private single-thread scheduler for delayed retries so 
that retry tasks are
+        // bound to this operator's lifecycle. Previously 
CompletableFuture.delayedExecutor was
+        // used, but it schedules on the shared ForkJoinPool.commonPool() 
whose tasks are not
+        // cancellable from close() and would happily fire an HTTP call with 
an already-released
+        // client. Only allocate when retries are actually enabled to avoid 
idle threads.
+        if (maxRetries > 0) {
+            final AtomicInteger threadIndex = new AtomicInteger();
+            this.retryScheduler =
+                    Executors.newSingleThreadScheduledExecutor(
+                            r -> {
+                                Thread t =
+                                        new Thread(
+                                                r,
+                                                "triton-retry-scheduler-"
+                                                        + modelName
+                                                        + "-"
+                                                        + 
threadIndex.getAndIncrement());

Review Comment:
   Good catch. Since we use a `SingleThreadScheduledExecutor`, the counter 
could only ever produce `-0` and carried no diagnostic value. Dropped the 
`AtomicInteger` entirely in commit bb17448e936; the thread is now simply named 
`triton-retry-scheduler-<modelName>`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to