Axum

Better concurrency with a .NET language for
isolation and asynchrony
1
Axum == Maestro
“What's in a name? That which we call a rose
By any other name would smell as sweet."
Shakespeare, Romeo and Juliet (II, ii, 1-2)
2
Incubation Project
 Farther along than research
 But not yet in productization phase
 Have released internally in Microsoft
 Will soon release a public beta
3
Inspirational Quotes
“If the state of your entire universe can change from one
instant to the next, there’s something wrong with your
universe.”
“Programmers are asked to take a wildly non-deterministic
model and rein it in where needed. We should start with a
deterministic model and add non-determinism where
necessary.”
Ed Lee, UCB
4
Axum Language
 Imperative, managed language
 Looks and feels like C# or C++
 Has curly-brace!
 And a few other familiar concepts …
 Works with all .Net libraries
 Such as BCL
 Can be mixed with C# or VB.Net
 Even in the same project!
 Built on top of CCR
5
Why Another Language?
 Relying on programmer’s discipline doesn’t work
 Library solutions can only do so much
 We want strong safety enforced by the compiler
 Reduce complexity
 Concurrent by default
 “Forget” you’re writing a parallel program
 Not intended to substitute other languages
 High level orchestration in Axum
 Most of the application still written in traditional
language
6
Isolation
 Shared state is evil
 Processes in OS
 Tabs and plug-ins in Google Chrome
 Computers on the Web
 But: worms, viruses and trojans (when isolation breaks
down)
7
Main Concepts
 Domains
 Passive containers of state
 Agents
 Active components; can send messages and share state
within the same domain
 Channels and Ports
 “Pipes” that conduct messages
 A channel has a collection of ports
8
Example: Tax Calculator
public channel TaxCalculator
{
input int Income;
output int Tax;
}
public agent TaxAgent : channel TaxCalculator
{
public TaxAgent()
{
var income = receive(this.PrimaryChannel::Income);
var tax = (int)(income * GetTaxRate());
this.PrimaryChannel::Tax <-- tax;
}
}
9
Example: Tax Calculator, 2
TaxService.TaxCalculator taxCalculator =
new TaxService.TaxCalculator("TaxCalc1");
taxCalculator::Income <-- 50000;
// Do something useful while the
// taxes are being calculated...
int taxAmount = receive(taxCalculator::Tax);
10
Agents and Channels
TaxCalculator
Income
User Agent
Tax
Server Agent
11
Example: Tax Calculator, 3
 Demo:
 Simple Input/Output ports
 Request-Reply port
 Forwarding network
12
Dataflow Programming
 Execution is triggered by the availability of data
 Spreadsheet:
 Change in a cell triggers reevaluation of dependent cells;
 Independent cells can change concurrently
 Compiler:
 Characters flow through lexer turning into tokens;
 Tokens go through grammar turning into AST;
 AST goes through several passes
13
Image Processor
• Read JPG, Sharpen, Reduce “red eye” effect, Shrink, Save as
85% quality JPG
• Simple pipeline
Read
Sharpen
Red Eye
Shrink
Save
PrimaryChannel::FileName ==>
Sharpen ==> RemoveRedEye ==> Shrink ==> Save;
Contrast with:
Save(Shrink(RemoveRedEye(Sharpen(filename))));
14
Isolation
 No two stages of the pipeline can access the same
image!
 Let’s dive deeper…
15
Units Of Isolation in Axum
 Domains
 Passive containers of shared state
 Agents
 Disciplined access to domain state



Writer: can write domain state
Reader: can read domain state
No-access: cannot access domain mutable state
 True Functions


In agents, cannot modify domain and agent state
In domains, cannot modify domain state
16
Example
domain D
{
int data;
reader agent A : channel C
{
public A() {
int n = data; // OK
data = 10; // error!
}
}
function void f() {
data = 20; // error
}
}
17
Example, cont
domain D
{
int data;
const int cdata;
agent A : channel C // no-access agent
{
public A()
{
int n = data; // error
int m = cdata; // OK
}
}
}
18
Good ‘ol C++
 Const data:
const int n=1;
 Pointer to const:
int const * p = &n;
 Rule 1: Cannot modify const data
const S* ps;
*ps = s; // error
(*ps).val = 0;// error
ps->val = 10; // ditto
 Rule 2: Cannot convert pointer to const to pointer to
non-const
19
The Many Faces of Const
struct S
{
int val;
void f() const
{
val = 1; // Error!
// Translates to:
// (*this).val = 1;
}
};
20
Loophole!
struct S
{
int val;
int *ptr;
};
…
const S * ps = &s;
// error: l-value specifies const object:
ps->val = 0;
*ps->ptr = 1; // OK!
21
Example
domain D
{
int data;
reader agent A : channel C
{
public A() {
int n = parent.data; // OK, parent is readonly
parent.data = 10; // error!
}
}
function void f() {
this.data = 20; // error, this is readonly
}
}
22
Immutability in Axum
 Readonly vs. Const
 Data cannot be mutated through readonly reference.
 Const reference can only refer to immutable data (data
that never changes)
 Readonly: “I won’t break you”
 Const: “You won’t break me”
 Deep immutability
 a.b.c.d = 1; // error if one of a,b,c,d is readonly
23
Concurrency in Network
 Same model: one writer or multiple readers
 Execution scheduled in the most efficient safe way
Domain
Reader
Agent1
Writer
Agent2
No Access
Agent3
method1
m1
m2
f1
f2
m1
m2
f1
f2
m1
m2
f1
f2
method2
function1
function2
24
No Silver Bullet…
 Non-determinism
 Deadlocks
 Demo: Dining Philosophers
25
Thank you!
 We need your feedback!
 [email protected][email protected]
 Check out our blog:
 http://blogs.msdn.com/maestroteam
26