Search in sources :

Example 1 with DisruptorQueue

use of org.apache.storm.utils.DisruptorQueue 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 DisruptorQueue

use of org.apache.storm.utils.DisruptorQueue in project storm by apache.

the class WorkerState method transferLocal.

public void transferLocal(List<AddressedTuple> tupleBatch) {
    Map<Integer, List<AddressedTuple>> grouped = new HashMap<>();
    for (AddressedTuple tuple : tupleBatch) {
        Integer executor = taskToShortExecutor.get(tuple.dest);
        if (null == executor) {
            LOG.warn("Received invalid messages for unknown tasks. Dropping... ");
            continue;
        }
        List<AddressedTuple> current = grouped.get(executor);
        if (null == current) {
            current = new ArrayList<>();
            grouped.put(executor, current);
        }
        current.add(tuple);
    }
    for (Map.Entry<Integer, List<AddressedTuple>> entry : grouped.entrySet()) {
        DisruptorQueue queue = shortExecutorReceiveQueueMap.get(entry.getKey());
        if (null != queue) {
            queue.publish(entry.getValue());
        } else {
            LOG.warn("Received invalid messages for unknown tasks. Dropping... ");
        }
    }
}
Also used : DisruptorQueue(org.apache.storm.utils.DisruptorQueue) ImmutableMap(com.google.common.collect.ImmutableMap) AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Example 3 with DisruptorQueue

use of org.apache.storm.utils.DisruptorQueue in project storm by apache.

the class BoltExecutor method init.

public void init(Map<Integer, Task> idToTask) {
    while (!stormActive.get()) {
        Utils.sleep(100);
    }
    LOG.info("Preparing bolt {}:{}", componentId, idToTask.keySet());
    for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
        Task taskData = entry.getValue();
        IBolt boltObject = (IBolt) taskData.getTaskObject();
        TopologyContext userContext = taskData.getUserContext();
        taskData.getBuiltInMetrics().registerAll(stormConf, userContext);
        if (boltObject instanceof ICredentialsListener) {
            ((ICredentialsListener) boltObject).setCredentials(credentials);
        }
        if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue, "transfer", workerData.getTransferQueue());
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
            Map cachedNodePortToSocket = (Map) workerData.getCachedNodeToPortSocket().get();
            BuiltinMetricsUtil.registerIconnectionClientMetrics(cachedNodePortToSocket, stormConf, userContext);
            BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), stormConf, userContext);
        } else {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
        }
        IOutputCollector outputCollector = new BoltOutputCollectorImpl(this, taskData, entry.getKey(), rand, hasEventLoggers, isDebug);
        boltObject.prepare(stormConf, userContext, new OutputCollector(outputCollector));
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Prepared bolt {}:{}", componentId, idToTask.keySet());
    setupMetrics();
}
Also used : IOutputCollector(org.apache.storm.task.IOutputCollector) OutputCollector(org.apache.storm.task.OutputCollector) Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) IOutputCollector(org.apache.storm.task.IOutputCollector) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 4 with DisruptorQueue

use of org.apache.storm.utils.DisruptorQueue in project storm by apache.

the class SpoutExecutor method init.

public void init(final Map<Integer, Task> idToTask) {
    while (!stormActive.get()) {
        Utils.sleep(100);
    }
    LOG.info("Opening spout {}:{}", componentId, idToTask.keySet());
    this.idToTask = idToTask;
    this.maxSpoutPending = Utils.getInt(stormConf.get(Config.TOPOLOGY_MAX_SPOUT_PENDING), 0) * idToTask.size();
    this.spouts = new ArrayList<>();
    for (Task task : idToTask.values()) {
        this.spouts.add((ISpout) task.getTaskObject());
    }
    this.pending = new RotatingMap<>(2, new RotatingMap.ExpiredCallback<Long, TupleInfo>() {

        @Override
        public void expire(Long key, TupleInfo tupleInfo) {
            Long timeDelta = null;
            if (tupleInfo.getTimestamp() != 0) {
                timeDelta = Time.deltaMs(tupleInfo.getTimestamp());
            }
            failSpoutMsg(SpoutExecutor.this, idToTask.get(tupleInfo.getTaskId()), timeDelta, tupleInfo, "TIMEOUT");
        }
    });
    this.spoutThrottlingMetrics.registerAll(stormConf, idToTask.values().iterator().next().getUserContext());
    this.outputCollectors = new ArrayList<>();
    for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
        Task taskData = entry.getValue();
        ISpout spoutObject = (ISpout) taskData.getTaskObject();
        SpoutOutputCollectorImpl spoutOutputCollector = new SpoutOutputCollectorImpl(spoutObject, this, taskData, entry.getKey(), emittedCount, hasAckers, rand, hasEventLoggers, isDebug, pending);
        SpoutOutputCollector outputCollector = new SpoutOutputCollector(spoutOutputCollector);
        this.outputCollectors.add(outputCollector);
        taskData.getBuiltInMetrics().registerAll(stormConf, taskData.getUserContext());
        Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
        BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, taskData.getUserContext());
        if (spoutObject instanceof ICredentialsListener) {
            ((ICredentialsListener) spoutObject).setCredentials(credentials);
        }
        spoutObject.open(stormConf, taskData.getUserContext(), outputCollector);
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Opened spout {}:{}", componentId, idToTask.keySet());
    setupMetrics();
}
Also used : Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) TupleInfo(org.apache.storm.executor.TupleInfo) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) MutableLong(org.apache.storm.utils.MutableLong) RotatingMap(org.apache.storm.utils.RotatingMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ISpout(org.apache.storm.spout.ISpout)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)4 DisruptorQueue (org.apache.storm.utils.DisruptorQueue)4 Map (java.util.Map)2 ICredentialsListener (org.apache.storm.ICredentialsListener)2 Task (org.apache.storm.daemon.Task)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Function (java.util.function.Function)1 TupleInfo (org.apache.storm.executor.TupleInfo)1 Load (org.apache.storm.grouping.Load)1 ISpout (org.apache.storm.spout.ISpout)1 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)1 IBolt (org.apache.storm.task.IBolt)1 IOutputCollector (org.apache.storm.task.IOutputCollector)1 OutputCollector (org.apache.storm.task.OutputCollector)1 TopologyContext (org.apache.storm.task.TopologyContext)1 AddressedTuple (org.apache.storm.tuple.AddressedTuple)1 MutableLong (org.apache.storm.utils.MutableLong)1 RotatingMap (org.apache.storm.utils.RotatingMap)1