Search in sources :

Example 1 with NamedThreadFactory

use of io.seata.common.thread.NamedThreadFactory in project seata by seata.

the class TmNettyRemotingClient method getInstance.

/**
 * Gets instance.
 *
 * @return the instance
 */
public static TmNettyRemotingClient getInstance() {
    if (instance == null) {
        synchronized (TmNettyRemotingClient.class) {
            if (instance == null) {
                NettyClientConfig nettyClientConfig = new NettyClientConfig();
                final ThreadPoolExecutor messageExecutor = new ThreadPoolExecutor(nettyClientConfig.getClientWorkerThreads(), nettyClientConfig.getClientWorkerThreads(), KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<>(MAX_QUEUE_SIZE), new NamedThreadFactory(nettyClientConfig.getTmDispatchThreadPrefix(), nettyClientConfig.getClientWorkerThreads()), RejectedPolicies.runsOldestTaskPolicy());
                instance = new TmNettyRemotingClient(nettyClientConfig, null, messageExecutor);
            }
        }
    }
    return instance;
}
Also used : NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with NamedThreadFactory

use of io.seata.common.thread.NamedThreadFactory in project seata by seata.

the class RmNettyRemotingClient method getInstance.

/**
 * Gets instance.
 *
 * @return the instance
 */
public static RmNettyRemotingClient getInstance() {
    if (instance == null) {
        synchronized (RmNettyRemotingClient.class) {
            if (instance == null) {
                NettyClientConfig nettyClientConfig = new NettyClientConfig();
                final ThreadPoolExecutor messageExecutor = new ThreadPoolExecutor(nettyClientConfig.getClientWorkerThreads(), nettyClientConfig.getClientWorkerThreads(), KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<>(MAX_QUEUE_SIZE), new NamedThreadFactory(nettyClientConfig.getRmDispatchThreadPrefix(), nettyClientConfig.getClientWorkerThreads()), new ThreadPoolExecutor.CallerRunsPolicy());
                instance = new RmNettyRemotingClient(nettyClientConfig, null, messageExecutor);
            }
        }
    }
    return instance;
}
Also used : NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 3 with NamedThreadFactory

use of io.seata.common.thread.NamedThreadFactory in project seata by seata.

the class AbstractNettyRemotingClient method init.

@Override
public void init() {
    timerExecutor.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            clientChannelManager.reconnect(getTransactionServiceGroup());
        }
    }, SCHEDULE_DELAY_MILLS, SCHEDULE_INTERVAL_MILLS, TimeUnit.MILLISECONDS);
    if (NettyClientConfig.isEnableClientBatchSendRequest()) {
        mergeSendExecutorService = new ThreadPoolExecutor(MAX_MERGE_SEND_THREAD, MAX_MERGE_SEND_THREAD, KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory(getThreadPrefix(), MAX_MERGE_SEND_THREAD));
        mergeSendExecutorService.submit(new MergedSendRunnable());
    }
    super.init();
    clientBootstrap.start();
}
Also used : NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 4 with NamedThreadFactory

use of io.seata.common.thread.NamedThreadFactory in project seata by seata.

the class DefaultServerMessageListenerImpl method init.

/**
 * Init.
 */
public void init() {
    ExecutorService mergeSendExecutorService = new ThreadPoolExecutor(MAX_LOG_SEND_THREAD, MAX_LOG_SEND_THREAD, KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory(THREAD_PREFIX, MAX_LOG_SEND_THREAD, true));
    mergeSendExecutorService.submit(new BatchLogRunnable());
}
Also used : NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 5 with NamedThreadFactory

use of io.seata.common.thread.NamedThreadFactory in project seata by seata.

the class ProtocolV1Client method main.

// can test tps
public static void main(String[] args) {
    ProtocolV1Client client = new ProtocolV1Client();
    client.connect("127.0.0.1", 8811, 500);
    Map<String, String> head = new HashMap<>();
    head.put("tracerId", "xxadadadada");
    head.put("token", "adadadad");
    BranchCommitRequest body = new BranchCommitRequest();
    body.setBranchId(12345L);
    body.setApplicationData("application");
    body.setBranchType(BranchType.AT);
    body.setResourceId("resource-1234");
    body.setXid("xid-1234");
    final int threads = 50;
    final AtomicLong cnt = new AtomicLong(0);
    // no queue
    final ThreadPoolExecutor service1 = new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("client-", false));
    for (int i = 0; i < threads; i++) {
        service1.execute(() -> {
            while (true) {
                try {
                    Future future = client.sendRpc(head, body);
                    RpcMessage resp = (RpcMessage) future.get(200, TimeUnit.MILLISECONDS);
                    if (resp != null) {
                        cnt.incrementAndGet();
                    }
                } catch (Exception e) {
                // ignore
                }
            }
        });
    }
    Thread thread = new Thread(new Runnable() {

        private long last = 0;

        @Override
        public void run() {
            while (true) {
                long count = cnt.get();
                long tps = count - last;
                LOGGER.error("last 1s invoke: {}, queue: {}", tps, service1.getQueue().size());
                last = count;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest) RpcMessage(io.seata.core.protocol.RpcMessage) AtomicLong(java.util.concurrent.atomic.AtomicLong) Future(java.util.concurrent.Future) ChannelFuture(io.netty.channel.ChannelFuture) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

NamedThreadFactory (io.seata.common.thread.NamedThreadFactory)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)7 RpcMessage (io.seata.core.protocol.RpcMessage)2 BranchCommitRequest (io.seata.core.protocol.transaction.BranchCommitRequest)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)1 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)1 NettyRemotingServer (io.seata.core.rpc.netty.NettyRemotingServer)1 ProtocolV1Decoder (io.seata.core.rpc.netty.v1.ProtocolV1Decoder)1 ProtocolV1Encoder (io.seata.core.rpc.netty.v1.ProtocolV1Encoder)1 DefaultCoordinator (io.seata.server.coordinator.DefaultCoordinator)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1