Search in sources :

Example 31 with DefaultThreadFactory

use of io.netty.util.concurrent.DefaultThreadFactory in project dubbo by alibaba.

the class Server method start.

/**
 * start server, bind port
 */
public void start() throws Throwable {
    if (!hasStarted.compareAndSet(false, true)) {
        return;
    }
    boss = new NioEventLoopGroup(0, new DefaultThreadFactory("qos-boss", true));
    worker = new NioEventLoopGroup(0, new DefaultThreadFactory("qos-worker", true));
    ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(boss, worker);
    serverBootstrap.channel(NioServerSocketChannel.class);
    serverBootstrap.childOption(ChannelOption.TCP_NODELAY, true);
    serverBootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    serverBootstrap.childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ch.pipeline().addLast(new QosProcessHandler(welcome, acceptForeignIp));
        }
    });
    try {
        serverBootstrap.bind(port).sync();
        logger.info("qos-server bind localhost:" + port);
    } catch (Throwable throwable) {
        logger.error("qos-server can not bind localhost:" + port, throwable);
        throw throwable;
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) QosProcessHandler(com.alibaba.dubbo.qos.server.handler.QosProcessHandler) Channel(io.netty.channel.Channel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 32 with DefaultThreadFactory

use of io.netty.util.concurrent.DefaultThreadFactory in project bookkeeper by apache.

the class BookieClientTest method setUp.

@Before
public void setUp() throws Exception {
    tmpDir = IOUtils.createTempDir("bookieClient", "test");
    // Since this test does not rely on the BookKeeper client needing to
    // know via ZooKeeper which Bookies are available, okay, so pass in null
    // for the zkServers input parameter when constructing the BookieServer.
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    conf.setBookiePort(port).setJournalDirName(tmpDir.getPath()).setLedgerDirNames(new String[] { tmpDir.getPath() }).setZkServers(null);
    bs = new BookieServer(conf);
    bs.start();
    eventLoopGroup = new NioEventLoopGroup();
    executor = OrderedExecutor.newBuilder().name("BKClientOrderedSafeExecutor").numThreads(2).build();
    scheduler = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("BookKeeperClientScheduler"));
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Before(org.junit.Before)

Example 33 with DefaultThreadFactory

use of io.netty.util.concurrent.DefaultThreadFactory in project bookkeeper by apache.

the class PrometheusMetricsProvider method start.

@Override
public void start(Configuration conf) {
    int httpPort = conf.getInt(PROMETHEUS_STATS_HTTP_PORT, DEFAULT_PROMETHEUS_STATS_HTTP_PORT);
    InetSocketAddress httpEndpoint = InetSocketAddress.createUnresolved("0.0.0.0", httpPort);
    this.server = new Server(httpEndpoint);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new PrometheusServlet(this)), "/metrics");
    try {
        server.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // Include standard JVM stats
    new StandardExports().register(registry);
    new MemoryPoolsExports().register(registry);
    new GarbageCollectorExports().register(registry);
    new ThreadExports().register(registry);
    // Add direct memory allocated through unsafe
    Gauge.build("jvm_memory_direct_bytes_used", "-").create().setChild(new Child() {

        @Override
        public double get() {
            return directMemoryUsage != null ? directMemoryUsage.longValue() : Double.NaN;
        }
    }).register(registry);
    Gauge.build("jvm_memory_direct_bytes_max", "-").create().setChild(new Child() {

        @Override
        public double get() {
            return PlatformDependent.maxDirectMemory();
        }
    }).register(registry);
    executor = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("metrics"));
    int latencyRolloverSeconds = conf.getInt(PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS, DEFAULT_PROMETHEUS_STATS_LATENCY_ROLLOVER_SECONDS);
    executor.scheduleAtFixedRate(() -> {
        rotateLatencyCollection();
    }, 1, latencyRolloverSeconds, TimeUnit.SECONDS);
    log.info("Started Prometheus stats endpoint at {}", httpEndpoint);
}
Also used : Server(org.eclipse.jetty.server.Server) StandardExports(io.prometheus.client.hotspot.StandardExports) ThreadExports(io.prometheus.client.hotspot.ThreadExports) InetSocketAddress(java.net.InetSocketAddress) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) IOException(java.io.IOException) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) GarbageCollectorExports(io.prometheus.client.hotspot.GarbageCollectorExports) MemoryPoolsExports(io.prometheus.client.hotspot.MemoryPoolsExports) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Child(io.prometheus.client.Gauge.Child)

