javaspaces and linda language ghaith haddad eel6897 fall 2007

28
JavaSpaces and JavaSpaces and Linda Language Linda Language Ghaith Haddad Ghaith Haddad EEL6897 EEL6897 Fall 2007 Fall 2007

Upload: darlene-goodwin

Post on 31-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces and JavaSpaces and Linda LanguageLinda Language

Ghaith HaddadGhaith Haddad

EEL6897EEL6897

Fall 2007Fall 2007

Page 2: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

WalkthroughWalkthrough Parallel Programming ModelsParallel Programming Models What is Linda?What is Linda? Linda ModelLinda Model

• RequirementsRequirements• AdvantagesAdvantages• Compare with MPICompare with MPI• DisadvantagesDisadvantages

Linda Implementations in JavaLinda Implementations in Java• TSpacesTSpaces• JavaspacesJavaspaces

RequirementsRequirements ComplexityComplexity DiagramDiagram In DepthIn Depth ExampleExample TransactionsTransactions Distributed EventsDistributed Events

• GigaSpacesGigaSpaces• ComparisonComparison• Research ProjectsResearch Projects

ReferencesReferences DemoDemo

Page 3: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Parallel Programming ModelsParallel Programming Models Set of software technologies to express parallel Set of software technologies to express parallel

algorithms and match applications with the algorithms and match applications with the underlying parallel systemsunderlying parallel systems[2][2]

Areas include: applications, programming Areas include: applications, programming languages, compilers, libraries, communications languages, compilers, libraries, communications systems, and parallel I/Osystems, and parallel I/O

““Roughly” categorized into two kinds of systems:Roughly” categorized into two kinds of systems:• Shared-MemoryShared-Memory• Distributed-MemoryDistributed-Memory

Examples: POSIX Threads, MPI, Charm++, Linda, Examples: POSIX Threads, MPI, Charm++, Linda, Oz (programming language)Oz (programming language)

Page 4: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

What is LindaWhat is Linda ““Linda is a coordination language for parallel and Linda is a coordination language for parallel and

distributed processing, providing a communication distributed processing, providing a communication mechanism based on a logically shared memory space mechanism based on a logically shared memory space called called tuple spacetuple space.” .” [1][1]

Developed by David Gelernter and Nicholas Carriero at Yale Developed by David Gelernter and Nicholas Carriero at Yale University.University.

Coordination Language: Model, not Grammar!Coordination Language: Model, not Grammar! tuple spacetuple space

• An implementation of the associative memory paradigm for An implementation of the associative memory paradigm for parallel/distributed computingparallel/distributed computing

• Structured as a bag of Structured as a bag of tuplestuples Tuple Example: ("point", 12, 67), Tuple Example: ("point", 12, 67),

• Three fields tupleThree fields tuple• 12 and 67 are the 12 and 67 are the x x and and y y coordinates of the point represented coordinates of the point represented

by this tupleby this tuple• Similar to struct or object without methodsSimilar to struct or object without methods

Page 5: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Tuple Space vs. Associative Tuple Space vs. Associative MemoryMemory[7][7]

Allow memory items Allow memory items to be selected by to be selected by reference to their reference to their contents rather than contents rather than by an addressby an address

Every word in the Every word in the associative memory is associative memory is searched in parallel searched in parallel against a key held in against a key held in the comparand the comparand register which is the register which is the same width as same width as memory memory

Page 6: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Linda Model Requirements Linda Model Requirements

The original Linda model requires four The original Linda model requires four operations that individual workers perform operations that individual workers perform on the tuples and the tuplespaceon the tuples and the tuplespace[3][3]

• in:in: atomically reads and removes -consumes- a atomically reads and removes -consumes- a tuple from tuplespace tuple from tuplespace

• rd:rd: non-destructively reads a tuplespace non-destructively reads a tuplespace • out:out: produces a tuple, writing it into produces a tuple, writing it into

tuplespace tuplespace • eval:eval: creates new processes to evaluate creates new processes to evaluate

tuples, writing the result into tuplespace tuples, writing the result into tuplespace

Page 7: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Linda Model RequirementsLinda Model Requirements

The specification of the tuple to be The specification of the tuple to be retrieved makes use of an retrieved makes use of an associative matching techniqueassociative matching technique• A subset of the fields in the tuple have their A subset of the fields in the tuple have their

values specifiedvalues specified• Used to locate a matching tuple in the tuple Used to locate a matching tuple in the tuple

spacespace• Example: in("point", ?x, ?y)is called an anti-Example: in("point", ?x, ?y)is called an anti-

tupletuple• anti-tuple: Any tuple with the same number anti-tuple: Any tuple with the same number

