33
Denis Caromel 1 Denis Caromel Institut universitaire de France (IUF) INRIA Sophia-Antipolis – CNRS – I3S – Université de Nice Luis Mateu DCC – Universidad de Chile Eric Tanter DCC – Universidad de Chile Ecole des Mines de Nantes SOM: Sequential Object Monitors 1. SOM Principles: Thread-Less Active Object 2. Scheduling Strategy and API 3. Examples 4. Implementation and Benchmarks

Denis Caromel Institut universitaire de France (IUF)

Embed Size (px)

DESCRIPTION

SOM: Sequential Object Monitors. Denis Caromel Institut universitaire de France (IUF) INRIA Sophia-Antipolis – CNRS – I3S – Université de Nice Luis Mateu DCC – Universidad de Chile Eric Tanter DCC – Universidad de Chile – Ecole des Mines de Nantes. - PowerPoint PPT Presentation

Citation preview

Page 1: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 1

Denis CaromelInstitut universitaire de France (IUF)

INRIA Sophia-Antipolis – CNRS – I3S – Université de Nice

Luis MateuDCC – Universidad de Chile

Eric TanterDCC – Universidad de Chile – Ecole des Mines de Nantes

SOM: Sequential Object Monitors

1. SOM Principles: Thread-Less Active Object2. Scheduling Strategy and API3. Examples4. Implementation and Benchmarks

Page 2: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 2

Thread Locks, Notify, Synchronization

wait/notifyAll of

Java monitors are:

• Difficult to understand for

most programmers

• Inefficient: may trigger lots

of thread context-switches

• Tangling of synchronization

concern with application logic

Not “Sequential”:many pending, interleaved, method calls

Page 3: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 3

SOM Orientations

• Easier to understand: • Sequentiality of monitor code

• Efficient: • Minimize thread context-switches

• Separation of concerns: • Separate synchronization code from synchronized code

Page 4: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 4

SOM: an Object and a thread-less scheduler

(1) Method call reification in queue

(2) Schedule method

(3) Request execution

Page 5: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 5

SOM Principles

• Any method invocation on a SOM:

• reified as a request, and • delayed in a pending queue until scheduled

• The scheduling method is:

• guaranteed to be executed if a request may be scheduled

• A scheduled request is executed:

• in mutual excusion with other requests and scheduling

Page 6: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 6

What’s in the name ?

S

O

M

bject: Method Call,

Reification: Request

equential:no interleaving, ”run-to-completion” action

onitor:Mutual Exclusion

Page 7: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 7

Scheduling:

Principles and API

Page 8: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 8

SOM: thread-less scheduling + minimizing context switch

Page 9: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 9

SOM: thread-less scheduling + minimizing context switch

Page 10: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 10

SOM Strategy and Guarantees

• No infinite busy execution of scheduling method• schedule() is called by caller threads, in mutual exclusion

• No additional thread is needed to execute schedule• Several requests can be scheduled at a time:

• requests executed by their caller threads, in scheduling order•schedule will not be called again before all scheduled requests complete

• After a request is executed:

• the caller thread does at most one schedule

Page 11: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 11

Principle for the

scheduling API

Standard class:

class Buffer {

...

void put(Object o) { ... }

Object get() { ... }

boolean isEmpty() { ... }

boolean isFull() { ... }

}

Page 12: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 12

Scheduler API

scheduleOldest ();

scheduleOldest (“get”);

scheduleAll(“exitRead”);

scheduleOlderThan(“foo”,”bar”);

scheduleAll(new RequestFilter()

boolean accept(Request req){

if … return true

if … return false

… } );

Page 13: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 13

The Full Scheduler for buffer-like classes

Can be abstracted for any method names !

scheduleOldest(putMethod);

Full control to tune the synchronization !

public void schedule () {

if (!buffer.isEmpty() ) scheduleOldest (“get”);

if (!buffer.isFull() ) scheduleOldest (“put”); }

Page 14: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 14

Fair

Reader Writer

with

SOM

Page 15: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 15

Implementation and

Benchmarks

Page 16: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 16

Implementation

