Search in sources :

Example 1 with ChannelManager

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));
        }
    });
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) ChannelManager(com.tencent.angel.common.transport.ChannelManager) Configuration(org.apache.hadoop.conf.Configuration) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) ServiceException(com.google.protobuf.ServiceException) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Bootstrap(io.netty.bootstrap.Bootstrap) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 2 with ChannelManager

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());
        }
    });
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) ChannelManager(com.tencent.angel.common.transport.ChannelManager) Configuration(org.apache.hadoop.conf.Configuration) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) Bootstrap(io.netty.bootstrap.Bootstrap) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

ChannelManager (com.tencent.angel.common.transport.ChannelManager)2 Bootstrap (io.netty.bootstrap.Bootstrap)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)2 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)2 Configuration (org.apache.hadoop.conf.Configuration)2 ServiceException (com.google.protobuf.ServiceException)1