Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Runtime System for Generalized Committed Choice

A Runtime System for Generalized Committed Choice

Presentation @ APPLC'12 (affiliated with PLDI'12)

Xiao Jia

June 15, 2012
Tweet

Other Decks in Research

Transcript

  1. A Runtime System for Generalized Committed Choice Xiao Jia Kenny

    Q. Zhu Shanghai Jiao Tong University {xjia,kzhu}@cs.sjtu.edu.cn Joxan Jaffar Roland H.C. Yap National University of Singapore {joxan,ryap}@comp.nus.edu.sg
  2. /53 Motivation •  Online trading system •  Bob wants to

    upgrade his camera •  Jill wants to downgrade June 15, 2012 Xiao Jia <[email protected]> 4
  3. /53 •  Bob: (upgrade) 1.  buy ( good lens )

    ; sell ( average lens ) 2.  buy ( good cam ) ; sell ( average cam ) •  Jill: (downgrade) 1.  sell ( good lens ) ; buy ( average cam ) 2.  sell ( good cam ) ; buy ( average cam ) June 15, 2012 Xiao Jia <[email protected]> 5
  4. /53 •  Bob: (upgrade) 1.  buy ( good lens )

    ; sell ( average lens ) 2.  buy ( good cam ) ; sell ( average cam ) •  Jill: (downgrade) 1.  sell ( good lens ) ; buy ( average cam ) 2.  sell ( good cam ) ; buy ( average cam ) June 15, 2012 Xiao Jia <[email protected]> 6
  5. /53 •  Bob: (upgrade) 1.  buy ( good lens )

    ; sell ( average lens ) 2.  buy ( good cam ) ; sell ( average cam ) •  Jill: (downgrade) 1.  sell ( good lens ) ; buy ( average cam ) 2.  sell ( good cam ) ; buy ( average cam ) June 15, 2012 Xiao Jia <[email protected]> 7
  6. /53 •  Bob: (upgrade) 1.  buy ( good lens )

    ; sell ( average lens ) 2.  buy ( good cam ) ; sell ( average cam ) •  Jill: (downgrade) 1.  sell ( good lens ) ; buy ( average cam ) 2.  sell ( good cam ) ; buy ( average cam ) June 15, 2012 Xiao Jia <[email protected]> 8
  7. /53 •  Bob: (upgrade) 1.  buy ( good lens )

    ; sell ( average lens ) 2.  buy ( good cam ) ; sell ( average cam ) •  Jill: (downgrade) 1.  sell ( good lens ) ; buy ( average cam ) 2.  sell ( good cam ) ; buy ( average cam ) June 15, 2012 Xiao Jia <[email protected]> 9
  8. /53 •  Bob: (upgrade) 1.  buy ( good lens )

    ; sell ( average lens ) 2.  buy ( good cam ) ; sell ( average cam ) •  Jill: (downgrade) 1.  sell ( good lens ) ; buy ( average cam ) 2.  sell ( good cam ) ; buy ( average cam ) June 15, 2012 Xiao Jia <[email protected]> 10
  9. /53 The transaction can be completed only if both Bob

    and Jill choose the second choice June 15, 2012 Xiao Jia <[email protected]> 11
  10. /53 However, it is impossible for the agents to know

    the others’ choices in the context of online trading June 15, 2012 Xiao Jia <[email protected]> 12
  11. /53 June 15, 2012 Xiao Jia <[email protected]> 14 But we

    want maximal happiness among the agents
  12. /53 June 15, 2012 Xiao Jia <[email protected]> 15 What if

    we can try different combinations of the choices in isolated environments?
  13. /53 June 15, 2012 Xiao Jia <[email protected]> 16 Bob: 1.

    buy ( good lens ) sell ( average lens ) Jill: 1. sell ( good lens ) buy ( average cam ) Bob: 1. buy ( good lens ) sell ( average lens ) Jill: 2. sell ( good cam ) buy ( average cam ) Bob: 2. buy ( good cam ) sell ( average cam ) Jill: 1. sell ( good lens ) buy ( average cam ) Bob: 2. buy ( good cam ) sell ( average cam ) Jill: 2. sell ( good cam ) buy ( average cam )
  14. /53 June 15, 2012 Xiao Jia <[email protected]> 17 Bob: 1.

    buy ( good lens ) sell ( average lens ) Jill: 1. sell ( good lens ) buy ( average cam ) Bob: 1. buy ( good lens ) sell ( average lens ) Jill: 2. sell ( good cam ) buy ( average cam ) Bob: 2. buy ( good cam ) sell ( average cam ) Jill: 1. sell ( good lens ) buy ( average cam ) Bob: 2. buy ( good cam ) sell ( average cam ) Jill: 2. sell ( good cam ) buy ( average cam ) 4 speculative worlds
  15. /53 June 15, 2012 Xiao Jia <[email protected]> 18 Bob: 1.

    buy ( good lens ) sell ( average lens ) Jill: 1. sell ( good lens ) buy ( average cam ) Bob: 1. buy ( good lens ) sell ( average lens ) Jill: 2. sell ( good cam ) buy ( average cam ) Bob: 2. buy ( good cam ) sell ( average cam ) Jill: 1. sell ( good lens ) buy ( average cam ) Bob: 2. buy ( good cam ) sell ( average cam ) Jill: 2. sell ( good cam ) buy ( average cam ) REAL!  
  16. /53 Write agent programs like this June 15, 2012 Xiao

    Jia <[email protected]> 19 // bob.cc int main() { gcc(lens, cam); return 0; } void lens() { buy(GoodLens); sell(AvgLens); cm(); } void cam() { buy(GoodCam); sell(AvgCam); cm(); } // jill.cc int main() { gcc(lens, cam); return 0; } void lens() { sell(GoodLens); buy(AvgCam); cm(); } void cam() { buy(GoodCam); sell(AvgCam); cm(); } buy and sell are blocking and will be implemented in a few slides later
  17. /53 Agent programs run like this June 15, 2012 Xiao

    Jia <[email protected]> 20 Bob Bob: lens() Jill Bob: lens() Jill: lens() Bob: lens() Jill: cam() Bob: cam() Jill Bob: cam() Jill: lens() Bob: cam() Jill: cam() w1 w2 w3 w4 (Suppose Bob starts first)
  18. /53 Agent programs run like this June 15, 2012 Xiao

    Jia <[email protected]> 21 Bob Bob: lens() Jill Bob: lens() Jill: lens() Bob: lens() Jill: cam() Bob: cam() Jill Bob: cam() Jill: lens() Bob: cam() Jill: cam() w1 w2 w3 w4 (Suppose Bob starts first)
  19. /53 Programming Model = Coordination Model + Computation Model June

    15, 2012 Xiao Jia <[email protected]> 23 David Gelernter, Nicholas Carriero. Coordination languages and their significance. 1992.
  20. /53 Programming Model = Coordination Model + Computation Model June

    15, 2012 Xiao Jia <[email protected]> 24 David Gelernter, Nicholas Carriero. Coordination languages and their significance. 1992. Traditional computations like additions and multiplications …
  21. /53 Programming Model = Coordination Model + Computation Model June

    15, 2012 Xiao Jia <[email protected]> 25 David Gelernter, Nicholas Carriero. Coordination languages and their significance. 1992. For coordination of computations Sequential control flows (if/for/…) Or concurrent coordination model for multiple agents
  22. /53 Generalized Committed Choice •  A concurrent coordination model • 

    Speculation among concurrent agents by using multi-worlds •  Worlds: isolated tuple spaces June 15, 2012 Xiao Jia <[email protected]> 26
  23. /53 Generalized Committed Choice •  A concurrent coordination model • 

    Speculation among concurrent agents by using multi-worlds •  Worlds: isolated tuple spaces June 15, 2012 Xiao Jia <[email protected]> 27 (tree  structure)  
  24. /53 Generalized Committed Choice •  A concurrent coordination model • 

    Speculation among concurrent agents by using multi-worlds •  Worlds: isolated tuple spaces June 15, 2012 Xiao Jia <[email protected]> 28 (Sell, GoodLens, 123) (Sell, GoodLens, 456) (Ack, GoodCam, 789) (a  collec2on  of  tuples)   ……  
  25. /53 The Runtime System for GCC •  A central server

    for coordination •  Agent programs act as clients •  Clients communicate with the server via network connections June 15, 2012 Xiao Jia <[email protected]> 29
  26. /53 GCC Primitives gcc fork multiple choices cm commit me

    (commit to this choice) cu commit you (kill this choice) in reads and removes a tuple from a tuple space rd non-destructively reads a tuple space out produces a tuple, writing it into a tuple space June 15, 2012 Xiao Jia <[email protected]> 30
  27. /53 Write agent programs like this June 15, 2012 Xiao

    Jia <[email protected]> 31 // bob.cc int main() { gcc(lens, cam); return 0; } void lens() { buy(GoodLens); sell(AvgLens); cm(); } void cam() { buy(GoodCam); sell(AvgCam); cm(); } // jill.cc int main() { gcc(lens, cam); return 0; } void lens() { sell(GoodLens); buy(AvgCam); cm(); } void cam() { buy(GoodCam); sell(AvgCam); cm(); }
  28. /53 Example: Implement sell/buy void sell(Product t) { int id

    = get_unique_id(); out("Sell %d %d", t, id); in ("Buy _ %d", id); out("Ack %d %d", t, id); } void buy(Product t) { int id = -1; in ("Sell %d &d", t, &id); out("Buy %d %d", t, id); rd ("Ack _ %d", id); } June 15, 2012 Xiao Jia <[email protected]> 32 enum Product { GoodLens, AvgLens, GoodCam, AvgCam };
  29. /53 Example: Implement sell/buy void sell(Product t) { int id

    = get_unique_id(); out("Sell %d %d", t, id); in ("Buy _ %d", id); out("Ack %d %d", t, id); } void buy(Product t) { int id = -1; in ("Sell %d &d", t, &id); out("Buy %d %d", t, id); rd ("Ack _ %d", id); } June 15, 2012 Xiao Jia <[email protected]> 33 enum Product { GoodLens, AvgLens, GoodCam, AvgCam }; in/rd/out are primitives for tuple operations
  30. /53 Example: Implement sell/buy void sell(Product t) { int id

    = get_unique_id(); out("Sell %d %d", t, id); in ("Buy _ %d", id); out("Ack %d %d", t, id); } void buy(Product t) { int id = -1; in ("Sell %d &d", t, &id); out("Buy %d %d", t, id); rd ("Ack _ %d", id); } June 15, 2012 Xiao Jia <[email protected]> 34 enum Product { GoodLens, AvgLens, GoodCam, AvgCam }; Tuple
  31. /53 Example: Implement sell/buy void sell(Product t) { int id

    = get_unique_id(); out("Sell %d %d", t, id); in ("Buy _ %d", id); out("Ack %d %d", t, id); } void buy(Product t) { int id = -1; in ("Sell %d &d", t, &id); out("Buy %d %d", t, id); rd ("Ack _ %d", id); } June 15, 2012 Xiao Jia <[email protected]> 35 enum Product { GoodLens, AvgLens, GoodCam, AvgCam }; Tuples are in the form of (operation, product, trade id)
  32. /53 Example: Implement sell/buy void sell(Product t) { int id

    = get_unique_id(); out("Sell %d %d", t, id); in ("Buy _ %d", id); out("Ack %d %d", t, id); } void buy(Product t) { int id = -1; in ("Sell %d &d", t, &id); out("Buy %d %d", t, id); rd ("Ack _ %d", id); } June 15, 2012 Xiao Jia <[email protected]> 36 enum Product { GoodLens, AvgLens, GoodCam, AvgCam }; Underscore ( _ ) matches any value Ampersand ( & ) returns a value
  33. /53 Example: Implement sell/buy void sell(Product t) { int id

    = get_unique_id(); out("Sell %d %d", t, id); in ("Buy _ %d", id); out("Ack %d %d", t, id); } void buy(Product t) { int id = -1; in ("Sell %d &d", t, &id); out("Buy %d %d", t, id); rd ("Ack _ %d", id); } June 15, 2012 Xiao Jia <[email protected]> 37 enum Product { GoodLens, AvgLens, GoodCam, AvgCam }; Underscore ( _ ) matches any value Ampersand ( & ) returns a value Also  support  range  queries  on   tuple  elements  (e.g.  prices)   See  details  in  paper  J  
  34. /53 Agent programs run like this June 15, 2012 Xiao

    Jia <[email protected]> 39 Bob Bob: lens() Jill Bob: lens() Jill: lens() Bob: lens() Jill: cam() Bob: cam() Jill Bob: cam() Jill: lens() Bob: cam() Jill: cam() w1 w2 w3 w4
  35. /53 Exponential ! June 15, 2012 Xiao Jia <[email protected]> 40

    For 10 instances each of Bob and Jill agents, the theoretical bound is 220 worlds
  36. /53 Exponential ! June 15, 2012 Xiao Jia <[email protected]> 41

    If we can process 100 worlds per second, it will take 3 hours for only 20 agents
  37. /53 Not all the agents are trading cameras and lenses

    Other agents may trade apples and bananas June 15, 2012 Xiao Jia <[email protected]> 42
  38. /53 With multiple universe June 15, 2012 Xiao Jia <[email protected]>

    44 ……   ……   Camera  Universe   Fruits  Universe  
  39. /53 With multiple universe June 15, 2012 Xiao Jia <[email protected]>

    45 ……   ……   220 >> 210 + 210 Details in paper J Camera  Universe   Fruits  Universe  
  40. /53 10 instances of each Bob and Jill agents June

    15, 2012 Xiao Jia <[email protected]> 47 Bob-Jill cases min max Max # of worlds 11 67 Max storage (MB) 40.6 53.5 Response time (s) maximum 9.22 133.62 average 4.44 44.48 Turnaround time (s) maximum 9.23 1011.91 average 5.07 318.19
  41. /53 10 instances of each Bob and Jill agents June

    15, 2012 Xiao Jia <[email protected]> 48 Bob-Jill cases min max Max # of worlds 11 67 Max storage (MB) 40.6 53.5 Response time (s) maximum 9.22 133.62 average 4.44 44.48 Turnaround time (s) maximum 9.23 1011.91 average 5.07 318.19 Worst-­‐case   Best-­‐case  
  42. /53 10 instances of each Bob and Jill agents June

    15, 2012 Xiao Jia <[email protected]> 49 Bob-Jill cases min max Max # of worlds 11 67 Max storage (MB) 40.6 53.5 Response time (s) maximum 9.22 133.62 average 4.44 44.48 Turnaround time (s) maximum 9.23 1011.91 average 5.07 318.19 Much  smaller  than  220  
  43. /53 10 instances of each Bob and Jill agents June

    15, 2012 Xiao Jia <[email protected]> 50 Bob-Jill cases min max Max # of worlds 11 67 Max storage (MB) 40.6 53.5 Response time (s) maximum 9.22 133.62 average 4.44 44.48 Turnaround time (s) maximum 9.23 1011.91 average 5.07 318.19 Caused  by  the  opportunisEc   forking  opEmizaEon   A  tradeoff  between  usage  of   system  resources  versus  latency  
  44. /53 Conclusion •  Provide more possibilities •  Practical and realistic

    •  Independent and embeddable in mainstream languages (C/C++/…) June 15, 2012 Xiao Jia <[email protected]> 51