GGraziadei commented on code in PR #8593: URL: https://github.com/apache/storm/pull/8593#discussion_r3407823472
########## 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: Thank you. I have actually gone ahead and implemented the P2C selection strategy to avoid that herd effect. Regarding that, what are your thoughts on falling back to `LoadAware` grouping as a default routing mechanism when we don't have any jitter statistics yet, or if the system fails to select a proper task to forward to? -- 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]