and type of fieldsand type of fields• Anti-tuple is used to Anti-tuple is used to

Page 8: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Linda Model AdvantagesLinda Model Advantages[3][3]

More orthogonalMore orthogonal• Treats process coordination as a separate Treats process coordination as a separate

activity from computation.activity from computation.• Allows processes computing in different Allows processes computing in different

languages and platforms to interoperate using languages and platforms to interoperate using the same primitivesthe same primitives

More general: More general: • Can subsume various levels of concurrency -Can subsume various levels of concurrency -

uni-processor, multi-threaded multiprocessor, uni-processor, multi-threaded multiprocessor, or networked- under a single model.or networked- under a single model.

• Allows a multi-threaded Linda system to be Allows a multi-threaded Linda system to be distributed across multiple computers, or vice-distributed across multiple computers, or vice-versa, without changeversa, without change

Page 9: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Compare with MPICompare with MPI[3][3]

Message-passing models require Message-passing models require tightly-coupled processes sending tightly-coupled processes sending messages to each other in some messages to each other in some sequence or protocolsequence or protocol

Linda processes are decoupled from Linda processes are decoupled from other processes, communicating only other processes, communicating only through the tuplespacethrough the tuplespace• a process need have no notion of other a process need have no notion of other

processes except for the kinds of tuples processes except for the kinds of tuples consumed or produced (data coupling).consumed or produced (data coupling).

Page 10: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Linda Model DisadvantagesLinda Model Disadvantages

The tuple space is unprotected since any The tuple space is unprotected since any process can access any tuple in itprocess can access any tuple in it[5][5]

No hierarchical organization of tuples, No hierarchical organization of tuples, therefore no sense of name scopingtherefore no sense of name scoping[5][5]

Decreased speed of operations in Linda Decreased speed of operations in Linda systems as compared to MPI systemssystems as compared to MPI systems[3][3]

At worst, inefficient, and, at best, subject At worst, inefficient, and, at best, subject to unpredictable performanceto unpredictable performance[1][1]

More disadvantages inMore disadvantages in[6][6]

Page 11: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Linda Implementations in JavaLinda Implementations in Java

TSpacesTSpaces JavaSpacesJavaSpaces GigaSpacesGigaSpaces Many Other Research Projects…Many Other Research Projects…

Page 12: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

TSpacesTSpaces IBM’s implementationIBM’s implementation "the common platform on which we build links to "the common platform on which we build links to

all system and application services“all system and application services“[8][8]

Single server process running on the network Single server process running on the network which makes use of a textual configurations filewhich makes use of a textual configurations file[1][1]

Transports tuples across the network using the Transports tuples across the network using the standard Java object serialization mechanisms standard Java object serialization mechanisms and TCP/IP socketsand TCP/IP sockets[1][1]

New commands can be added relatively easilyNew commands can be added relatively easily[1][1]

Page 13: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

TSpacesTSpaces

Page 14: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpacesJavaSpaces Forms part of the Jini system, and so Forms part of the Jini system, and so

makes extensive use of the Jini APImakes extensive use of the Jini API[9][9]

Network support is provided by the Java Network support is provided by the Java RMI (Remote Method Invocation) RMI (Remote Method Invocation) protocolprotocol[10][10]

Distribution of classes to clients is handled Distribution of classes to clients is handled by the standard Internet hypertext by the standard Internet hypertext protocol (HTTP)protocol (HTTP)[1][1]

Supports the basic Yale Linda operations Supports the basic Yale Linda operations (the names differ from the original names (the names differ from the original names used by the Yale group, but essentially the used by the Yale group, but essentially the same functionality is provided)same functionality is provided)

Page 15: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpacesJavaSpaces

Page 16: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces – RequirementsJavaSpaces – Requirements[1][1]

a web (HTTP) server (a minimal one is provided a web (HTTP) server (a minimal one is provided with the Jini/JavaSpaces release)with the Jini/JavaSpaces release)

an RMI activation server (part of the standard RMI an RMI activation server (part of the standard RMI software bundled with Java)software bundled with Java)

a Jini lookup service (alternatively the RMI a Jini lookup service (alternatively the RMI registry service can be used, but this is registry service can be used, but this is discouraged as support for this option may be discouraged as support for this option may be discontinued by Sun in the future)discontinued by Sun in the future)

a Jini transaction managera Jini transaction manager a JavaSpaces servera JavaSpaces server Applications are also required to run a security Applications are also required to run a security

manager, whether security checking is required manager, whether security checking is required or notor not

Page 17: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces – ComplexityJavaSpaces – Complexity[1][1]

