Embracing
                                    Concurrency
                     for Fun, Utility & Simpler Code




Michael...
Embracing
                                     Concurrency
                     for Fun, Utility & Simpler Code
          ...
Why?                             Hardware finally going
                                  massively concurrent            ...
Missing Something?
  Fundamental Control Structures
  ... in imperative languages number greater than 3! (despite what you...
Regarding using
concurrency, what sort
 of applications are we
  talking about here?


                                   ...
Speak 'n Write
Think backend               P2P Whiteboard Programming
                                                    ...
Core Approach:
   Concurrent things with comms points
   Generally send messages
   Keep data private, don't share



    ...
But I must share data?
Use Software Transactional Memory
ie version control for variables.
                        1. Chec...
Perspectives in APIs! (1/2)
    If you have concurrency it becomes
 natural to think in terms of 1st 2nd and 3rd
         ...
Perspectives in APIs! (2/2)
    If you have concurrency it becomes
 natural to think in terms of 1st 2nd and 3rd
         ...
Actor Systems
         Distinction can be unclear,
                                          private real methods
        ...
Advantages of outboxes
                                    No hardcoding of recipient
                                    ...
A Core Concurrency DSL
    Pipeline(A,B,C)
    Graphline(A=A,B=B, C=C, linkages = {})
    Tpipe(cond, C)
    Seq(A,B,C), P...
Pipeline Example
    Pipeline(
        MyGamesEventsComponent(up=quot;pquot;, down=quot;lquot;, left=quot;aquot;, right=qu...
Graphline Example
    Graphline(
      NEXT = Button(...),
      PREVIOUS = Button(...),                  PREVIOUS       N...
Server Example

                              data
                              from
                              user  ...
Server Example

                                        You therefore
                                        need to prov...
Server Example
    from Kamaelia.Chassis.ConnectedServer import ServerCore
    from Kamaelia.Util.PureTransformer import P...
Backplane Example
    # Streaming Server for raw DVB of Radio 1
    Backplane(“Radio”).activate()

    Pipeline(
       DV...
Thank you for listening!

            If you have questions, grab me later :-)




Michael Sparks
BBC R&D, http://www.kama...
Upcoming SlideShare
Loading in …5
×

Embracing concurrency for fun utility and simpler code

2,594 views

Published on

This was a talk at O'Reilly UK's "Ignite" event in leeds. It tries in 20 slides/5 minutes to give an overview of what makes concurrency actually useable and fun in general purpose languages. Whilst Kamaelia is python based, a proof of concept for the core has been done in C++, Ruby & Java, and our "introduction" tutorial teaches anyone (even complete novices) how to build their own proof of concept in python.

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
2,594
On SlideShare
0
From Embeds
0
Number of Embeds
276
Actions
Shares
0
Downloads
59
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Embracing concurrency for fun utility and simpler code

  1. 1. Embracing Concurrency for Fun, Utility & Simpler Code Michael Sparks BBC R&D, http://www.kamaelia.org/Home Ignite Leeds, Jan 2009
  2. 2. Embracing Concurrency for Fun, Utility & Simpler Code Or “what we've learnt as a part of the Kamaelia project about making concurrency something that's fun and useful, and usable by novice and advanced developers alike... ...rather than a pain in the neck” Michael Sparks BBC R&D, http://www.kamaelia.org/Home Ignite Leeds, Jan 2009
  3. 3. Why? Hardware finally going massively concurrent ... Opportunity! .... PS3, high end servers, trickling down to desktops, laptops) “many hands make light work” but Viewed as Hard ... do we just have crap tools? “And one language to in the darkness bind them” Problems ... can just we REALLY abandon 50 years of code for Erlang, Haskell and occam? Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  4. 4. Missing Something? Fundamental Control Structures ... in imperative languages number greater than 3! (despite what you get taught...!) 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 bugs This slide raises the point that teaching of imperative languages often misses out concurrency as a fundamental Michael Sparks construct, leaving a conceptual gap BBC R&D, http://www.kamaelia.org/Home for most developers
  5. 5. Regarding using concurrency, what sort of applications are we talking about here? Desktop gsoc Novice Media APPS trainee 3rd Party Network Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  6. 6. Speak 'n Write Think backend P2P Whiteboard Programming Simple needed for (logo) ER DB Modeller P2P Radio Games Kids youtube/flickr Torrent 3D Systems type systems Compose Realtime Music Desktop gsoc UGC Paint App P2P Web Server Backend Secure “phone” Transcoder Social Net Vis Novice Media ... Shot Change APPS Detection MiniAxon trainee ScriptReader Mobile DVB MediaPreview Reframing on Mobile Reliable 3rd Party Podcasts Multicast Network Macro Sedna “record XMPP XMLDB everything” AWS Email & pubsub Web (Amazon) Spam Qt SMTP IRC Serving Gtk Greylisting ClientSide microblogging AIM Pop3Proxy Spam Tools Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  7. 7. Core Approach: Concurrent things with comms points Generally send messages Keep data private, don't share outbox inbox outbox inbox signal control signal control ... ... ... ... Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  8. 8. But I must share data? Use Software Transactional Memory ie 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 1 Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  9. 9. Perspectives in APIs! (1/2) If you have concurrency it becomes natural to think in terms of 1st 2nd and 3rd 1st Person - I change my state person. This affects an API's structure, and can be vital for understanding it! This is one we've found that makes sense 2nd Person – YOU 3rd Person – want to me to do Bla should something do something (you send (I send a message) outbox inbox me a message) signal control ... ... Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  10. 10. Perspectives in APIs! (2/2) If you have concurrency it becomes natural to think in terms of 1st 2nd and 3rd private real methods person. This affects an API's structure, and can be vital for understanding it! This is one we've found that makes sense Messages sent Messages to public outboxes from public inboxes outbox inbox signal control Also, think Also, think ... ... about stdout about stdin Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  11. 11. Actor Systems Distinction can be unclear, private real methods potential source of ambiguity* Messages No outbox concept from public Possible issues with inboxes rate limiting* inbox Hardcodes recipient control in the sender ... *system dependent issue Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  12. 12. Advantages of outboxes No hardcoding of recipient allows: - Late Binding - Dynamic rewiring Concurrency Patterns as outbox inbox Reusable Code signal control ... a concurrency DSL ... ... Michael Sparks BBC 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 – they've been identified as useful, but not implemented as chassis, yet Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  14. 14. Pipeline Example Pipeline( MyGamesEventsComponent(up=quot;pquot;, down=quot;lquot;, left=quot;aquot;, right=quot;squot;), BasicSprite(quot;cat.pngquot;, name = quot;catquot;, border=40), ).activate() MyGames Events Component Basic Sprite Michael Sparks BBC 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(...), FIRST LAST IMAGE = Image(...), (button) (button) ... ).run() Chooser Image Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  16. 16. Server Example data from user data Socket handler Main to Server Core user Created at runtime to handle the connection Remote Protocol Handler Factory User Protocol handler Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  17. 17. Server Example You therefore need to provide this bit. Main Server Core Protocol Handler Factory Michael Sparks BBC 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: quot;helloquot; +x) class GreeterServer(ServerCore): protocol=greeter port=1601 GreeterServer().run() Michael Sparks BBC 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(quot;RADIOquot;), ).activate() def radio(*argv,**argd): return SubscribeTo(“RADIO”) ServerCore(protocol=radio, port=1600).run() Michael Sparks BBC R&D, http://www.kamaelia.org/Home
  20. 20. Thank you for listening! If you have questions, grab me later :-) Michael Sparks BBC R&D, http://www.kamaelia.org/Home

×