sociable software

79
Sociable Software (or “how you really already know how to make concurrency for multicore easy to work with”) http://kamaelia.sourceforge.net/Developers/ Michael Sparks [email protected] BBC Research & Innovation

Upload: kamaelian

Post on 06-May-2015

4.821 views

Category:

Business


1 download

DESCRIPTION

This presentation aims to show people that they already know how to deal with concurrency. It argues that if we have the tools for large scale concurrency (mashups) and small scale (hardware) that midrange (normal apps) can be done in a similar way, using existing tools. This is done by showing useful systems that have been produced in this manner using existing tools. ie from existing practice, not theory During the actual presentation I also talked about Kamaelia projects created by novice programmers of varying ability which show high levels of concurrency. These include: previewing PVR content on mobiles, multicast island joining, as-live streaming using bit torrent, Open GL based user interfaces & integration, seaside style webserving, speex based secure phone, IRC/IM systems, a shakespeare script player, and games tools. Other systems created include Atom/RSS routing, memcached integration, P2P whiteboarding (with audio + mixing), gesture recognition, presentation tools, a kids development environment, topology visualisation tools, database modelling etc.

TRANSCRIPT

Page 1: Sociable Software

Sociable Software(or “how you really already knowhow to make concurrency for multicoreeasy to work with”)

http://kamaelia.sourceforge.net/Developers/

Michael [email protected]

BBC Research & Innovation

Page 2: Sociable Software

This presentation aims to show people that they already knowhow to deal with concurrency.

It argues that if we have the tools for large scale concurrency(mashups) and small scale (hardware) that midrange (normalapps) can be done in a similar way, using existing tools.

This is done by showing useful systems that have been producedin this manner using existing tools.

ie from existing practice, not theory

http://kamaelia.sourceforge.net/Developers/ [email protected]

Note added after barcamp

Page 3: Sociable Software

During the actual presentation I also talked about Kamaeliaprojects created by novice programmers of varying ability whichshow high levels of concurrency.

These include: previewing PVR content on mobiles, multicastisland joining, as-live streaming using bit torrent, Open GL baseduser interfaces & integration, seaside style webserving, speexbased secure phone, IRC/IM systems, a shakespeare scriptplayer, and games tools.

Other systems created include Atom/RSS routing, memcachedintegration, P2P whiteboarding (with audio + mixing), gesturerecognition, presentation tools, a kids development environment,topology visualisation tools, database modelling etc.

http://kamaelia.sourceforge.net/Developers/ [email protected]

Note added after barcamp

Page 4: Sociable Software

Sociable Software

Core idea : “building systems that are made of many software systems that are sociable with each other”

(yes, this project did start at work, but I am primarily working on it in my own time at present due to a resource crunch :)

Page 5: Sociable Software

Sociable Software

ie it's comprised of systems that

talk to each other.

ie are sociable.

Page 6: Sociable Software

Comfortable examples

Page 7: Sociable Software

Web Browser

Web Serverresponse

request

Page 8: Sociable Software

Web Browser

Web Server

request

RSS/Atom Feed

More sociable:

Page 9: Sociable Software

Web Browser

Web Server

request

RSS/Atom Feed

More sociable:

Kinda like your facebook mini-feed

Page 10: Sociable Software

Web Browser

General principle

Web Server

RSS/Atom Feed

Web Server

RSS/Atom Feed

Web Server

RSS/Atom Feed

Page 11: Sociable Software

Mash ups(next logical step)

Page 12: Sociable Software

Basic client side mashup

Web Server

Atom Feed

Web Server

Web API

Web Server

Someclient

RSS Feed

Page 13: Sociable Software

Basic client side mashup

Web Server

Atom Feed

Web Server

Web API

Web Server

Someclient

RSS Feed

Example: Google Ads

Page 14: Sociable Software

Basic client side mashup

Web Server

Atom Feed

Web Server

Web API

Web Server

Someclient

RSS Feed

Example: Google Ads Or any similar sort of system ie using Javascript for transcludes

Page 15: Sociable Software

Mashup as a service

Someclient

Web Server

Atom Feed

Web Server

Web API

Web Server

Web Server

RSS Feed

Page 16: Sociable Software

Mashup as a service

Someclient

Web Server

Atom Feed

Web Server

Web API

Web Server

