rzo1 commented on code in PR #8593: URL: https://github.com/apache/storm/pull/8593#discussion_r3409930165
########## storm-client/src/jvm/org/apache/storm/grouping/JitterAwareStreamGrouping.java: ########## @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package org.apache.storm.grouping; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.storm.executor.ChildEwmaStats; +import org.apache.storm.generated.GlobalStreamId; +import org.apache.storm.task.WorkerTopologyContext; + +/** + * A {@link CustomStreamGrouping} that routes each tuple to the downstream (child) task with the lowest + * jitter, as reported back to the emitting task through upstream feedback and aggregated by + * {@link ChildEwmaStats}. Candidates are ordered with {@link ChildEwmaStats#compareByJitter}, so a lower + * {@code __execute-jitter} wins first, then {@code __process-jitter}, then {@code __complete-jitter}. + * Until a source task has any feedback data — and for targets that have not reported yet — the grouping + * falls back to round-robin over the target tasks, so it degrades to an even spread rather than pinning a + * single task. + */ +public class JitterAwareStreamGrouping implements LoadAwareCustomStreamGrouping { + + private final AtomicInteger roundRobin = new AtomicInteger(); + private List<Integer> targetTasks; + private ChildEwmaStats stats; + + @Override + public void refreshLoad(LoadMapping loadMapping) { + // load mapping agnostic + } + + @Override + public void registerEwmaStats(ChildEwmaStats childEwmaStats) { + this.stats = childEwmaStats; + } + + @Override + public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) { + this.targetTasks = targetTasks; + } + + @Override + public List<Integer> chooseTasks(int taskId, List<Object> values) { Review Comment: Falling back to `LoadAwareShuffleGrouping` when there are no jitter stats yet (warmup) or when selection can't pick a clear winner (ties / all-VOID) is exactly the right default, and I see you've already wired it in. It means the grouping degrades to sensible load-aware behavior instead of round-robin in those cases, which is the conservative choice — at worst you match the baseline, you never do worse. It also dovetails with the EWMA-enable point in my summary comment: with `topology.stats.ewma.enable=false` the fallback is *all* you'd ever get, silently, which is the main reason I'd still want validation/a warning there rather than leaving it implicit. -- 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]
