Search in sources :

Example 1 with NamedThreadFactory

use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.

the class GlobalMonitor method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    nThreads = nThreads <= 0 ? DEFAULT_THREADS : nThreads;
    executor = new ThreadPoolExecutor(nThreads, nThreads, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(nThreads * 2), new NamedThreadFactory("global monitor", false), new ThreadPoolExecutor.CallerRunsPolicy());
}
Also used : NamedThreadFactory(com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 2 with NamedThreadFactory

use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.

the class OtterDownStreamHandler method startDetecting.

private void startDetecting() {
    // 直接发送已追上的状态,保持和eromanga兼容处理
    MainStemEventData mainStemData = new MainStemEventData();
    mainStemData.setPipelineId(pipelineId);
    mainStemData.setStatus(MainStemEventData.Status.OVERTAKE);
    arbitrateEventService.mainStemEvent().single(mainStemData);
    // 启动异步线程定时监控,一定会有数据过来
    String schedulerName = String.format("pipelineId = %s , CanalDetecting", String.valueOf(pipelineId));
    scheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory(schedulerName));
    future = scheduler.scheduleAtFixedRate(new Runnable() {

        public void run() {
            try {
                MDC.put(OtterConstants.splitPipelineLogFileKey, String.valueOf(pipelineId));
                // (因为会有心跳包数据,理论上时间间隔会小于一定值)
                if (isDelayed(System.currentTimeMillis(), lastEventExecuteTime)) {
                    notifyFailed();
                } else {
                    notifySuccessed();
                }
            } catch (Exception e) {
                logger.error("heartbeat check failed!", e);
            } finally {
                MDC.remove(OtterConstants.splitPipelineLogFileKey);
            }
        }
    }, detectingIntervalInSeconds, detectingIntervalInSeconds, TimeUnit.SECONDS);
}
Also used : NamedThreadFactory(com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData)

Example 3 with NamedThreadFactory

use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.

the class StatisticsClientServiceImpl method afterPropertiesSet.

// ================= helper method ==============
public void afterPropertiesSet() throws Exception {
    scheduler = new ScheduledThreadPoolExecutor(DEFAULT_POOL, new NamedThreadFactory("Otter-Statistics-Client"), new ThreadPoolExecutor.CallerRunsPolicy());
    scheduler.submit(new Runnable() {

        public void run() {
            doSendDelayCountEvent();
        }
    });
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NamedThreadFactory(com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory)

Example 4 with NamedThreadFactory

use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.

the class DbPerfIntergration method test_stack.

@Test
public void test_stack() {
    DbMediaSource dbMediaSource = new DbMediaSource();
    dbMediaSource.setId(1L);
    dbMediaSource.setDriver("com.mysql.jdbc.Driver");
    dbMediaSource.setUsername("otter");
    dbMediaSource.setPassword("otter");
    dbMediaSource.setUrl("jdbc:mysql://127.0.0.1:3306/retl");
    dbMediaSource.setEncode("UTF-8");
    dbMediaSource.setType(DataMediaType.MYSQL);
    DbDataMedia dataMedia = new DbDataMedia();
    dataMedia.setSource(dbMediaSource);
    dataMedia.setId(1L);
    dataMedia.setName("ljhtable1");
    dataMedia.setNamespace("otter");
    final DbDialect dbDialect = dbDialectFactory.getDbDialect(2L, dataMedia.getSource());
    want.object(dbDialect).clazIs(MysqlDialect.class);
    final TransactionTemplate transactionTemplate = dbDialect.getTransactionTemplate();
    // 插入数据准备
    int minute = 5;
    int nextId = 1;
    final int thread = 10;
    final int batch = 50;
    final String sql = "insert into otter.ljhtable1 values(? , ? , ? , ?)";
    final CountDownLatch latch = new CountDownLatch(thread);
    ExecutorService executor = new ThreadPoolExecutor(thread, thread, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(thread * 2), new NamedThreadFactory("load"), new ThreadPoolExecutor.CallerRunsPolicy());
    for (int sec = 0; sec < minute * 60; sec++) {
        // 执行秒循环
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < thread; i++) {
            final int start = nextId + i * batch;
            executor.submit(new Runnable() {

                public void run() {
                    try {
                        transactionTemplate.execute(new TransactionCallback() {

                            public Object doInTransaction(TransactionStatus status) {
                                JdbcTemplate jdbcTemplate = dbDialect.getJdbcTemplate();
                                return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

                                    public void setValues(PreparedStatement ps, int idx) throws SQLException {
                                        int id = start + idx;
                                        StatementCreatorUtils.setParameterValue(ps, 1, Types.INTEGER, null, id);
                                        StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, null, RandomStringUtils.randomAlphabetic(1000));
                                        // RandomStringUtils.randomAlphabetic()
                                        long time = new Date().getTime();
                                        StatementCreatorUtils.setParameterValue(ps, 3, Types.TIMESTAMP, new Timestamp(time));
                                        StatementCreatorUtils.setParameterValue(ps, 4, Types.TIMESTAMP, new Timestamp(time));
                                    }

                                    public int getBatchSize() {
                                        return batch;
                                    }
                                });
                            }
                        });
                    } finally {
                        latch.countDown();
                    }
                }
            });
        }
        long endTime = System.currentTimeMillis();
        try {
            latch.await(1000 * 60L - (endTime - startTime), TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (latch.getCount() != 0) {
            System.out.println("perf is not enough!");
            System.exit(-1);
        }
        endTime = System.currentTimeMillis();
        System.out.println("Time cost : " + (System.currentTimeMillis() - startTime));
        try {
            TimeUnit.MILLISECONDS.sleep(1000L - (endTime - startTime));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        nextId = nextId + thread * batch;
    }
    executor.shutdown();
}
Also used : SQLException(java.sql.SQLException) NamedThreadFactory(com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) PreparedStatement(java.sql.PreparedStatement) CountDownLatch(java.util.concurrent.CountDownLatch) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Timestamp(java.sql.Timestamp) Date(java.util.Date) TransactionCallback(org.springframework.transaction.support.TransactionCallback) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) DbDialect(com.alibaba.otter.node.etl.common.db.dialect.DbDialect) BatchPreparedStatementSetter(org.springframework.jdbc.core.BatchPreparedStatementSetter) ExecutorService(java.util.concurrent.ExecutorService) DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia) Test(org.testng.annotations.Test) BaseDbTest(com.alibaba.otter.node.etl.BaseDbTest)

Example 5 with NamedThreadFactory

use of com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory in project otter by alibaba.

the class DefaultCommunicationClientImpl method initial.

public void initial() {
    RejectedExecutionHandler handler = null;
    if (discard) {
        handler = new ThreadPoolExecutor.DiscardPolicy();
    } else {
        handler = new ThreadPoolExecutor.AbortPolicy();
    }
    executor = new ThreadPoolExecutor(poolSize, poolSize, 60 * 1000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(10 * 1000), new NamedThreadFactory("communication-async"), handler);
}
Also used : RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) NamedThreadFactory(com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

NamedThreadFactory (com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)1 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)1 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)1 DbDataMedia (com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)1 DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 BatchPreparedStatementSetter (org.springframework.jdbc.core.BatchPreparedStatementSetter)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1