use of com.tencent.angel.common.transport.ChannelManager in project angel by Tencent.
the class MatrixTransportClient method init.
private void init() {
Configuration conf = PSAgentContext.get().getConf();
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));
responseThreadPool = Executors.newFixedThreadPool(conf.getInt(AngelConf.ANGEL_MATRIXTRANSFER_CLIENT_RESPONSER_POOL_SIZE, AngelConf.DEFAULT_ANGEL_MATRIXTRANSFER_CLIENT_RESPONSER_POOL_SIZE));
bootstrap = new Bootstrap();
channelManager = new ChannelManager(bootstrap);
// TODO: use Epoll for linux future
/*Class channelClass = null;
String os = System.getProperty("os.name");
if(os.toLowerCase().startsWith("win")) {
LOG.info("os is windows, we use NioEventLoopGroup");
channelClass = NioSocketChannel.class;
eventGroup = new NioEventLoopGroup(nettyWorkerNum);
((NioEventLoopGroup)eventGroup).setIoRatio(70);
} else if(os.toLowerCase().startsWith("linux")) {
}
*/
eventGroup = new NioEventLoopGroup(nettyWorkerNum);
((NioEventLoopGroup) eventGroup).setIoRatio(70);
bootstrap.group(eventGroup).channel(NioSocketChannel.class).option(ChannelOption.SO_SNDBUF, sendBuffSize).option(ChannelOption.SO_RCVBUF, recvBuffSize).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(msgQueue, dispatchMessageQueue));
}
});
}
use of com.tencent.angel.common.transport.ChannelManager in project angel by Tencent.
the class PSClient method init.
/**
* Init
*/
public void init() {
bootstrap = new Bootstrap();
Configuration conf = context.getConf();
int workerNum = conf.getInt(AngelConf.ANGEL_PS_HA_SYNC_WORKER_NUM, AngelConf.DEFAULT_ANGEL_PS_HA_SYNC_WORKER_NUM);
channelManager = new ChannelManager(bootstrap, workerNum);
int sendBuffSize = conf.getInt(AngelConf.ANGEL_PS_HA_SYNC_SEND_BUFFER_SIZE, AngelConf.DEFAULT_ANGEL_PS_HA_SYNC_SEND_BUFFER_SIZE);
final int maxMessageSize = conf.getInt(AngelConf.ANGEL_NETTY_MATRIXTRANSFER_MAX_MESSAGE_SIZE, AngelConf.DEFAULT_ANGEL_NETTY_MATRIXTRANSFER_MAX_MESSAGE_SIZE);
// TODO: use Epoll for linux future
/*Class channelClass = null;
String os = System.getProperty("os.name");
if(os.toLowerCase().startsWith("win")) {
LOG.info("os is windows, we use NioEventLoopGroup");
channelClass = NioSocketChannel.class;
eventGroup = new NioEventLoopGroup(nettyWorkerNum);
((NioEventLoopGroup)eventGroup).setIoRatio(70);
} else if(os.toLowerCase().startsWith("linux")) {
}
*/
eventGroup = new NioEventLoopGroup(workerNum);
((NioEventLoopGroup) eventGroup).setIoRatio(70);
bootstrap.group(eventGroup).channel(NioSocketChannel.class).option(ChannelOption.SO_SNDBUF, sendBuffSize).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 PSClientHandler());
}
});
}
Aggregations