Search in sources :

Example 1 with ByteBufAllocatorMetricProvider

use of io.netty.buffer.ByteBufAllocatorMetricProvider in project zuul by Netflix.

the class Server method start.

public void start() {
    serverGroup = new ServerGroup("Salamander", eventLoopConfig.acceptorCount(), eventLoopConfig.eventLoopCount(), eventLoopGroupMetrics);
    serverGroup.initializeTransport();
    try {
        List<ChannelFuture> allBindFutures = new ArrayList<>(addressesToInitializers.size());
        // Setup each of the channel initializers on requested ports.
        for (Map.Entry<NamedSocketAddress, ? extends ChannelInitializer<?>> entry : addressesToInitializers.entrySet()) {
            NamedSocketAddress requestedNamedAddr = entry.getKey();
            ChannelFuture nettyServerFuture = setupServerBootstrap(requestedNamedAddr, entry.getValue());
            Channel chan = nettyServerFuture.channel();
            addressesToChannels.put(requestedNamedAddr.withNewSocket(chan.localAddress()), chan);
            allBindFutures.add(nettyServerFuture);
        }
        // Add metrics to monitor that allocator's memory usage.
        if (!allBindFutures.isEmpty()) {
            ByteBufAllocator alloc = allBindFutures.get(0).channel().alloc();
            if (alloc instanceof ByteBufAllocatorMetricProvider) {
                ByteBufAllocatorMetric metrics = ((ByteBufAllocatorMetricProvider) alloc).metric();
                PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "heap")).monitorValue(metrics, ByteBufAllocatorMetric::usedHeapMemory);
                PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "direct")).monitorValue(metrics, ByteBufAllocatorMetric::usedDirectMemory);
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ByteBufAllocatorMetric(io.netty.buffer.ByteBufAllocatorMetric) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) ByteBufAllocatorMetricProvider(io.netty.buffer.ByteBufAllocatorMetricProvider) IOUringServerSocketChannel(io.netty.incubator.channel.uring.IOUringServerSocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) KQueueSocketChannel(io.netty.channel.kqueue.KQueueSocketChannel) IOUringSocketChannel(io.netty.incubator.channel.uring.IOUringSocketChannel) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 ByteBufAllocatorMetric (io.netty.buffer.ByteBufAllocatorMetric)1 ByteBufAllocatorMetricProvider (io.netty.buffer.ByteBufAllocatorMetricProvider)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ServerChannel (io.netty.channel.ServerChannel)1 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)1 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)1 KQueueServerSocketChannel (io.netty.channel.kqueue.KQueueServerSocketChannel)1 KQueueSocketChannel (io.netty.channel.kqueue.KQueueSocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 IOUringServerSocketChannel (io.netty.incubator.channel.uring.IOUringServerSocketChannel)1 IOUringSocketChannel (io.netty.incubator.channel.uring.IOUringSocketChannel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1