Search in sources :

Example 1 with Load

use of org.apache.storm.grouping.Load in project storm by apache.

the class WorkerState method refreshLoad.

public void refreshLoad() {
    Set<Integer> remoteTasks = Sets.difference(new HashSet<Integer>(outboundTasks), new HashSet<>(taskIds));
    Long now = System.currentTimeMillis();
    Map<Integer, Double> localLoad = shortExecutorReceiveQueueMap.entrySet().stream().collect(Collectors.toMap((Function<Map.Entry<Integer, DisruptorQueue>, Integer>) Map.Entry::getKey, (Function<Map.Entry<Integer, DisruptorQueue>, Double>) entry -> {
        DisruptorQueue.QueueMetrics qMetrics = entry.getValue().getMetrics();
        return ((double) qMetrics.population()) / qMetrics.capacity();
    }));
    Map<Integer, Load> remoteLoad = new HashMap<>();
    cachedNodeToPortSocket.get().values().stream().forEach(conn -> remoteLoad.putAll(conn.getLoad(remoteTasks)));
    loadMapping.setLocal(localLoad);
    loadMapping.setRemote(remoteLoad);
    if (now > nextUpdate.get()) {
        receiver.sendLoadMetrics(localLoad);
        nextUpdate.set(now + LOAD_REFRESH_INTERVAL_MS);
    }
}
Also used : Load(org.apache.storm.grouping.Load) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) Function(java.util.function.Function) AtomicLong(java.util.concurrent.atomic.AtomicLong) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with Load

use of org.apache.storm.grouping.Load in project storm by apache.

the class NettyTest method doTestLoad.

private void doTestLoad(Map<String, Object> stormConf) throws Exception {
    LOG.info("2 test load");
    String reqMessage = "0123456789abcdefghijklmnopqrstuvwxyz";
    IContext context = TransportFactory.makeContext(stormConf, null);
    try {
        AtomicReference<TaskMessage> response = new AtomicReference<>();
        try (IConnection server = context.bind(null, 0, mkConnectionCallback(response::set), null);
            IConnection client = context.connect(null, "localhost", server.getPort(), remoteBpStatus)) {
            waitUntilReady(client, server);
            byte[] messageBytes = reqMessage.getBytes(StandardCharsets.UTF_8);
            send(client, taskId, messageBytes);
            /*
                 * This test sends a broadcast to all connected clients from the server, so we need to wait until the server has registered
                 * the client as connected before sending load metrics.
                 *
                 * It's not enough to wait until the client reports that the channel is open, because the server event loop may not have
                 * finished running channelActive for the new channel. If we send metrics too early, the server will broadcast to no one.
                 *
                 * By waiting for the response here, we ensure that the client will be registered at the server before we send load metrics.
                 */
            waitForNotNull(response);
            Map<Integer, Double> taskToLoad = new HashMap<>();
            taskToLoad.put(1, 0.0);
            taskToLoad.put(2, 1.0);
            server.sendLoadMetrics(taskToLoad);
            List<Integer> tasks = new ArrayList<>();
            tasks.add(1);
            tasks.add(2);
            Testing.whileTimeout(Testing.TEST_TIMEOUT_MS, () -> client.getLoad(tasks).isEmpty(), sleep());
            Map<Integer, Load> load = client.getLoad(tasks);
            assertThat(load.get(1).getBoltLoad(), is(0.0));
            assertThat(load.get(2).getBoltLoad(), is(1.0));
        }
    } finally {
        context.term();
    }
}
Also used : Load(org.apache.storm.grouping.Load) IContext(org.apache.storm.messaging.IContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) IConnection(org.apache.storm.messaging.IConnection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TaskMessage(org.apache.storm.messaging.TaskMessage)

Example 3 with Load

use of org.apache.storm.grouping.Load in project storm by apache.

the class Client method getLoad.

@Override
public Map<Integer, Load> getLoad(Collection<Integer> tasks) {
    Map<Integer, Double> loadCache = serverLoad;
    Map<Integer, Load> ret = new HashMap<>();
    if (loadCache != null) {
        double clientLoad = Math.min(pendingMessages.get(), 1024) / 1024.0;
        for (Integer task : tasks) {
            Double found = loadCache.get(task);
            if (found != null) {
                ret.put(task, new Load(true, found, clientLoad));
            }
        }
    }
    return ret;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Load(org.apache.storm.grouping.Load) HashMap(java.util.HashMap)

Example 4 with Load

use of org.apache.storm.grouping.Load in project storm by apache.

the class WorkerState method refreshLoad.

public void refreshLoad(List<IRunningExecutor> execs) {
    Set<Integer> remoteTasks = Sets.difference(new HashSet<>(outboundTasks), new HashSet<>(localTaskIds));
    Map<Integer, Double> localLoad = new HashMap<>();
    for (IRunningExecutor exec : execs) {
        double receiveLoad = exec.getReceiveQueue().getQueueLoad();
        localLoad.put(exec.getExecutorId().get(0).intValue(), receiveLoad);
    }
    Map<Integer, Load> remoteLoad = new HashMap<>();
    cachedNodeToPortSocket.get().values().stream().forEach(conn -> remoteLoad.putAll(conn.getLoad(remoteTasks)));
    loadMapping.setLocal(localLoad);
    loadMapping.setRemote(remoteLoad);
    Long now = System.currentTimeMillis();
    if (now > nextLoadUpdate.get()) {
        receiver.sendLoadMetrics(localLoad);
        nextLoadUpdate.set(now + LOAD_REFRESH_INTERVAL_MS);
    }
}
Also used : Load(org.apache.storm.grouping.Load) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) IRunningExecutor(org.apache.storm.executor.IRunningExecutor)

Aggregations

Load (org.apache.storm.grouping.Load)4 HashMap (java.util.HashMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1 IRunningExecutor (org.apache.storm.executor.IRunningExecutor)1 IConnection (org.apache.storm.messaging.IConnection)1 IContext (org.apache.storm.messaging.IContext)1 TaskMessage (org.apache.storm.messaging.TaskMessage)1 DisruptorQueue (org.apache.storm.utils.DisruptorQueue)1