title: Netty server - slow consumer over TCP
body: <p>I'm writing a TCP server using Netty v4. The server will handle multiple connections from clients, and stream data to them.</p>
  
  <p>I want to be able to detect when a client is consuming data at a slow ratio. I basically want to avoid the TCP buffers to get full just because a client is slow!</p>
  
  <p>It's basically what ZeroMQ does (called "Slow Subscriber Detection (Suicidal Snail Pattern)"). How can that be done using Netty?</p>
  
  <p>My current code is (I'll just show the server setup):</p>
  
  <pre><code>      ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
            .channel(NioServerSocketChannel.class)
            .option(ChannelOption.SO_BACKLOG, 1000)
            .handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(new ChannelInitializer&lt;SocketChannel&gt;() {
              @Override
              public void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                p.addLast(new Handler());
              }
            });
  
        ChannelFuture f = b.bind(8000).sync();
        f.channel().closeFuture().sync();
  </code></pre>
  
  <p>Is that wha the <code>SO_BACKLOG</code> option does? It says it's for connections being queued, but I'm interested in packets being queued for a specific connection.</p>