This might help: https://stackoverflow.com/questions/34326230/how-to-use-channeltrafficshapinghandler-in-netty-4
Rogan On Tue, Jun 13, 2017 at 1:20 PM Zhaojie Niu <[email protected]> wrote: > Hi All: > > I am trying to control the network read/write speed with > ChannelTrafficShapingHandler provided by Netty. > > > In TransportContext.java > > I modify it as below: > > public TransportChannelHandler initializePipeline( > SocketChannel channel, > RpcHandler channelRpcHandler) { > try { > // added by zhaojie > logger.info("want to try control read bandwidth on host: " + host); > final ChannelTrafficShapingHandler channelShaping = new > ChannelTrafficShapingHandler(50, 50, 1000); > > TransportChannelHandler channelHandler = createChannelHandler(channel, > channelRpcHandler); > > channel.pipeline() > .addLast("encoder", ENCODER) > .addLast(TransportFrameDecoder.HANDLER_NAME, > NettyUtils.createFrameDecoder()) > .addLast("decoder", DECODER) > .addLast("channelTrafficShaping", channelShaping) > .addLast("idleStateHandler", new IdleStateHandler(0, 0, > conf.connectionTimeoutMs() / 1000)) > // NOTE: Chunks are currently guaranteed to be returned in the > order of request, but this > // would require more logic to guarantee if this were not part of > the same event loop. > .addLast("handler", channelHandler); > > > I create a ChannelTrafficShapingHandler and register it into the pipeline > of the channel. I set the write and read speed as 50kb/sec in the > constructor. > Except for it, what else do I need to do? > > However, it does not work. Is this idea correct? Am I missing something? > Is there any better way ? > > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "Netty discussions" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/netty/a6ce7d8a-4ef7-4f53-a8e9-fe407253ade0%40googlegroups.com > <https://groups.google.com/d/msgid/netty/a6ce7d8a-4ef7-4f53-a8e9-fe407253ade0%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Netty discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/netty/CAOYdKdi5q-uwE5QNOmT%2BbRx7YAYgXGy%2BNxf2qZKxx3NmUx8aTg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
