Search in sources :

Example 11 with AsyncLoopThread

use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.

the class Worker method startDispatchThread.

private AsyncLoopThread startDispatchThread() {
    // send tuple directly from netty server
    // send control tuple to dispatch thread
    // startDispatchDisruptor();
    IContext context = workerData.getContext();
    String topologyId = workerData.getTopologyId();
    //create recv connection
    Map stormConf = workerData.getStormConf();
    long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 256);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
    //metric for recvControlQueue
    QueueGauge revCtrlGauge = new QueueGauge(recvControlQueue, MetricDef.RECV_CTRL_QUEUE);
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.RECV_CTRL_QUEUE, MetricType.GAUGE), new AsmGauge(revCtrlGauge));
    IConnection recvConnection = context.bind(topologyId, workerData.getPort(), workerData.getDeserializeQueues(), recvControlQueue, false, workerData.getTaskids());
    workerData.setRecvConnection(recvConnection);
    // create recvice control messages's thread
    RunnableCallback recvControlDispather = new VirtualPortCtrlDispatch(workerData, recvConnection, recvControlQueue, MetricDef.RECV_THREAD);
    return new AsyncLoopThread(recvControlDispather, false, Thread.MAX_PRIORITY, true);
}
Also used : IContext(backtype.storm.messaging.IContext) DisruptorQueue(backtype.storm.utils.DisruptorQueue) IConnection(backtype.storm.messaging.IConnection) RunnableCallback(com.alibaba.jstorm.callback.RunnableCallback) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy)

Example 12 with AsyncLoopThread

use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.

the class WorkerData method setDeserializeThreads.

protected List<AsyncLoopThread> setDeserializeThreads() {
    WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
    int tasksNum = shutdownTasks.size();
    double workerRatio = ConfigExtension.getWorkerDeserializeThreadRatio(stormConf);
    int workerDeseriaThreadNum = Utils.getInt(Math.ceil(workerRatio * tasksNum));
    if (workerDeseriaThreadNum > 0 && tasksNum > 0) {
        double average = tasksNum / (double) workerDeseriaThreadNum;
        for (int i = 0; i < workerDeseriaThreadNum; i++) {
            int startRunTaskIndex = Utils.getInt(Math.rint(average * i));
            deserializeThreads.add(new AsyncLoopThread(new WorkerDeserializeRunnable(shutdownTasks, stormConf, workerTopologyContext, startRunTaskIndex, i)));
        }
    }
    return deserializeThreads;
}
Also used : WorkerTopologyContext(backtype.storm.task.WorkerTopologyContext) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread)

Example 13 with AsyncLoopThread

use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.

the class TaskShutdownDameon method shutdown.

@Override
public void shutdown() {
    if (isClosing.compareAndSet(false, true)) {
        LOG.info("Begin to shut down task " + topology_id + ":" + task_id);
        TopologyContext userContext = task.getUserContext();
        for (ITaskHook iTaskHook : userContext.getHooks()) iTaskHook.cleanup();
        closeComponent(task_obj);
        taskHeartbeatTrigger.updateExecutorStatus(TaskStatus.SHUTDOWN);
        // To be assure send  the shutdown information TM
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        // all thread will check the taskStatus
        // once it has been set SHUTDOWN, it will quit
        taskStatus.setStatus(TaskStatus.SHUTDOWN);
        for (AsyncLoopThread thr : all_threads) {
            LOG.info("Begin to shutdown " + thr.getThread().getName());
            thr.cleanup();
            JStormUtils.sleepMs(10);
            thr.interrupt();
            // try {
            // //thr.join();
            // thr.getThread().stop(new RuntimeException());
            // } catch (Throwable e) {
            // }
            LOG.info("Successfully shutdown " + thr.getThread().getName());
        }
        try {
            zkCluster.disconnect();
        } catch (Exception e) {
            LOG.error("Failed to disconnect zk for task-" + task_id);
        }
        LOG.info("Successfully shutdown task " + topology_id + ":" + task_id);
    }
}
Also used : ITaskHook(backtype.storm.hooks.ITaskHook) TopologyContext(backtype.storm.task.TopologyContext) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread)

Example 14 with AsyncLoopThread

use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.

the class Drpc method initClearThread.

private void initClearThread() {
    clearThread = new AsyncLoopThread(new ClearThread(this));
    LOG.info("Successfully start clear thread");
}
Also used : AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread)

Example 15 with AsyncLoopThread

use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.

the class Task method getShutdown.

public TaskShutdownDameon getShutdown(List<AsyncLoopThread> allThreads, RunnableCallback baseExecutor) {
    AsyncLoopThread ackerThread = null;
    if (baseExecutor instanceof SpoutExecutors) {
        ackerThread = ((SpoutExecutors) baseExecutor).getAckerRunnableThread();
        if (ackerThread != null) {
            allThreads.add(ackerThread);
        }
    }
    List<AsyncLoopThread> recvThreads = taskReceiver.getDeserializeThread();
    for (AsyncLoopThread recvThread : recvThreads) {
        allThreads.add(recvThread);
    }
    List<AsyncLoopThread> serializeThreads = taskTransfer.getSerializeThreads();
    allThreads.addAll(serializeThreads);
    TaskHeartbeatTrigger taskHeartbeatTrigger = ((BaseExecutors) baseExecutor).getTaskHbTrigger();
    TaskShutdownDameon shutdown = new TaskShutdownDameon(taskStatus, topologyId, taskId, allThreads, zkCluster, taskObj, this, taskHeartbeatTrigger);
    return shutdown;
}
Also used : TaskHeartbeatTrigger(com.alibaba.jstorm.daemon.worker.timer.TaskHeartbeatTrigger) SingleThreadSpoutExecutors(com.alibaba.jstorm.task.execute.spout.SingleThreadSpoutExecutors) MultipleThreadSpoutExecutors(com.alibaba.jstorm.task.execute.spout.MultipleThreadSpoutExecutors) SpoutExecutors(com.alibaba.jstorm.task.execute.spout.SpoutExecutors) BaseExecutors(com.alibaba.jstorm.task.execute.BaseExecutors) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread)

Aggregations

AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)15 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)3 IConnection (backtype.storm.messaging.IConnection)2 WorkerTopologyContext (backtype.storm.task.WorkerTopologyContext)2 ArrayList (java.util.ArrayList)2 ITaskHook (backtype.storm.hooks.ITaskHook)1 IContext (backtype.storm.messaging.IContext)1 WorkerSlot (backtype.storm.scheduler.WorkerSlot)1 TopologyContext (backtype.storm.task.TopologyContext)1 DisruptorQueue (backtype.storm.utils.DisruptorQueue)1 LocalState (backtype.storm.utils.LocalState)1 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)1 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 SupervisorRefreshConfig (com.alibaba.jstorm.config.SupervisorRefreshConfig)1 WorkerReportError (com.alibaba.jstorm.daemon.worker.WorkerReportError)1 WorkerHeartbeatRunable (com.alibaba.jstorm.daemon.worker.hearbeat.WorkerHeartbeatRunable)1 TaskHeartbeatTrigger (com.alibaba.jstorm.daemon.worker.timer.TaskHeartbeatTrigger)1 EventManagerImp (com.alibaba.jstorm.event.EventManagerImp)1 EventManagerPusher (com.alibaba.jstorm.event.EventManagerPusher)1