Title: WorkManager
1WorkManager
2High Level APIs (CommonJ)
- Interface Work extends Runnable
- Interface WorkListener
- Interface WorkManager
- WorkItem schedule(Work work)
- WorkItem schedule(Work, WorkListener listener)
- waitForAll(Collection workItems, long timeout)
- waitForAny(Collection workItems, long timeout)
3Typical Invocation
- someQuery ()
- Collection pending new some collection
- SetltWorkgt work generate some work items
- For (Work w work)
- WorkItem wi workManager.schedule(w, timeout)
- pending.add(wi)
- workManager.waitForAll(pending, timeout)
4Simple Implementation
Worker
run() Work w lbq.take()
w.setStatus(ACCEPTED) w.run()
w.setStatus(COMPLETED)
Worker
Executor
Executor
LBQ
LBQ
schedule(Work w) lbq.put(w) waitForAll()
for (Work w work) if (work.completed())
SimpleWorkManager ltimplements WorkManagergt
LBQ
5Version 2.0 - Channels
- Goals
- Eliminate Lock Contention
- Send
- Receive
- Eliminate Lock Contention on work complete
- Try DMI vs. LinkedBlockingQueue
- Reimplement waitForAll() and waitForAny()
- Dynamically Adapt to Adds
- Dynamically Adapt to Removes
- Support Reschedule of Work
6Architecture - 2xMxN Channels
ChannelWorker
ChannelWorker
ChannelWorker
ChannelWorker
ChannelManager
ChannelMaster
ChannelMaster
ChannelMaster
7V2.0 - Channels
org.terracotta.channel
Interface ChannelltTgt put(T t) take(T t)
poll(T t)
Interface ChannelFactoryltTgt ChannelltTgt create()
Interface Handle
Interface ListenerltTgt event(T t)
DMIChannel
Channel Manager addChannel(Handle s, Handle d,
Channel channel) registerChannelListener(Handle
s, ListenerltChannelMessagegt l)
BatchingChannel
LBQChannel
org.terracotta.workmanager..
Interface Router MutableWorkItem
schedule(MutableWorkItem workItem)
addOutboundChannel(Channelltgt channel, Handle
destination) addReturnChannel(Channelltgt
channel, Handle source)
RoundRobinRouter
SingleRouter
ChannelMaster implements WorkManager
ChannelWorker implements Worker
NodeManager
8Master
Master M0
M0W2
M0W1
M0W0
M0W3
Router
9Worker
Worker W0
run() Work w lbq.take()
w.setStatus(ACCEPTED) w.run()
w.setStatus(COMPLETED)
Executor
LBQ
ChannelWorkItem setStatus() if (status
completed) channel.put(this)
M0W0
M1W0
M2W0
10Batching
BatchingChannelltTgt implements ChannelltTgt
put(T t) batch.put(t) if (batch.full())
flush() flush() channel.Put(batch)
batch new Batch()
batch
channel
LBQltTgt(batchSize)
ChannelltLinkedBlockingQueueltTgtgt channel
11Batching vs. Non-Batching
Batching
Batching Channel
Batch
Batch
Batch
Batch
T
T
T
T
T
T
T
T
T
T
T
T
T
T
T
T
Batching
Channel
T
T
T
T
T
T
T
T
T
T
T
T
T
T
T
T
12Usage
MASTER ChannelFactoryltBlockingQueueltChannelWorkIt
emgt batchFactory ChannelFactoryltChannelWorkItemgt
factory ChannelManagerltChannelWorkItemgt
channelManager Router router batchFactory
new BlockingQueueChannel.FactoryltBlockingQueueltCha
nnelWorkItemgtgt() factory new
BatchingChannel.FactoryltChannelWorkItemgt(100,
batchFactory) channelManager new
ChannelManagerltChannelWorkItemgt() router new
RoundRobinRouter() workManager new
ChannelMaster(channelManager, router, factory)
WORKER ChannelFactoryltChannelWorkItemgt
factory ChannelManagerltChannelWorkItemgt
channelManager factory new
BlockingQueueChannel.FactoryltChannelWorkItemgt() c
hannelManager new ChannelManagerltChannelWorkItem
gt() new CachedThreadPoolWorkExecutorltCha
nnelWorkItemgt(Executors.newCachedThreadPool(),
new ChannelWorker(channelManager,
factory)).start()
13Results
- Simple Implementation
- ??? 100s? TPS
- Channel Implementation DMI
- 1 Node 550 TPS
- Channel Implementation LBQ w/out Batching
- 1 Node 600 TPS
- 2 Nodes 750 TPS
- 3 Nodes 1000 TPS
- Channel Implementation LBQ w/Batching
- 1 Node 1000 TPS
- 2 Nodes ??? TPS
- 3 Nodes 2500 TPS
Note Results are for 2.0GHz Dual Proc Xeon,
HotSpot 1.5 JVM with no GC tuning
2.0 GHZ