Embracing                                    Concurrency                     for Fun, Utility & Simpler CodeMichael Sparks...
Embracing                                     Concurrency                     for Fun, Utility & Simpler Code             ...
Why?                             Hardware finally going              Opportunity!                                  massive...
Were Taught Wrong Fundamental Control Structures ... in imperative languages number greater than 3!      Control Structure...
Desktop            gsoc                Media                      Novice                                APPS              ...
Speak n WriteThink backend               P2P Whiteboard Programmingneeded for                                             ...
Core Approach:   Concurrent things with comms points   Generally send messages   Keep data private, dont share            ...
But I must share data?Use Software Transactional Memoryie version control for variables.                        1. Check o...
Perspectives in APIs! (1/2)   st    nd     rd 1 , 2 , 3 Person                                        1st Person - I chang...
Perspectives in APIs! (2/2)   st    nd     rd 1 , 2 , 3 Person                                           private real meth...
Actor Systems         Distinction can be unclear,         potential source of ambiguity*   private real methods Messages f...
Advantages of outboxes                                    No hardcoding of recipient                                    al...
A Core Concurrency DSL    Pipeline(A,B,C)    Graphline(A=A,B=B, C=C, linkages = {})    Tpipe(cond, C)    Seq(A,B,C), PAR()...
Pipeline Example    Pipeline(        MyGamesEventsComponent(up="p", down="l", left="a", right="s"),        BasicSprite("ca...
Graphline Example    Graphline(      NEXT = Button(...),      PREVIOUS = Button(...),                  PREVIOUS       NEXT...
Server Example                              data                              from                              user      ...
Server Example                                        You therefore                                        need to provide...
Server Example    from Kamaelia.Chassis.ConnectedServer import ServerCore    from Kamaelia.Util.PureTransformer import Pur...
Backplane Example    # Streaming Server for raw DVB of Radio 1    Backplane(“Radio”).activate()    Pipeline(       DVB_Mul...
Thank you for listening!            If you have questions, grab me later :-)Michael SparksBBC R&D, http://www.kamaelia.org...
Upcoming SlideShare
Loading in...5
×

Embracing Concurrency: For Fun, Utility & Simpler Code (Michael Sparks)

725

Published on

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
725
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Embracing Concurrency: For Fun, Utility & Simpler Code (Michael Sparks)

  1. 1. Embracing Concurrency for Fun, Utility & Simpler CodeMichael SparksBBC R&D, http://www.kamaelia.org/Home Ignite Leeds, Jan 2009
  2. 2. Embracing Concurrency for Fun, Utility & Simpler Code Or “what weve learnt as a part of the Kamaelia project about making concurrency something thats fun and useful, and usable by novice and advanced developers alike... ...rather than a pain in the neck”Michael SparksBBC R&D, http://www.kamaelia.org/Home Ignite Leeds, Jan 2009
  3. 3. Why? Hardware finally going Opportunity! massively concurrent ... .... PS3, high end servers, trickling down to desktops, laptops)“many hands make lightwork” but Viewed as Hard... do we just have crap tools? “And one language to in Problems the darkness bind them” ... can just we REALLY abandon 50 years of code for Erlang, Haskell and occam?Michael SparksBBC R&D, http://www.kamaelia.org/Home
  4. 4. Were Taught Wrong Fundamental Control Structures ... in imperative languages number greater than 3! Control Structure Traditional Abstraction Biggest Pain Points Sequence Function Global Var Selection Function Global Var Iteration Function Global Var Parallel Thread Shared Data Usually Skipped Lost or duplicate update are most common bugsMichael SparksBBC R&D, http://www.kamaelia.org/Home
  5. 5. Desktop gsoc Media Novice APPS trainee Network 3rd PartyMichael SparksBBC R&D, http://www.kamaelia.org/Home
  6. 6. Speak n WriteThink backend P2P Whiteboard Programmingneeded for Simple ER DB Modeller (logo) P2P Radio Kids Gamesyoutube/flickr Torrent 3D Systemstype systems Compose Realtime Music UGC Desktop gsoc Paint App Backend P2P Web Server Secure “phone” Transcoder Social Net Vis Media Novice ...Shot ChangeDetection APPS trainee MiniAxon ScriptReader Mobile DVB MediaPreview Reframing on Mobile Reliable Macro Podcasts Network 3rd Party Multicast Sedna “record everything” XMPP XMLDB Email & AWS pubsub Spam Web (Amazon) SMTP IRC Qt Serving Gtk Greylisting Pop3Proxy ClientSide AIM microblogging Spam ToolsMichael SparksBBC R&D, http://www.kamaelia.org/Home
  7. 7. Core Approach: Concurrent things with comms points Generally send messages Keep data private, dont share outbox inbox outbox inbox signal control signal control ... ... ... ...Michael SparksBBC R&D, http://www.kamaelia.org/Home
  8. 8. But I must share data?Use Software Transactional Memoryie version control for variables. 1. Check out the collection of values you wish to work on 2. Change them 3. Check them back in 4. If conflict/clash, go back to 1Michael SparksBBC R&D, http://www.kamaelia.org/Home
  9. 9. Perspectives in APIs! (1/2) st nd rd 1 , 2 , 3 Person 1st Person - I change my state2nd Person – YOU 3rd Person –want to me to do Bla shouldsomething do something(you send outbox (I send a message) inboxme a message) control signal ... ...Michael SparksBBC R&D, http://www.kamaelia.org/Home
  10. 10. Perspectives in APIs! (2/2) st nd rd 1 , 2 , 3 Person private real methods Messages Messages sent from public to public outboxes inboxes inbox outbox control signalAlso, think ... ... Also, thinkabout stdin about stdoutMichael SparksBBC R&D, http://www.kamaelia.org/Home
  11. 11. Actor Systems Distinction can be unclear, potential source of ambiguity* private real methods Messages from public No outbox concept inboxes Possible issues with inbox rate limiting* control Hardcodes recipient ... in the sender*system dependent issueMichael SparksBBC R&D, http://www.kamaelia.org/Home
  12. 12. Advantages of outboxes No hardcoding of recipient allows: - Late Binding - Dynamic rewiring inbox outbox Concurrency Patterns as control signal Reusable Code ... ... ... a concurrency DSLMichael SparksBBC R&D, http://www.kamaelia.org/Home
  13. 13. A Core Concurrency DSL Pipeline(A,B,C) Graphline(A=A,B=B, C=C, linkages = {}) Tpipe(cond, C) Seq(A,B,C), PAR(), ALT() Backplane(“name”), PublishTo(“name”), SubscribeTo(“name”) Carousel(...) PureTransformer(...) StatefulTransformer(...) PureServer(...) MessageDemuxer(...) Source(*messages) NullSink Some of these are work in progress – theyve been identified as useful, but not implemented as chassis, yetMichael SparksBBC R&D, http://www.kamaelia.org/Home
  14. 14. Pipeline Example Pipeline( MyGamesEventsComponent(up="p", down="l", left="a", right="s"), BasicSprite("cat.png", name = "cat", border=40), ).activate() MyGames Events Component Basic SpriteMichael SparksBBC R&D, http://www.kamaelia.org/Home
  15. 15. Graphline Example Graphline( NEXT = Button(...), PREVIOUS = Button(...), PREVIOUS NEXT FIRST = Button(...), (button) (button) LAST = Button(...), CHOOSER = Chooser(...), IMAGE = Image(...), FIRST LAST (button) (button) ... ).run() Chooser ImageMichael SparksBBC R&D, http://www.kamaelia.org/Home
  16. 16. Server Example data from user data Main Socket handler Server Core to user Created at runtime to handle the Protocol Handler Factory connection Remote Protocol handler UserMichael SparksBBC R&D, http://www.kamaelia.org/Home
  17. 17. Server Example You therefore need to provide Main this bit. Server Core Protocol Handler FactoryMichael SparksBBC R&D, http://www.kamaelia.org/Home
  18. 18. Server Example from Kamaelia.Chassis.ConnectedServer import ServerCore from Kamaelia.Util.PureTransformer import PureTransformer def greeter(*argv, **argd): return PureTransformer(lambda x: "hello" +x) class GreeterServer(ServerCore): protocol=greeter port=1601 GreeterServer().run()Michael SparksBBC R&D, http://www.kamaelia.org/Home
  19. 19. Backplane Example # Streaming Server for raw DVB of Radio 1 Backplane(“Radio”).activate() Pipeline( DVB_Multiplex(850.16, [6210], feparams), # RADIO ONE PublishTo("RADIO"), ).activate() def radio(*argv,**argd): return SubscribeTo(“RADIO”) ServerCore(protocol=radio, port=1600).run()Michael SparksBBC R&D, http://www.kamaelia.org/Home
  20. 20. Thank you for listening! If you have questions, grab me later :-)Michael SparksBBC R&D, http://www.kamaelia.org/Home
  1. A particular slide catching your eye?

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

×