Example 34 with DefaultThreadFactory

use of io.netty.util.concurrent.DefaultThreadFactory in project bookkeeper by apache.

the class BookieClient method main.

/**
 * @param args
 * @throws IOException
 * @throws NumberFormatException
 * @throws InterruptedException
 */
public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
    if (args.length != 3) {
        System.err.println("USAGE: BookieClient bookieHost port ledger#");
        return;
    }
    WriteCallback cb = new WriteCallback() {

        public void writeComplete(int rc, long ledger, long entry, BookieSocketAddress addr, Object ctx) {
            Counter counter = (Counter) ctx;
            counter.dec();
            if (rc != 0) {
                System.out.println("rc = " + rc + " for " + entry + "@" + ledger);
            }
        }
    };
    Counter counter = new Counter();
    byte[] hello = "hello".getBytes(UTF_8);
    long ledger = Long.parseLong(args[2]);
    EventLoopGroup eventLoopGroup = new NioEventLoopGroup(1);
    OrderedExecutor executor = OrderedExecutor.newBuilder().name("BookieClientWorker").numThreads(1).build();
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("BookKeeperClientScheduler"));
    BookieClient bc = new BookieClient(new ClientConfiguration(), eventLoopGroup, executor, scheduler, NullStatsLogger.INSTANCE);
    BookieSocketAddress addr = new BookieSocketAddress(args[0], Integer.parseInt(args[1]));
    for (int i = 0; i < 100000; i++) {
        counter.inc();
        bc.addEntry(addr, ledger, new byte[0], i, ByteBufList.get(Unpooled.wrappedBuffer(hello)), cb, counter, 0);
    }
    counter.wait(0);
    System.out.println("Total = " + counter.total());
    scheduler.shutdown();
    eventLoopGroup.shutdownGracefully();
    executor.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WriteCallback(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback) OrderedExecutor(org.apache.bookkeeper.common.util.OrderedExecutor) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration)

Example 35 with DefaultThreadFactory

use of io.netty.util.concurrent.DefaultThreadFactory in project bookkeeper by apache.

the class BookKeeper method getDefaultEventLoopGroup.

static EventLoopGroup getDefaultEventLoopGroup() {
    ThreadFactory threadFactory = new DefaultThreadFactory("bookkeeper-io");
    final int numThreads = Runtime.getRuntime().availableProcessors() * 2;
    if (SystemUtils.IS_OS_LINUX) {
        try {
            return new EpollEventLoopGroup(numThreads, threadFactory);
        } catch (Throwable t) {
            LOG.warn("Could not use Netty Epoll event loop for bookie server: {}", t.getMessage());
            return new NioEventLoopGroup(numThreads, threadFactory);
        }
    } else {
        return new NioEventLoopGroup(numThreads, threadFactory);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)49 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)24 EventLoopGroup (io.netty.channel.EventLoopGroup)15 ThreadFactory (java.util.concurrent.ThreadFactory)12 ChannelFuture (io.netty.channel.ChannelFuture)9 ExecutorService (java.util.concurrent.ExecutorService)8 Test (org.junit.jupiter.api.Test)8 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)7 IOException (java.io.IOException)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)6 UdtChannel (io.netty.channel.udt.UdtChannel)6 LoggingHandler (io.netty.handler.logging.LoggingHandler)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)5 Channel (io.netty.channel.Channel)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Timeout (org.junit.jupiter.api.Timeout)5 Test (org.testng.annotations.Test)5 ParameterException (com.beust.jcommander.ParameterException)4