260 likes | 463 Views
Axum. Better concurrency with a .NET language for isolation and asynchrony. 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). Incubation Project. Farther along than research
E N D
Axum Better concurrency with a .NET language for isolation and asynchrony
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)
Incubation Project • Farther along than research • But not yet in productization phase • Have released internally in Microsoft • Will soon release a public beta
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
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
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
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)
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
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; } }
Example: Tax Calculator, 2 TaxService.TaxCalculatortaxCalculator = new TaxService.TaxCalculator("TaxCalc1"); taxCalculator::Income <-- 50000; // Do something useful while the // taxes are being calculated... inttaxAmount = receive(taxCalculator::Tax);
Agents and Channels User Agent Server Agent TaxCalculator Income Tax
Example: Tax Calculator, 3 • Demo: • Simple Input/Output ports • Request-Reply port • Forwarding network
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
Image Processor • Read JPG, Sharpen,Reduce “red eye” effect, Shrink, Save as 85% quality JPG • Simple pipeline PrimaryChannel::FileName ==> Sharpen ==> RemoveRedEye ==> Shrink ==> Save; Contrast with: Save(Shrink(RemoveRedEye(Sharpen(filename))));
Isolation • No two stages of the pipeline can access the same image! • Let’s dive deeper…
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
Example domain D { int data; readeragent A : channel C { public A() { int n = data; // OK data = 10; // error! } } function void f() { data = 20; // error } }
Example, cont domain D { int data; const intcdata; agent A : channel C // no-access agent { public A() { int n = data; // error int m = cdata; // OK } } }
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
The Many Faces of Const struct S { intval; void f() const { val= 1; // Error! // Translates to: // (*this).val = 1; } };
Loophole! struct S { intval; int *ptr; }; … const S * ps = &s; // error: l-value specifies const object: ps->val = 0; *ps->ptr = 1; // OK!
Example domain D { int data; readeragent 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 } }
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
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 method2 m1 m1 m1 m2 m2 m2 function1 f1 f1 f1 f2 f2 f2 function2
No Silver Bullet… • Non-determinism • Deadlocks • Demo: Dining Philosophers
Thank you! • We need your feedback! • axum@microsoft.com • arturl@microsoft.com • Check out our blog: • http://blogs.msdn.com/maestroteam