35
Space based programming [email protected] @gojkoadzic http://gojko.net

Space Based Programming

Embed Size (px)

DESCRIPTION

Presentation of space based programming given at Skills Matter 02 Sep 2009

Citation preview

Page 1: Space Based Programming

Space based programming

[email protected]@gojkoadzic

http://gojko.net

Page 2: Space Based Programming

Why should you care?

It helps us build applications that: can scale out to lots of machines easily can grow and shrink dynamically have massive throughput handle massive amounts of data

Page 3: Space Based Programming

So what are spaces?

Data spaces are “network attached memory”, allowing us to read, put or take objects

Space takes care of redundancy, failover, transactions …

Alternatively, send tasks to the object and let it execute it.

Page 4: Space Based Programming

The idea has been around for a while, but somehow has not caught on…

however it’s coming back with a bang!

Page 5: Space Based Programming

Another language named after a Lovelace

Page 6: Space Based Programming

David Gelertner invents Linda in the 80’s

Distributed processing based on tuples Orthogonal process coordination Data coupling rather than process coupling

Page 7: Space Based Programming

Sun Jini in the 90’s

Evolvable architectures, autodiscovery and lots of other flux capacitors nobody needed or knew how to use at the time…

Page 8: Space Based Programming

Grid computing in 00's

Page 9: Space Based Programming

Great for computations, but what about transaction processing?

Page 10: Space Based Programming

Space-based systems will be key for cloud scalability

Page 11: Space Based Programming

Products

http://coherence.oracle.com http://www.gigaspaces.com http://virtuoso.openlinksw.com/ http://www.almaden.ibm.com/cs/TSpaces/ http://www.jboss.org/infinispan

Page 12: Space Based Programming

Command Pattern (GOF)

“is a design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time”... (wikipedia)

Page 13: Space Based Programming

You need a recipient, probably an entity by ID

Page 14: Space Based Programming

You need a “recipient”, probably an entity by ID

A “command” with all the information

required to run it

Page 15: Space Based Programming

You need a “recipient”, probably an entity by ID

A “command” with all the information

required to run it

And an “invoker” to do the job

Page 16: Space Based Programming

And the command gets executed...

Page 17: Space Based Programming

So what does it have to do with spaces?

“...makes it easier to construct general components that need to delegate, sequence or execute method calls” (also wikipedia)

Page 18: Space Based Programming

You can use many invokers

Page 19: Space Based Programming

And do loads of work in parallel

Page 20: Space Based Programming

And you can do something more productive with your time...

Page 21: Space Based Programming

So what does that have to do with spaces?

Space is where recipients reside and where you send commands

Lots of different processors run in the space, but from the outside appear as a single “mind”

This scales really well and it is virtually indestructible....

Page 22: Space Based Programming

Space: all your objects

Page 23: Space Based Programming

Processing units (=partitions)

Page 24: Space Based Programming

GigaSpace data objects

[SpaceClass]

public class Message

{

[SpaceID(AutoGenerate=true)]

public String MessageId {get; set;}

[SpaceRouting]

public String MessageType{ get; set;}

...

}

Page 25: Space Based Programming

Space Data Properties

[SpaceID] is unique for the class in Space [SpaceRouting] determines the partition

(defaults to space ID) Indexes speed up queries

[SpaceProperty(Index=SpaceIndexType.Basic)] [SpaceVersion] for optimistic locking [SpaceExclude] are not serialized

Page 26: Space Based Programming

Recipient (Command context)

Space object Space ID is the entity ID Routing ID is the same field

Page 27: Space Based Programming

Commands

Space object Space ID is a GUID

(can be auto-generated)

Target recipient ID is the Routing ID

Page 28: Space Based Programming

Processing Units

Worker thread pool Template matches the command

Class matching Property matching (if not null)

Works inside a PU container

Page 29: Space Based Programming

Example processor

[PollingEventDriven(MinConcurrentConsumers = 1,

MaxConcurrentConsumers = 4)]

internal class MessageProcessor

{

[EventTemplate]

public Message TemplateForThisProcessor { get{ ... } }

[DataEventHandler]

public Message ProcessMessage(Message message)

{.... }

}

Page 30: Space Based Programming

Processes

Contain one or more processing unit containers Own a space partition Run on the network, balanced, clustered,

backed up

Page 31: Space Based Programming

Coherence - distributed HashMaps

Works on POCO objects, but you can implement PortableObject for .NET/Java interop

void IPortableObject.ReadExternal(IPofReader reader)

{

firstName = reader.ReadString(0);

addrHome = (Address)reader.ReadObject(1);

....

void IPortableObject.WriteExternal(IPofWriter writer)

{

writer.WriteString(0, firstName);

writer.WriteObject(1, addrHome);

Page 32: Space Based Programming

Works as a hashmap

INamedCache cache = CacheFactory.GetCache(“my map”);

cache.Add(key, value)

cache.Remove(key, value)

Also supports queries, notifications etc

Page 33: Space Based Programming

Entry Processors – push code to objects

cache.Insert("BGD", new Temperature(25, 'c', 12));

IValueUpdater updater = new ReflectionUpdater("setDegree");

IEntryProcessor processor = new UpdaterProcessor(updater, 26);

object result = cache.Invoke("BGD", processor);

Page 34: Space Based Programming

Key ideas to do it efficiently

Forget about n-tier systems Group data together with all processes Ensure that invokers have all the information

needed to run (so no unnecessary serialization) Ensure that the recipients are the correct

aggregates for execution (so low contention during execution)

Use asynchronous persistence

Page 35: Space Based Programming

That's it for now...

• http://gojko.net

• http://ukdotnet.ning.com

• October 1st, Mike Hadlow on MassTransit