Better concurrency with a.NET language for isolation and asynchrony 1.

26
Axum Better concurrency with a .NET language for isolation and asynchrony 1

Transcript of Better concurrency with a.NET language for isolation and asynchrony 1.

  • Slide 1

Better concurrency with a.NET language for isolation and asynchrony 1 Slide 2 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 Slide 3 Incubation Project Farther along than research But not yet in productization phase Have released internally in Microsoft Will soon release a public beta 3 Slide 4 Inspirational Quotes If the state of your entire universe can change from one instant to the next, theres 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 Slide 5 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 Slide 6 Why Another Language? Relying on programmers discipline doesnt work Library solutions can only do so much We want strong safety enforced by the compiler Reduce complexity Concurrent by default Forget youre 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 Slide 7 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 Slide 8 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 Slide 9 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 Image Processor ReadSharpenRed EyeShrinkSave 14 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)))); Slide 15 Isolation No two stages of the pipeline can access the same image! Lets dive deeper 15 Slide 16 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 Slide 17 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 Slide 18 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 Slide 19 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 Slide 20 The Many Faces of Const struct S { int val; void f() const { val = 1; // Error! // Translates to: // (*this).val = 1; } }; 20 Slide 21 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 Slide 22 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 Slide 23 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 wont break you Const: You wont break me Deep immutability a.b.c.d = 1; // error if one of a,b,c,d is readonly 23 Slide 24 Concurrency in Network Same model: one writer or multiple readers Execution scheduled in the most efficient safe way 24 Domain Reader Agent1 method1 method2 function1 function2 m1 m2 f1 f2 Writer Agent2 m1 m2 f1 f2 No Access Agent3 m1 m2 f1 f2 Slide 25 No Silver Bullet Non-determinism Deadlocks Demo: Dining Philosophers 25 Slide 26 Thank you! We need your feedback! [email protected] [email protected] Check out our blog: http://blogs.msdn.com/maestroteam 26