A typical command line required to run a A typical command line required to run a JavaSpaces application is as followsJavaSpaces application is as follows

java -Djava.security.policy= D:\JavaProgs\java -Djava.security.policy= D:\JavaProgs\policy.allpolicy.all

-Doutrigger.spacename=JavaSpaces-Doutrigger.spacename=JavaSpaces

-Dcom.sun.jini.lookup.groups=public-Dcom.sun.jini.lookup.groups=public

-Djava.rmi.server.codebase= http://host/space--Djava.rmi.server.codebase= http://host/space-examples-dl.jarexamples-dl.jar

-cp D:\JavaProgs\space-examples.jar;D:\-cp D:\JavaProgs\space-examples.jar;D:\JavaProgs\classesJavaProgs\classes

sun.applet.AppletViewer worker.htmlsun.applet.AppletViewer worker.html

Page 18: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces – DiagramJavaSpaces – Diagram[11][11]

Page 19: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces – In DepthJavaSpaces – In Depth[11][11]

All operations are invoked on an object that implements the All operations are invoked on an object that implements the net.jini.space.JavaSpace interface.net.jini.space.JavaSpace interface.

A space stores entries, each of which is a collection of typed objects that A space stores entries, each of which is a collection of typed objects that implements the Entry interfaceimplements the Entry interface

import net.jini.core.entry.*;import net.jini.core.entry.*;public class MessageEntry public class MessageEntry

implements Entry {implements Entry {public String content;public String content;public MessageEntry() { }public MessageEntry() { }public MessageEntry(String content) {public MessageEntry(String content) {

this.content = content;this.content = content;}}public String toString() {public String toString() {

return "MessageContent: " + content;return "MessageContent: " + content;}}

} }

Page 20: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Net.jini.space.JavaSpaceNet.jini.space.JavaSpace InterfaceInterface[12][12]

EventRegistration notify(Entry tmpl, Transaction txn, RemoteEventListener EventRegistration notify(Entry tmpl, Transaction txn, RemoteEventListener listener, long lease, MarshalledObject handback)listener, long lease, MarshalledObject handback)

- When entries are written that match this template notify the given listener - When entries are written that match this template notify the given listener with a RemoteEvent that includes the handback object.with a RemoteEvent that includes the handback object.

Entry read(Entry tmpl, Transaction txn, long timeout)Entry read(Entry tmpl, Transaction txn, long timeout)- Read any matching entry from the space, blocking until one exists.- Read any matching entry from the space, blocking until one exists.Entry readIfExists(Entry tmpl, Transaction txn, long timeout)Entry readIfExists(Entry tmpl, Transaction txn, long timeout)- Read any matching entry from the space, returning null if there is currently is - Read any matching entry from the space, returning null if there is currently is

none.none.Entry snapshot(Entry e)Entry snapshot(Entry e)- The process of serializing an entry for transmission to a JavaSpaces service - The process of serializing an entry for transmission to a JavaSpaces service

will be identical if the same entry is used twice.will be identical if the same entry is used twice.Entry take(Entry tmpl, Transaction txn, long timeout)Entry take(Entry tmpl, Transaction txn, long timeout)- Take a matching entry from the space, waiting until one exists.- Take a matching entry from the space, waiting until one exists.Entry takeIfExists(Entry tmpl, Transaction txn, long timeout)Entry takeIfExists(Entry tmpl, Transaction txn, long timeout)- Take a matching entry from the space, returning null if there is currently is - Take a matching entry from the space, returning null if there is currently is

none.none.Lease write(Entry entry, Transaction txn, long lease)Lease write(Entry entry, Transaction txn, long lease)- Write a new entry into the space.- Write a new entry into the space.

http://java.sun.com/products/jini/2.1/doc/api/overview-summary.htmlhttp://java.sun.com/products/jini/2.1/doc/api/overview-summary.html

Page 21: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces – ExampleJavaSpaces – Exampleimport net.jini.space.JavaSpace;import net.jini.space.JavaSpace;public class SpaceClient {public class SpaceClient {

public static void main(String argv[]) {public static void main(String argv[]) {try {try {

System.out.println("Searching for a JavaSpace...");System.out.println("Searching for a JavaSpace...");Lookup finder = new Lookup(JavaSpace.class);Lookup finder = new Lookup(JavaSpace.class);JavaSpace space = (JavaSpace) finder.getService();JavaSpace space = (JavaSpace) finder.getService();System.out.println("A JavaSpace has been discovered.");System.out.println("A JavaSpace has been discovered.");System.out.println("Writing a message into the System.out.println("Writing a message into the

spce...");spce...");MessageEntry msg = new MessageEntry();MessageEntry msg = new MessageEntry();msg.content = "Hello there";msg.content = "Hello there";space.write(msg, null, 60*60*1000);space.write(msg, null, 60*60*1000);MessageEntry template = new MessageEntry();MessageEntry template = new MessageEntry();System.out.println("Reading a message from the System.out.println("Reading a message from the

space...");space...");MessageEntry result = (MessageEntry) MessageEntry result = (MessageEntry)

space.read(template, null, Long.MAX_VALUE);space.read(template, null, Long.MAX_VALUE);System.out.println(“Message read is: "+result.content);System.out.println(“Message read is: "+result.content);

} catch(Exception e) {e.printStackTrace();}} catch(Exception e) {e.printStackTrace();}}}

}}