Web Server

RSS Feed

Example: gmap-pedometer

Page 17: Sociable Software

Someclient

Web Server

Atom Feed

Web Server

Web API

Web Server

Web Server

RSS Feed

Service

More generally

Page 18: Sociable Software

Go Crazy(next logical step)

Page 19: Sociable Software

Web Server

Web Server

Web Server

RSS Feed

Web Server

Atom Feed

Web Server

Web Server

RSS Feed

Web Server

Web Server

RSS Feed

Web API Web API

Web API

Web API Web API

Web ServerWeb API

Web Server

Service

Web Server

Service

`

Atom Feed

Page 20: Sociable Software

Do you really think of it that way?

Page 21: Sociable Software
Page 22: Sociable Software

Got that?(pretty common stuff yes?)

Page 23: Sociable Software

Let's look at something completely

different.

Page 24: Sociable Software

Formal verification of asynchronous hardware

(Rainbow project, Manchester Uni. ~10 years old)

Page 25: Sociable Software

Doesn't really look so very different does it?

Page 26: Sociable Software

Even complex examples look similar.

Page 27: Sociable Software

Why?

Page 28: Sociable Software

They're comprised of systems that

talk to each other.

Page 29: Sociable Software

So what?

Page 30: Sociable Software

Both represent concurrent systems.

One is very high level.

One is incredibly low level.

The low level has the best tools and builds on decades of experience of making things simpler.

They've made their lives easier

Page 31: Sociable Software

green Pipeline() = Random() >> buffer(1) >> Invert() >> buffer(1) >> Invert() >> buffer(1) >> sinkend

Page 32: Sociable Software

green Substituter() = chan thevalue,istwelve end function test(value x:integer) : boolean = x==12 end Random() >> thevalue >> test() >> istwelve$ thevalue >> if istwelve then sink$ source 0 >> else {} end_if >> sinkend

Page 33: Sociable Software

Um?green Substituter() = chan thevalue,istwelve end function test(value x:integer) : boolean = x==12 end Random() >> thevalue >> test() >> istwelve$ thevalue >> if istwelve then sink$ source 0 >> else {} end_if >> sinkend

Page 34: Sociable Software

Um?

That looks like software!

green Substituter() = chan thevalue,istwelve end function test(value x:integer) : boolean = x==12 end Random() >> thevalue >> test() >> istwelve$ thevalue >> if istwelve then sink$ source 0 >> else {} end_if >> sinkend

Page 35: Sociable Software

Can we write software that way

and still have it perform well,

and gain the same benefits?

Page 36: Sociable Software

YES!

Page 37: Sociable Software

Examples

Page 38: Sociable Software

Examples

I am only going to show you non-trivial examples

For more trivial examples, please look at the slides uploaded to slideshare.net/kamaelian and also the Kamaelia cookbook.

Page 39: Sociable Software

Examples

Email Greylisting Server: Kamaelia Grey

Specifically written to deal with the ever growing spam problem I was facing

Has eradicated my spam problem on my home server.

Page 40: Sociable Software

Examples

Email Greylisting Server:

TCPServer

GreylistServer

Selector

outbox

inbox

outbox

inbox

Page 41: Sociable Software

Examples

Email Greylisting Server: New Connection

TCPServer

GreylistServer

Selector

ConnectedSocketAdapter

GreyListingPolicy

outbox

inbox

outbox

inbox

inbox

inboxoutbox

outbox

inbox

inbox

inboxoutbox

inboxoutbox

outbox

Page 42: Sociable Software

Examples

Email Greylisting Server: Many Connections

TCPServer

GreylistServer

Selector

ConnectedSocketAdapter

ConnectedSocketAdapter

ConnectedSocketAdapter

GreyListingPolicy

GreyListingPolicy

GreyListingPolicy

Page 43: Sociable Software

Examples

Email Greylisting Core Code:class GreylistServer(MoreComplexServer): logfile = config["greylist_log"] ... port = config["port"] socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

class TCPS(TCPServer): CSA = NoActivityTimeout(ConnectedSocketAdapter, timeout=config["inactivity_timeout"])

class protocol(GreyListingPolicy): servername = config["servername"] smtp_ip = config["smtp_ip"] smtp_port = config["smtp_port"] ...

Page 44: Sociable Software

Examples

Email Greylisting Core Code:class GreylistServer(MoreComplexServer): logfile = config["greylist_log"] ... port = config["port"] socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

class TCPS(TCPServer): CSA = NoActivityTimeout(ConnectedSocketAdapter, timeout=config["inactivity_timeout"])

class protocol(GreyListingPolicy): servername = config["servername"] smtp_ip = config["smtp_ip"] smtp_port = config["smtp_port"] ...

TCPServer

GreylistServer

Selector

ConnectedSocketAdapter

GreyListingPolicy

Page 45: Sociable Software

Examples

Email Greylisting Core Code:class GreylistServer(MoreComplexServer): logfile = config["greylist_log"] ... port = config["port"] socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

class TCPS(TCPServer): CSA = NoActivityTimeout(ConnectedSocketAdapter, timeout=config["inactivity_timeout"])

class protocol(GreyListingPolicy): servername = config["servername"] smtp_ip = config["smtp_ip"] smtp_port = config["smtp_port"] ...

TCPServer

GreylistServer

Selector

ConnectedSocketAdapter

GreyListingPolicy

Page 46: Sociable Software

Examples

Email Greylisting Core Code:class GreylistServer(MoreComplexServer): logfile = config["greylist_log"] ... port = config["port"] socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

class TCPS(TCPServer): CSA = NoActivityTimeout(ConnectedSocketAdapter, timeout=config["inactivity_timeout"])

class protocol(GreyListingPolicy): servername = config["servername"] smtp_ip = config["smtp_ip"] smtp_port = config["smtp_port"] ...

TCPServer

GreylistServer

Selector

ConnectedSocketAdapter

GreyListingPolicy

Page 47: Sociable Software

Examples

Email Greylisting Core Code:class GreylistServer(MoreComplexServer): logfile = config["greylist_log"] ... port = config["port"] socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

class TCPS(TCPServer): CSA = NoActivityTimeout(ConnectedSocketAdapter, timeout=config["inactivity_timeout"])

class protocol(GreyListingPolicy): servername = config["servername"] smtp_ip = config["smtp_ip"] smtp_port = config["smtp_port"] ...

TCPServer

GreylistServer

Selector

ConnectedSocketAdapter

GreyListingPolicy

Page 48: Sociable Software

Examples

Email Greylisting Core Code:class GreylistServer(MoreComplexServer): logfile = config["greylist_log"] ... port = config["port"] socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

class TCPS(TCPServer): CSA = NoActivityTimeout(ConnectedSocketAdapter, timeout=config["inactivity_timeout"])

class protocol(GreyListingPolicy): servername = config["servername"] smtp_ip = config["smtp_ip"] smtp_port = config["smtp_port"] ...

TCPServer

GreylistServer

Selector

ConnectedSocketAdapter

GreyListingPolicy

Page 49: Sociable Software

Slightly less obvious than normal, but these functions together form a factory.

TCPServer

GreylistServer

Selector

outbox

inbox

outbox

inbox

Page 50: Sociable Software

TCPServer

GreylistServer

Selector

Slightly less obvious than normal, but these functions together form a factory... so as to create new things to handle connections:

ConnectedSocketAdapter

GreyListingPolicy

Page 51: Sociable Software

TCPServer

GreylistServer

Selector

Slightly less obvious than normal, but these functions together form a factory... so as to create new things to handle connections:

ConnectedSocketAdapter

ConnectedSocketAdapter

GreyListingPolicy

GreyListingPolicy

Page 52: Sociable Software

TCPServer

GreylistServer

Selector

Slightly less obvious than normal, but these functions together form a factory... so as to create new things to handle connections:

ConnectedSocketAdapter

ConnectedSocketAdapter

ConnectedSocketAdapter

GreyListingPolicy

GreyListingPolicy

GreyListingPolicy

Page 53: Sociable Software

Examples

Kamaelia ER Modeller

Page 54: Sociable Software

Examples

Kamaelia ER Modeller

Intended for use in designing

databases. Created last

year because I had an

urgent need.

About a ½ day hack.

Page 55: Sociable Software

Examples

Kamaelia ER Modeller : Simple Example

entity missionagententity person(missionagent)entity team(missionagent)

entity missionitem: simpleattributes visible

entity activemission

relation participatesin(activemission,missionagent)relation creates(missionagent,missionitem)

Page 56: Sociable Software

Examples

Kamaelia ER Modeller : More Complex Example

entity missionagententity person(missionagent): simpleattributes nameentity team(missionagent): simpleattributes teamnameentity missionentity activemissionrelation participatesin(activemission,missionagent)entity missionitem: simpleattributes visiblerelation creates(missionagent,missionitem)relation updates(missionagent,missionitem)entity textfrag(atomicitem)entity externalurl(atomicitem)...

Page 57: Sociable Software

Examples

Kamaelia ER Modeller : Internals

Backplane(“TOPOLOGY”)

Pipeline

Console Reader

PublishTo(“TOPOLOGY”)

Pipeline

FileReader

PublishTo(“TOPOLOGY”)

ERParser

ERModel2Visualiser

Pipeline

ConsoleEchoer

SubscribeTo(“TOPOLOGY”)

ERVisualiser

lines_to_tokenlists

Page 58: Sociable Software

Examples

Kamaelia ER Modeller : Internals

Backplane(“TOPOLOGY”)

Pipeline

Console Reader

PublishTo(“TOPOLOGY”)

Pipeline

FileReader

PublishTo(“TOPOLOGY”)

ERParser

ERModel2Visualiser

Pipeline

ConsoleEchoer

SubscribeTo(“TOPOLOGY”)

ERVisualiser

lines_to_tokenlists

Backplane("TOPOLOGY").activate()

Page 59: Sociable Software

Examples

Kamaelia ER Modeller : Internals

Backplane(“TOPOLOGY”)

Pipeline

Console Reader

PublishTo(“TOPOLOGY”)

Pipeline

FileReader

PublishTo(“TOPOLOGY”)

ERParser

ERModel2Visualiser

Pipeline

ConsoleEchoer

SubscribeTo(“TOPOLOGY”)

ERVisualiser

lines_to_tokenlists

Pipeline( ConsoleReader(">>> "), PublishTo("TOPOLOGY"), ).activate()

Page 60: Sociable Software

Examples

Kamaelia ER Modeller : Internals

Backplane(“TOPOLOGY”)

Pipeline

Console Reader

PublishTo(“TOPOLOGY”)

Pipeline

ConsoleEchoer

SubscribeTo(“TOPOLOGY”)

ERVisualiser

lines_to_tokenlists

Pipeline

FileReader

PublishTo(“TOPOLOGY”)

ERParser

ERModel2Visualiser

Pipeline( ReadFileAdaptor(sys.argv[1]), ERParser(), ERModel2Visualiser(), PublishTo("TOPOLOGY"), ).activate()

Page 61: Sociable Software

Examples

Kamaelia ER Modeller : Internals

Backplane(“TOPOLOGY”)

Pipeline

Console Reader

PublishTo(“TOPOLOGY”)

Pipeline

FileReader

PublishTo(“TOPOLOGY”)

ERParser

ERModel2Visualiser

Pipeline

ConsoleEchoer

SubscribeTo(“TOPOLOGY”)

ERVisualiser

lines_to_tokenlists

Pipeline( SubscribeTo("TOPOLOGY"), lines_to_tokenlists(), ERVisualiser( screensize = (1024,768), fullscreen = True ), ConsoleEchoer(), ).run()

Page 62: Sociable Software

Examples

Kamaelia ER Modeller : Internals

Backplane(“TOPOLOGY”)

Pipeline

Console Reader

PublishTo(“TOPOLOGY”)

Pipeline

FileReader

PublishTo(“TOPOLOGY”)

ERParser

ERModel2Visualiser

Pipeline

ConsoleEchoer

SubscribeTo(“TOPOLOGY”)

ERVisualiser

lines_to_tokenlists

Backplane("TOPOLOGY").activate()

Pipeline( ConsoleReader(">>> "), PublishTo("TOPOLOGY"),).activate()

Pipeline( ReadFileAdaptor(sys.argv[1]), ERParser(), ERModel2Visualiser(), PublishTo("TOPOLOGY"),).activate()

Pipeline( SubscribeTo("TOPOLOGY"), lines_to_tokenlists(), ERVisualiser(screensize = (1024,768), fullscreen = True), ConsoleEchoer(),).run()

Page 63: Sociable Software

Examples

Kamaelia Macro

Page 64: Sociable Software

Examples

Kamaelia Macro

It records and transcodes what is broadcast over DTT for future viewing.

Page 65: Sociable Software

Examples

Kamaelia Macro

It records and transcodes what is broadcast over DTT for future viewing.

     17A.  ­ (1) The making in domestic premises for private and domestic use of a recording of a broadcast solely for the purpose of enabling it to be viewed or listened to at a more convenient time does not infringe any right conferred by Part 2 in relation to a performance or recording included in the broadcast.

­­ Timeshifting as defined by copyright

Page 66: Sociable Software

Examples

Kamaelia Macro

Page 67: Sociable Software

Examples

Kamaelia Macro: Top Level Schematic DVB Multiplex

outbox

Channel Transcoderinbox

DVB  Demuxer  

BBC_ONEinbox

Channel Transcoderinbox

Channel Transcoderinbox

Channel Transcoder

Channel Transcoder

Channel Transcoder

inbox

inbox

inbox

BBC_TWO

BBC_THREE

BBC_FOUR

CBEEBIES

CBBC

Page 68: Sociable Software

Examples

Kamaelia Macro: Transcode progs on a Channel

Channel Transcoder

Splitter

inbox

_eit_

inbox

ProgChangeDetector

outbox

inbox

RestartableTranscoder

transcoder_factory

inbox

nextoutbox

Page 69: Sociable Software

Examples

Kamaelia Macro: Finding Programme Junctions

EIT Parsing

DVB PacketReconstructor

inboxinbox

Now NextParser

outbox

inbox

Now Nextservice filter

Now NextChanges

outbox

inbox

outbox

inbox

outbox

outbox

Page 70: Sociable Software

Examples

Kamaelia Macro: Programme Transcoder

Programme Transcoder

(a pipeline)

Pipethrough(“mencoder ­o file options...”)

inbox control

signal

inbox

control

_transcodingcomplete

_stop

signal

Page 71: Sociable Software

How?

What's inside the box?

The following examples are largely simplified, simply because slides are a terrible way to show code.

I've generally removed shutdown code.

Page 72: Sociable Software

How?

What's inside the box?class ConsoleReader(threadedcomponent): def main(self): while 1: line = raw_input(">>") line = line + self.eol self.send(line, "outbox")

Page 73: Sociable Software

How?

What's inside the box?class ConsoleReader(threadedcomponent): def main(self): while 1: line = raw_input(">>") line = line + self.eol self.send(line, "outbox")

See – we're saying this component runs inside it's own thread. This is all we have to write for it to work.

Page 74: Sociable Software

How?

What's inside the box?class ConsoleReader(threadedcomponent): def main(self): while 1: line = raw_input(">>") line = line + self.eol self.send(line, "outbox")

As you can see here, a component communicates with other components by sending things to outboxes.

Page 75: Sociable Software

How?

What's inside the box?class ConsoleEchoer(component): def main(self): while not self.shutdown(): while self.dataReady("inbox"): data = self.recv("inbox") sys.stdout.write(str(data)) sys.stdout.flush() yield 1

Whereas here, you can see that they listen for data in their inboxes. and then do stuff based on that!

Page 76: Sociable Software

How?

What's inside the box?class ConsoleEchoer(component): def main(self): while not self.shutdown(): while self.dataReady("inbox"): data = self.recv("inbox") sys.stdout.write(str(data)) sys.stdout.flush() yield 1

This one however is a generator based component. This runs in the same thread as all other generators, making this code equivalent to a state machine. Note the baseclass does not say threaded or generator.

Page 77: Sociable Software

How?

What's inside the box?class ConsoleEchoer(component): def main(self): while not self.shutdown(): while self.dataReady("inbox"): data = self.recv("inbox") sys.stdout.write(str(data)) sys.stdout.flush() yield 1

This yield keyword is what makes this method a generator. For now, you can assume it acts like a “return back here when next called” thing. It's NOT really the same at all as a ruby yield!

Page 78: Sociable Software

And that's the basic idea.

On the website there's a mini axon tutorial and a guide to writing components, and a few magazine articles as well which should get you started.

There are also more tutorials on slideshare

Please also ask on #kamaelia on freenode.

Page 79: Sociable Software

Thank you:-)