Download iwmse slides

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Stage: Python with Actors
John Ayres & Susan Eisenbach
Imperial College
May 2009
The Anatomy of an Actor
Upon receipt of a
message Actors may:
Modify local state
(change behaviour)
Create new Actors
Send messages
With thanks to the SALSA team
Why Actors?
No shared state
Avoids low-level
locking
Reduces
corruption
Consistent model
Avoids
‘thread soup’
Distribution
‘plugs in’
Independent Execu>on
Distribu>on
Migra>on Reliability
Mobility
Doing a few things at once in Java
Hotel hotels = hotelService.find(country);
Flight flights = flightService.find(country);
render(hotel, flights);
Doing a few things at once in Java
List<Hotel> hotels;
List<Flight> flights;
Thread t1 = new Thread() {
@Override
public void run() {
hotels = hotelService.find(country);
}
};
Thread t2 = new Thread() {
@Override
public void run() {
flights = flightService.find(country);
}
};
t1.start(); t2.start();
t1.join(); t2.join();
render(hotels, flights);
Design
Aim: ‘A usable implementation of the Actor model
that supports distribution and concurrency in the
simplest way possible’
New Language
Extend existing language
Tiny user base (1)
Large user base
Unfamiliar syntax
Established syntax
Single issue
General purpose
Python
Object Oriented
‘Lightweight syntax’
Threading model and classes similar to Java
GIL makes multicore speedups
harder to achieve
Supports metaprogramming
Implementa>on
Subvert calling conventions:
Method calls become message sends
Instance methods become receives
Variables replaced with futures
References replaced with names
Ready
class Bank(MobileActor):
def query_bank(self) :
money = vault.get_money()
… code continues …
if ready (money):
print "%d in the bank" % money else: print "Don’t know yet!" Handle
def query_bank(self) :
money = vault.get_money()
handle(money, self.query_complete)
def query_complete(self, amount) :
print "%d in the bank" % money Sync
money = sync (vault.get_money()) if money < 1000:
print "Too poor to continue"
else:
transfer(1000)
Doing a few things at once in Java
List<Hotel> hotels;
List<Flight> flights;
Thread t1 = new Thread() {
@Override
public void run() {
hotels = hotelService.find(country);
}
};
Thread t2 = new Thread() {
@Override
public void run() {
flights = flightService.find(country);
}
};
t1.start(); t2.start();
t1.join(); t2.join();
render(hotels, flights);
Doing a few things at once in Stage
flights = flightActor.find(country)
hotels = hotelActor.find(country)
... code continues ...
render(flights, hotels)
Performance Represen>ng the real world
Stage 2.0
Runs on a mobile phone
Reliable and fast Actor naming using DHTs
Efficient load balancing of Actors
Improved local communication using Python MP
Conclusion
Closer to the ‘real world’ than other Actor
languages
Accessible to Python programmers – only removes few Python features Well written code will see a speedup
Ques>ons