Page 22: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces – TransactionsJavaSpaces – Transactions[11][11]

Package: net.jini.core.transactionPackage: net.jini.core.transaction Provides basic atomic transactions that group Provides basic atomic transactions that group

multiple operations across multiple JavaSpaces multiple operations across multiple JavaSpaces services into a bundle that acts as a single atomic services into a bundle that acts as a single atomic operationoperation

Either all modifications within the transactions Either all modifications within the transactions will be applied or none willwill be applied or none will• regardless of whether the transaction spans one or more regardless of whether the transaction spans one or more

operations or one or more JavaSpaces servicesoperations or one or more JavaSpaces services Transactions can span multiple spaces and Transactions can span multiple spaces and

participantsparticipants A read(), write(), or take() operation that has a A read(), write(), or take() operation that has a

null transaction acts as if it were in a committed null transaction acts as if it were in a committed transaction that contained that operation.transaction that contained that operation.

Page 23: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

JavaSpaces – Distributed EventsJavaSpaces – Distributed Events[14][14]

Defined in the Jini Technology Core Defined in the Jini Technology Core Platform SpecificationPlatform Specification• Defines interfaces and requirements placed on Defines interfaces and requirements placed on

Jini which is capable of sending remote eventsJini which is capable of sending remote events• The JavaSapces Specification overrides Jini The JavaSapces Specification overrides Jini

specification, it provides more details on how a specification, it provides more details on how a JavaSpace implements remote eventsJavaSpace implements remote events

A remote event model allows an object in A remote event model allows an object in one JVM to register as a listener to an one JVM to register as a listener to an object on another JVMobject on another JVM• Example: a JavaSpace can send remote events Example: a JavaSpace can send remote events

when an entry matching a specified template is when an entry matching a specified template is written into the spacewritten into the space

Page 24: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

GigaSpacesGigaSpaces[13][13]

Developed as a commercial implementation of the JavaSpaces specification, with some features added:• Operations on multiple tuples• Updating, deleting and counting tuples• Iterating over a set of tuples matching an anti-tuple• Distributed implementations of the Java Collections List, Set

and Map interfaces• Message queuing mechanism

Efficient implementation of GigaSpaces• Buffered writes• Indexing of tuples (with or without intervention from the

application developer)• Support for non-Java clients to access GigaSpaces through the

use of the SOAP protocol over HTTP• Support for web servers to make use of GigaSpaces to share

session information (potentially even between separate web servers)

Page 25: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

ComparisonComparison[1][1]

TSpaces is unique in providing an extensible form of TSpaces is unique in providing an extensible form of matching through the ability to add new commandsmatching through the ability to add new commands

Page 26: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Research projectsResearch projects XMLSpacesXMLSpaces[15][15]

• Designed to support the use of XML data in tuplesDesigned to support the use of XML data in tuples• Built over TSpacesBuilt over TSpaces• Supports a distributed tuple space modelSupports a distributed tuple space model

COCO33PSPS[16][16]

• "Computation, Coordination and Composition with Petri "Computation, Coordination and Composition with Petri net Specifications“net Specifications“

Java-LindaJava-Linda[17][17]

• a student project at Yale Universitya student project at Yale University eLindaeLinda[18][18]

• A model close to the standard Linda modelA model close to the standard Linda model• Three ImplementationsThree Implementations

eLinda1: Fully distributed tuple spaceeLinda1: Fully distributed tuple space eLinda2: Centralised tuple space, like JavaSpaces, TSpaceseLinda2: Centralised tuple space, like JavaSpaces, TSpaces eLinda3: Like in eLinda2, but with “broadcast” tuples eLinda3: Like in eLinda2, but with “broadcast” tuples

cached on each processing nodecached on each processing node

Page 27: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

ReferencesReferences [1] Linda implementations in Java for concurrent systems- G. C. Wells1[1] Linda implementations in Java for concurrent systems- G. C. Wells1;x;x, A. G. Chalmers and P. G. , A. G. Chalmers and P. G.

