PISTACHEA π-Calculus Internal Domain Specific Language for Scala
• PedroMatiello pmatiello@gmail.com• AnaCristina de Melo acvm@ime.usp.br• http://code.google.com/p/pistache/
INTRODUCTION• Pistacheis an implementation of the π-Calculus as a domain specific language hosted in Scala
INTRODUCTION• Itprovides π-Calculus’ abstractions for concurrent  computation within the Scala programming language
π-CALCULUS
• π-Calculus           is a formal language for describing concurrent computation with dynamic reconfiguration
• Agentscommunicate by exchanging names through channels (which are also names)• Connections between agents may change in ...
AGENTS  0             Nil α.P         PrefixP+Q           SumP|Q          Parallel(νx)P      Restriction[x=y].P      Match[...
PREFIXES_yx          Outputy(x)        Input τ          Silent
EXAMPLE• The Agents:                _ C = (νz) y(p).pz     _ S = yx.S P = x(w).α.P• The   composition: C|S|P              ...
SCALA
• Scalais a general-purpose programming language providing features both of object-oriented and functional programming
• Flexible   syntax• Statically-typed• Runs   on the Java Virtual Machine
• Actively-developed• Growing   community
PISTACHE
• Pistacheis an implementation of π-Calculus as an internal Domain Specific Language for Scala
AGENT DEFINITIONval P = Agent(...)lazy val recP:Agent = Agent(...)val restrP = Agent {    val restrictedName = Name(...)  ...
NAMESval name = Name(some_object)val name = Name[Type]name := other_objectvalue = name.value
CHANNELSval y = Link[Type]                                _y~x                             yxy(x)                         ...
SILENT TRANSITIONSval silent = Action{ doSomething() }   τ
CONCATENATIONval P = Agent { p1 * p2 * Q }   P = α.β.Q
COMPOSITIONval P = Agent { Q | R | S }   P=Q|R|S
SUMMATIONval P = Agent {    (p1 :: Q) + (p2 :: R) + (p3 :: S)   P = αQ + βR + γS}
MATCHINGval P = Agent(If (x==y) {Q})   P = [x=y] Q
EXAMPLE• The Agents:                _ C = (νz) y(p).pz     _ S = yx.S P = x(w).α.P• The   composition: C|S|P
EXAMPLEval y = Link[Link[String]]val x = Link[String]
EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent {  val p = Name[Link[String]]                          ...
EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent {  val p = Name[Link[String]]                          ...
EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent {  val p = Name[Link[String]]  y(p) * p~"message"}lazy ...
EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent {  val p = Name[Link[String]]  y(p) * p~"message"}lazy ...
MESSAGE PASSING• Channels   are implemented as shared buffers• Communication    between agents is synchronous
MESSAGE PASSING            _     Output yx                 Input y(x)Wait until y is empty   Wait until y is not empty    ...
DATA STRUCTUREval P = Agent ( p1 * p2 * p3 * Q )
DATA STRUCTUREval P = Agent ( p1 * p2 * p3 * Q )
EXECUTIONdef execute(agent:PiObject) {  agent match {    case ConcatenationAgent(left, right) => ...    case CompositionAg...
EXECUTIONcase ConcatenationAgent(left, right) =>  execute(left apply)  execute(right apply)
EXECUTIONcase CompositionAgent(left, right) =>  executeInNewThread(left apply)  executeInNewThread(right apply)
THREAD SPAWNINGdef executeInNewThread(agent:PiObject) {    val runnable = new Runnable() {      override def run() { execu...
THREAD SPAWNING•   CachedThreadPool    • Caches    finished threads    • Reuses   cached threads    • Creates   new threads...
THREAD SPAWNING    Strategy       Time consumed for 100k agents   new Thread               23 743 msCachedThreadPool      ...
CONCLUSION• We   knew that: • Concurrent   programming is hard
CONCLUSION• We   learned that: • Properabstractions can improve our understanding of  concurrency and concurrent programs
CONCLUSION• We   also learned that: • The     abstractions present in π-Calculus provide a feasible  model for concurrency...
PISTACHE     Pedro MatielloAna Cristina de Melo
Upcoming SlideShare
Loading in …5
×

Pistache: A π-Calculus Internal Domain Specific Language for Scala

397
-1

Published on

Presented at: XIV Simpósio Brasileiro de Métodos Formais (SBMF 2011), September/2011.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
397
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pistache: A π-Calculus Internal Domain Specific Language for Scala

  1. 1. PISTACHEA π-Calculus Internal Domain Specific Language for Scala
  2. 2. • PedroMatiello pmatiello@gmail.com• AnaCristina de Melo acvm@ime.usp.br• http://code.google.com/p/pistache/
  3. 3. INTRODUCTION• Pistacheis an implementation of the π-Calculus as a domain specific language hosted in Scala
  4. 4. INTRODUCTION• Itprovides π-Calculus’ abstractions for concurrent computation within the Scala programming language
  5. 5. π-CALCULUS
  6. 6. • π-Calculus is a formal language for describing concurrent computation with dynamic reconfiguration
  7. 7. • Agentscommunicate by exchanging names through channels (which are also names)• Connections between agents may change in the course of the computation
  8. 8. AGENTS 0 Nil α.P PrefixP+Q SumP|Q Parallel(νx)P Restriction[x=y].P Match[x≠y].P Mismatch
  9. 9. PREFIXES_yx Outputy(x) Input τ Silent
  10. 10. EXAMPLE• The Agents: _ C = (νz) y(p).pz _ S = yx.S P = x(w).α.P• The composition: C|S|P Example adapted from: An Introduction to the pi-Calculus, by Joachim Parrow
  11. 11. SCALA
  12. 12. • Scalais a general-purpose programming language providing features both of object-oriented and functional programming
  13. 13. • Flexible syntax• Statically-typed• Runs on the Java Virtual Machine
  14. 14. • Actively-developed• Growing community
  15. 15. PISTACHE
  16. 16. • Pistacheis an implementation of π-Calculus as an internal Domain Specific Language for Scala
  17. 17. AGENT DEFINITIONval P = Agent(...)lazy val recP:Agent = Agent(...)val restrP = Agent { val restrictedName = Name(...) ...}
  18. 18. NAMESval name = Name(some_object)val name = Name[Type]name := other_objectvalue = name.value
  19. 19. CHANNELSval y = Link[Type] _y~x yxy(x) y(x)
  20. 20. SILENT TRANSITIONSval silent = Action{ doSomething() } τ
  21. 21. CONCATENATIONval P = Agent { p1 * p2 * Q } P = α.β.Q
  22. 22. COMPOSITIONval P = Agent { Q | R | S } P=Q|R|S
  23. 23. SUMMATIONval P = Agent { (p1 :: Q) + (p2 :: R) + (p3 :: S) P = αQ + βR + γS}
  24. 24. MATCHINGval P = Agent(If (x==y) {Q}) P = [x=y] Q
  25. 25. EXAMPLE• The Agents: _ C = (νz) y(p).pz _ S = yx.S P = x(w).α.P• The composition: C|S|P
  26. 26. EXAMPLEval y = Link[Link[String]]val x = Link[String]
  27. 27. EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent { val p = Name[Link[String]] _ C = (νz) y(p).pz val z = "message" y(p) * p~z}
  28. 28. EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent { val p = Name[Link[String]] _ S = yx.S y(p) * p~"message"}lazy val S:Agent = Agent { y~x*S }
  29. 29. EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent { val p = Name[Link[String]] y(p) * p~"message"}lazy val S:Agent = Agent { y~x*S }lazy val P:Agent = Agent { val w = Name[String] P = x(w).α.P val act = Action { println(msg.value) } x(w) * act * P}
  30. 30. EXAMPLEval y = Link[Link[String]]val x = Link[String]val C = Agent { val p = Name[Link[String]] y(p) * p~"message"}lazy val S:Agent = Agent { y~x*S }lazy val P:Agent = Agent { val msg = Name[String] C|S|P val act = Action { println(msg.value) } x(msg) * act * P}new ThreadedRunner(C | S | P) start
  31. 31. MESSAGE PASSING• Channels are implemented as shared buffers• Communication between agents is synchronous
  32. 32. MESSAGE PASSING _ Output yx Input y(x)Wait until y is empty Wait until y is not empty Put x on y Put the contents of y in x Signal y not empty Signal y emptyWait until y is empty
  33. 33. DATA STRUCTUREval P = Agent ( p1 * p2 * p3 * Q )
  34. 34. DATA STRUCTUREval P = Agent ( p1 * p2 * p3 * Q )
  35. 35. EXECUTIONdef execute(agent:PiObject) { agent match { case ConcatenationAgent(left, right) => ... case CompositionAgent(left, right) => ... ... }}
  36. 36. EXECUTIONcase ConcatenationAgent(left, right) => execute(left apply) execute(right apply)
  37. 37. EXECUTIONcase CompositionAgent(left, right) => executeInNewThread(left apply) executeInNewThread(right apply)
  38. 38. THREAD SPAWNINGdef executeInNewThread(agent:PiObject) { val runnable = new Runnable() { override def run() { execute(agent) } } executor.execute(runnable)}
  39. 39. THREAD SPAWNING• CachedThreadPool • Caches finished threads • Reuses cached threads • Creates new threads if none are available • Deletesfrom the pool threads that have not been used reused for 60 seconds
  40. 40. THREAD SPAWNING Strategy Time consumed for 100k agents new Thread 23 743 msCachedThreadPool 2 089 ms
  41. 41. CONCLUSION• We knew that: • Concurrent programming is hard
  42. 42. CONCLUSION• We learned that: • Properabstractions can improve our understanding of concurrency and concurrent programs
  43. 43. CONCLUSION• We also learned that: • The abstractions present in π-Calculus provide a feasible model for concurrency in actual software programming
  44. 44. PISTACHE Pedro MatielloAna Cristina de Melo
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×