Threading Models and
the Agent Abstraction
Judd Gaddie
@juddgaddie
Shared Memory Concurrency Model
x?
x=x*2
x=x*3
x=x*4
x=x*5
x=x*6
x=x*7
x=x*8
x=x*9
x=x*10
What are all the possible values of X ?
private int x = 1
class BoundedBuffer {
synchronized void put(Object x) throws InterruptedException {
while( occupied == buffer.length )
wait();
notify();
++occupied;
putAt %= buffer.length;
buffer[putAt++] = x;
}
synchronized Object take() throws InterruptedException {
while( occupied == 0 )
wait();
notify();
--occupied;
takeAt %= buffer.length;
return buffer[takeAt++];
}
private Object[] buffer = new Object[4];
private int putAt, takeAt, occupied;
}
-- Tom Cargill
wiki.c2.com XP Challenge 14
Therac-25
“..developing, testing and debugging multithreaded programs can be
extremely difficult because concurrency bugs do not manifest themselves
predictably. And when they do surface, it is often at the worst possible time in
production, under heavy load.”
Brian Goetz - Java Concurrency in Practice
Service
Thread Thinking
English (XML)
Messages
Japanese
(JSON)
Messages
Thread Flow
Service
Service
English (XML)
Messages
Japanese
(JSON)
Messages
Thread Flow
Thread Thinking
3 Agents - Single Core
Core 1
Time
Agent1
1
Agent2
1
Agent3
1
Agent1
2
Agrona Basic Agent Framework
https://github.com/real-logic/agrona
Pay by the core
Pipelining - Agent per Core
Time
Core 2
Core 3
Core 1
Agent1
1
Agent1
2
Agent1
3
Agent1
4
Agent2
1
Agent2
2
Agent2
3
Agent3
1
Agent3
2
● No blocking calls in an Agent
● Agents must not hold on to execution cycle for too long
● Requires consistent small tasks (streaming) or a way to slice up large tasks
Limitations
Agent Agent Agent
Agent
Slow Aux Service
High Level Architecture
● Deterministic execution
● Easy reasoning
● Improved Testability
● 1 thread per core
● No kernel thread context switching
● Improved cache locality
Benefits
Thank you!
Questions?
We’re Hiring! transficc.com/careers

Agent threading model