• Based on a specific MOP: Reflex [Tanter et al. OOPSLA 03]• Bytecode transformation

• A generic metaobject (scheduler) uses Java monitor for synchronization

• Small configuration language:schedule: Buffer with: BufferScheduler

...

• Runtime APIBuffer b = (Buffer) SOM.newMonitor(Buffer.class,

BufferScheduler.class);

Page 17: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 17

0

2000

4000

6000

8000

10000

12000

1 2 4 8 16 32

Number of consumer threads

Exe

cuti

on

tim

e (m

s) Java monitors

SOM

SOM monitors scale better than Java monitors

Linux 2.4 JDK 1.4.2 BenchmarksSingle item buffer, one producer, multiple consumers

Page 18: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 18

SOM Expressiveness (in the paper)

SOM-based solutions for

• Bounded buffer

• Readers and writers

• Dining philosophers

SOM-based Abstractions of

• Guards

• Chords

• Full access to request queue, order of requests, filter, etc. :

==> Full control to express

various policies

• E.g: Reader Writers : • Fair,

• Reader Priority,

• Writer Priority

• ...

Page 19: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 19

Related Work• Classical monitors [Hoare and Brinch Hansen]

• Java monitors

• Java Specification Request 166 (JDK 1.5)

• Guards:

• Easy to express declarative synchronizations in SOM

• Scheduler, Active Objects:• SOM = AO without Activity, AO without its own thread

• Chords, Join, Functional Nets:

• Storing monitor state in parameters of pending calls,

• Calls Interleaving

My view: in a stateful OO, better of to reason about pending queue state

Page 20: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 20

SÖM: Sæquentiål Øbjæct Mönitör• An alternative to standard, interleaving, monitors

• Key points:

• Thread-less scheduler, Thread-less Active Object

• Threads collaborate for Mutual Scheduling

• Separation of concerns:

• Synchronizing + Synchronized code

• Expressive and Efficient:

• Full access to pending calls

• Avoids context-switches

• Stateful (object) vs. Pending Function Calls :

• Reason about data structure state rather than call interleaving

• Sequentiality: easier to reason about, to maintain, to reuse

Page 21: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 21

Page 22: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 22

Chords (Polyphonic C#)

Related to functional calculus (Join, Functional Nets):

• Storing monitor state in pending calls

e.g. calling an asynchronous sharedRead (n-1)

• Passing information from one call to another (copied)

==> No mutual exclusion is intrinsically required

An asynchronous call is also a kind of ’’Firing Token’’ + Value

Very nice abstraction for a purely functional setting but :

• No access to the queue of pending calls,

• Does not really promote interleaving-free reasoning

Page 23: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 23

Reader Writer Chords in C#

Page 24: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 24

Reader Writer Interface

Page 25: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 25

SOM Writer priority // Reader priority

Page 26: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 26

A declarative abstraction: Guards

Page 27: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 27

Windows 2000, JDK 1.4.2

Page 28: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 28

Linux 2.4, JDK 1.4.2

Page 29: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 29

Linux 2.6, JDK 1.5

Page 30: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 30

Page 31: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 31

SOM key originalities

• Thread-less scheduler, Thread-less Active Object

• Threads collaborate for mutual schedulling

From Active Objects, Scheduler, to SOM

Page 32: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 32

SOM Goals

• Powerful: other synchronization mechanisms are easily expressed with SOMs

• Easier to understand: method requests are executed sequentially

• Efficient: SOMs minimize thread context-switches

• Separation of concerns: SOMs separate the synchronization concern from the application logic

Page 33: Denis Caromel Institut universitaire de France (IUF)

Denis Caromel 33

An Example: The Bounded Buffer

Standard object:

class Buffer {

...

void put(Object o) { ... }

Object get() { ... }

boolean isEmpty() { ... }

boolean isFull() { ... }

}

Scheduler:

class BufferScheduler extends Scheduler { Buffer buf; ... void schedule() { if (buf.isEmpty()) scheduleOldest(“put”); else if (buf.isFull()) scheduleOldest(“get”); else scheduleOldest(); }}