Clayton – © 2003 John Wiley & Sons Ltd. Clayton – © 2003 John Wiley & Sons Ltd. [2] http://en.wikipedia.org/wiki/Parallel_programming_model[2] http://en.wikipedia.org/wiki/Parallel_programming_model [3] http://en.wikipedia.org/wiki/Linda_%28coordination_language%29[3] http://en.wikipedia.org/wiki/Linda_%28coordination_language%29 [4] G. Andrews, “ Concurrent Programming: Principles and Practice”, Benjamin/Cummings Publishing [4] G. Andrews, “ Concurrent Programming: Principles and Practice”, Benjamin/Cummings Publishing

Company, Inc., Redwood City, CA. 1991.Company, Inc., Redwood City, CA. 1991. [5] Drucker, R.; Frank, A., "A C++/Linda model for distributed objects," [5] Drucker, R.; Frank, A., "A C++/Linda model for distributed objects," Computer Systems and Computer Systems and

Software Engineering, 1996., Proceedings of the Seventh Israeli Conference onSoftware Engineering, 1996., Proceedings of the Seventh Israeli Conference on , vol., no., pp.30-37, , vol., no., pp.30-37, 12-13 Jun 199612-13 Jun 1996

[6] Ericsson-Zenith (1992). Process Interaction Models. Paris University[6] Ericsson-Zenith (1992). Process Interaction Models. Paris University [7] [7] http://www.gigaflop.demon.co.uk/comp/chapt2.htmhttp://www.gigaflop.demon.co.uk/comp/chapt2.htm [8] IBM. The TSpaces vision. URL: http://www.almaden.ibm.com/cs/TSpaces/html/Vision.html[8] IBM. The TSpaces vision. URL: http://www.almaden.ibm.com/cs/TSpaces/html/Vision.html [9] Sun Microsystems. Jini connection technology. URL: http://www.sun.com/jini[9] Sun Microsystems. Jini connection technology. URL: http://www.sun.com/jini [10] C. Austin and M. Pawlan. [10] C. Austin and M. Pawlan. Advanced Programming for the Java 2 PlatformAdvanced Programming for the Java 2 Platform. Addison-Wesley, . Addison-Wesley,

September 2000September 2000 [11] http://java.sun.com/developer/technicalArticles/tools/JavaSpaces/index.html[11] http://java.sun.com/developer/technicalArticles/tools/JavaSpaces/index.html [12] http://java.sun.com/products/jini/2.1/doc/api/net/jini/space/JavaSpace.html[12] http://java.sun.com/products/jini/2.1/doc/api/net/jini/space/JavaSpace.html [13] [13] GigaSpaces Technologies Ltd. Gigaspaces. URL: http://www.gigaspaces.com/index.htm , 2001GigaSpaces Technologies Ltd. Gigaspaces. URL: http://www.gigaspaces.com/index.htm , 2001 [14] P. Bishop and N. Warren, [14] P. Bishop and N. Warren, JavaSpaces in Practice,JavaSpaces in Practice, Addison-Wesley, 2002 Addison-Wesley, 2002 [15] R. Tolksdorf and D. Glaubitz. Coordinating web-based systems with documents in XMLSpaces. [15] R. Tolksdorf and D. Glaubitz. Coordinating web-based systems with documents in XMLSpaces.

URL: http://flp.cs.tu-berlin.de/~tolk/xmlspaces/webxmlspaces.pdf 2001URL: http://flp.cs.tu-berlin.de/~tolk/xmlspaces/webxmlspaces.pdf 2001 [16] T. Holvoet. An Approach for Open Concurrent Software Development. PhD thesis, Department [16] T. Holvoet. An Approach for Open Concurrent Software Development. PhD thesis, Department

of Computer Science, K.U.Leuven, December 1997of Computer Science, K.U.Leuven, December 1997 [17] A. Smith. Towards wide-area network Piranha: Implementing Java-Linda. URL: [17] A. Smith. Towards wide-area network Piranha: Implementing Java-Linda. URL:

http://www.cs.yale.edu/homes/asmith/cs690/cs690.html http://www.cs.yale.edu/homes/asmith/cs690/cs690.html [18] G.C. Wells. A Programmable Matching Engine for Application Development in Linda. PhD thesis, [18] G.C. Wells. A Programmable Matching Engine for Application Development in Linda. PhD thesis,

University of Bristol, U.K., 2001University of Bristol, U.K., 2001

Page 28: JavaSpaces and Linda Language Ghaith Haddad EEL6897 Fall 2007

Demo…Demo…