Package org.jgroups.protocols
Class BatchBundler
- java.lang.Object
-
- org.jgroups.protocols.NoBundler
-
- org.jgroups.protocols.BatchBundler
-
- All Implemented Interfaces:
Bundler
public class BatchBundler extends NoBundler
Bundler based onBATCH. Batches messages, keeping amax_sizefor every destination. When the accumulated size of the messages for a given destination P would exceed max_bytes, a MessageBatch is created and sent to P.
Additionally, a timer runs everyflush_intervalmilliseconds, sending messages whose size hasn't yet reached max_size.
Contrary toTransferQueueBundler, which maintains a max_size for all messages,BatchBundlermaintains it for every destination separately. This causes batches to be fuller than withTransferQueueBundler: assuming 4 members, everyone sending to everyone else, and max_size = 60000: with TransferQueueBundler, a batch is sent with ~15'000 bytes of messages (60'000/4), but with BatchBundler, it has ~60'000 bytes. Fuller batches means more amortization of costs of handling single messages.- Since:
- 5.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classBatchBundler.Bufferprotected classBatchBundler.FlushTask
-
Field Summary
Fields Modifier and Type Field Description protected longflush_intervalprotected java.util.concurrent.Future<?>flush_taskprotected Addresslocal_addrintmax_batch_sizeprotected intmax_sizeMaximum number of bytes for messages to be queued until they are sent.protected java.util.concurrent.ConcurrentMap<Address,BatchBundler.Buffer>msgMapprotected NullAddressnullAddressprotected longnum_ebs_sentprotected longnum_ebs_sent_due_to_full_queueprotected longnum_ebs_sent_due_to_max_number_of_msgsprotected longnum_ebs_sent_due_to_timeoutprotected longnum_msgs_sentprotected booleanrunningprotected TimeSchedulertimer
-
Constructor Summary
Constructors Constructor Description BatchBundler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_send(Message msg, ByteArrayDataOutputStream out)doubleavgBatchSize()voidflush()intgetCapacity()If the bundler implementation supports a capacity (e.g.intgetMaxSize()Maximum number of bytes for messages to be queued until they are sentintgetQueueSize()If the bundler has a queue and it should be managed by a queuing discipline (like Random Early Detection), then return the number of elements in the queue, else -1.voidinit(TP transport)Called after creation of the bundlervoidresetStats()voidsend(Message msg)BundlersetMaxSize(int s)intsize()The number of unsent messages in the bundlervoidstart()Called afterBundler.init(TP)protected voidstartFlushTask()voidstop()protected voidstopFlushTask()voidviewChange(View view)-
Methods inherited from class org.jgroups.protocols.NoBundler
sendSingleMessage
-
-
-
-
Field Detail
-
max_size
protected int max_size
Maximum number of bytes for messages to be queued until they are sent. This value needs to be smaller than the largest datagram packet size in case of UDP
-
flush_interval
protected long flush_interval
-
max_batch_size
public int max_batch_size
-
local_addr
protected volatile Address local_addr
-
num_msgs_sent
protected long num_msgs_sent
-
num_ebs_sent
protected long num_ebs_sent
-
num_ebs_sent_due_to_full_queue
protected long num_ebs_sent_due_to_full_queue
-
num_ebs_sent_due_to_max_number_of_msgs
protected long num_ebs_sent_due_to_max_number_of_msgs
-
num_ebs_sent_due_to_timeout
protected long num_ebs_sent_due_to_timeout
-
msgMap
protected java.util.concurrent.ConcurrentMap<Address,BatchBundler.Buffer> msgMap
-
nullAddress
protected final NullAddress nullAddress
-
timer
protected TimeScheduler timer
-
running
protected volatile boolean running
-
flush_task
protected java.util.concurrent.Future<?> flush_task
-
-
Method Detail
-
avgBatchSize
public double avgBatchSize()
-
resetStats
public void resetStats()
-
viewChange
public void viewChange(View view)
-
init
public void init(TP transport)
Description copied from interface:BundlerCalled after creation of the bundler
-
start
public void start()
Description copied from interface:BundlerCalled afterBundler.init(TP)
-
send
public void send(Message msg) throws java.lang.Exception
-
size
public int size()
Description copied from interface:BundlerThe number of unsent messages in the bundler
-
getQueueSize
public int getQueueSize()
Description copied from interface:BundlerIf the bundler has a queue and it should be managed by a queuing discipline (like Random Early Detection), then return the number of elements in the queue, else -1. In the latter case, the queue won't be managed.
This method needs to be fast as it might get called on every message to be sent.- Specified by:
getQueueSizein interfaceBundler- Overrides:
getQueueSizein classNoBundler
-
getCapacity
public int getCapacity()
Description copied from interface:BundlerIf the bundler implementation supports a capacity (e.g.RingBufferBundler, then return it, else return -1
-
getMaxSize
public int getMaxSize()
Description copied from interface:BundlerMaximum number of bytes for messages to be queued until they are sent- Specified by:
getMaxSizein interfaceBundler- Overrides:
getMaxSizein classNoBundler
-
setMaxSize
public Bundler setMaxSize(int s)
-
startFlushTask
protected void startFlushTask()
-
stopFlushTask
protected void stopFlushTask()
-
_send
protected void _send(Message msg, ByteArrayDataOutputStream out)
-
flush
public void flush()
-
-