use of com.tencent.angel.common.AngelThreadFactory in project angel by Tencent.
the class MatrixTransportClient method init.
private void init() {
Configuration conf = PSAgentContext.get().getConf();
rpcContext.init(conf, PSAgentContext.get().getLocationManager().getPsIds());
// Init response handler
registeHandler();
// Init network parameters
int nettyWorkerNum = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_EVENTGROUP_THREADNUM, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_EVENTGROUP_THREADNUM);
int sendBuffSize = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_SNDBUF, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_SNDBUF);
int recvBuffSize = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_RCVBUF, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_RCVBUF);
final int maxMessageSize = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_MAX_MESSAGE_SIZE, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_MAX_MESSAGE_SIZE);
requestThreadPool = Executors.newFixedThreadPool(conf.getInt(AngelConf.ANGEL_MATRIXTRANSFER_CLIENT_REQUESTER_POOL_SIZE, AngelConf.DEFAULT_ANGEL_MATRIXTRANSFER_CLIENT_REQUESTER_POOL_SIZE), new AngelThreadFactory("RPCRequest"));
responseThreadPool = Executors.newFixedThreadPool(conf.getInt(AngelConf.ANGEL_MATRIXTRANSFER_CLIENT_RESPONSER_POOL_SIZE, AngelConf.DEFAULT_ANGEL_MATRIXTRANSFER_CLIENT_RESPONSER_POOL_SIZE), new AngelThreadFactory("RPCResponser"));
ChannelPoolParam poolParam = new ChannelPoolParam();
poolParam.maxActive = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_PERSERVER, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_PERSERVER);
poolParam.minActive = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MIN_CONN_PERSERVER, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MIN_CONN_PERSERVER);
poolParam.maxIdleTimeMs = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_IDLETIME_MS, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_MAX_CONN_IDLETIME_MS);
poolParam.getChannelTimeoutMs = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_GET_CONN_TIMEOUT_MS, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_GET_CONN_TIMEOUT_MS);
int ioRatio = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_IORATIO, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_IORATIO);
String channelType = conf.get(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_CLIENT_CHANNEL_TYPE, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_CLIENT_CHANNEL_TYPE);
hbThreadPool = Executors.newFixedThreadPool(8, new AngelThreadFactory("Heartbeat"));
bootstrap = new Bootstrap();
channelManager = new ChannelManager2(bootstrap, poolParam);
channelManager.initAndStart();
// Use Epoll for linux
Class channelClass;
String os = System.getProperty("os.name");
if (os != null && os.toLowerCase().startsWith("linux") && channelType.equals("epoll")) {
LOG.info("Use epoll channel");
channelClass = EpollSocketChannel.class;
eventGroup = new EpollEventLoopGroup(nettyWorkerNum);
((EpollEventLoopGroup) eventGroup).setIoRatio(ioRatio);
} else {
LOG.info("Use nio channel");
channelClass = NioSocketChannel.class;
eventGroup = new NioEventLoopGroup(nettyWorkerNum);
((NioEventLoopGroup) eventGroup).setIoRatio(ioRatio);
}
MatrixTransportClient client = this;
bootstrap.group(eventGroup).channel(channelClass).option(ChannelOption.SO_SNDBUF, sendBuffSize).option(ChannelOption.SO_RCVBUF, recvBuffSize).option(ChannelOption.SO_KEEPALIVE, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeLine = ch.pipeline();
pipeLine.addLast(new LengthFieldBasedFrameDecoder(maxMessageSize, 0, 4, 0, 4));
pipeLine.addLast(new LengthFieldPrepender(4));
pipeLine.addLast(new MatrixTransportClientHandler(client, dispatchMessageQueue, rpcContext));
}
});
}
Aggregations