See: Description
Class | Description |
---|---|
AbstractTrafficShapingHandler |
AbstractTrafficShapingHandler allows to limit the global bandwidth
(see
GlobalTrafficShapingHandler ) or per session
bandwidth (see ChannelTrafficShapingHandler ), as traffic shaping. |
ChannelTrafficShapingHandler |
This implementation of the
AbstractTrafficShapingHandler is for channel
traffic shaping, that is to say a per channel limitation of the bandwidth.The general use should be as follow: Add in your pipeline a new ChannelTrafficShapingHandler, before a recommended ExecutionHandler (like
OrderedMemoryAwareThreadPoolExecutor or MemoryAwareThreadPoolExecutor ).ChannelTrafficShapingHandler myHandler = new ChannelTrafficShapingHandler(timer); timer could be created using HashedWheelTimer pipeline.addLast("CHANNEL_TRAFFIC_SHAPING", myHandler); Note that this handler has a Pipeline Coverage of "one" which means a new handler must be created for each new channel as the counter cannot be shared among all channels. For instance, if you have a ChannelPipelineFactory , you should create a new ChannelTrafficShapingHandler in this
ChannelPipelineFactory each time getPipeline() method is called.Other arguments can be passed like write or read limitation (in bytes/s where 0 means no limitation) or the check interval (in millisecond) that represents the delay between two computations of the bandwidth and so the call back of the doAccounting method (0 means no accounting at all). A value of 0 means no accounting for checkInterval. |
GlobalTrafficShapingHandler |
This implementation of the
AbstractTrafficShapingHandler is for global
traffic shaping, that is to say a global limitation of the bandwidth, whatever
the number of opened channels.The general use should be as follow: Create your unique GlobalTrafficShapingHandler like: GlobalTrafficShapingHandler myHandler = new GlobalTrafficShapingHandler(timer); timer could be created using HashedWheelTimer pipeline.addLast("GLOBAL_TRAFFIC_SHAPING", myHandler); Note that this handler has a Pipeline Coverage of "all" which means only one such handler must be created and shared among all channels as the counter must be shared among all channels. Other arguments can be passed like write or read limitation (in bytes/s where 0 means no limitation) or the check interval (in millisecond) that represents the delay between two computations of the bandwidth and so the call back of the doAccounting method (0 means no accounting at all). A value of 0 means no accounting for checkInterval. |
TrafficCounter |
TrafficCounter is associated with
AbstractTrafficShapingHandler .A TrafficCounter has for goal to count the traffic in order to enable to limit the traffic or not, globally or per channel. |
The main goal of this package is to allow to shape the traffic (bandwidth limitation), but also to get statistics on how many bytes are read or written. Both functions can be active or inactive (traffic or statistics).
Two classes implement this behavior:
TrafficCounter
: this class implements the counters
needed by the handlers. It can be accessed to get some extra information like the read or
write bytes since last check, the read and write bandwidth from last check...AbstractTrafficShapingHandler
: this abstract class
implements the kernel of the traffic shaping. It could be extended to fit your needs. Two
classes are proposed as default implementations: see
ChannelTrafficShapingHandler
and
GlobalTrafficShapingHandler
respectively for
Channel traffic shaping and Global traffic shaping.MemoryAwareThreadPoolExecutor
in your pipeline.MemoryAwareThreadPoolExecutor
(either non ordered or
OrderedMemoryAwareThreadPoolExecutor
) in your pipeline
when you want to use this feature with some real traffic shaping, since it will allow to relax the constraint on
NioWorker to do other jobs if necessary.ObjectSizeEstimator
can be passed at construction to specify what
is the size of the object to be read or write accordingly to the type of
object. If not specified, it will used the DefaultObjectSizeEstimator
implementation.Standard use could be as follow:
AbstractTrafficShapingHandler
.AbstractTrafficShapingHandler
or directly using the method configure of TrafficCounter
.So in your application you will create your own TrafficShapingHandler and set the values to fit your needs.
XXXXXTrafficShapingHandler myHandler = new XXXXXTrafficShapingHandler(timer);Note that a new ChannelTrafficShapingHandler
must be
created for each new channel, but only one GlobalTrafficShapingHandler
must be created for all channels.
Note also that you can create different GlobalTrafficShapingHandler if you want to separate classes of channels (for instance either from business point of view or from bind address point of view).
Copyright © 2008-2013 The Netty Project. All Rights Reserved.