Top Banner
Erlang Solutions Ltd. © 1999-2011 Erlang Solutions Ltd. The Design and Implementation of a Scalable, Concurrent Virtual Machine Robert Virding Principle Language Expert at Erlang Solutions Ltd.
27

The design and implementation of a scalable concurrent virtual machine (Robert Virding)

Jan 13, 2015

Download

Technology

Ontico

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

Erlang Solutions Ltd.

© 1999-2011 Erlang Solutions Ltd.

The Design and Implementation of a Scalable, Concurrent Virtual Machine

Robert VirdingPrinciple Language Expert at Erlang Solutions Ltd.

Page 2: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erlang Solutions Ltd.

• The one stop shop for all your Erlang needs

• Founded in 1999, Offices in UK, Sweden and Poland

• Clients on six continents

• System development experience in:

- Telecom, banking, e-commerce, track & trace, VOIP, etc.

• We do:

- In-house system development, on-site consultancy, and contracting,

- Erlang-based recruitment and Professional training at all levels

2

Page 3: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Concurrency vs. Parallelism

• Parallelism is what the system provides

•Concurrency is a property of the problem/solution

(as good a definition as any)

3

Page 4: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erlang is COP

Concurrency Oriented Programming

4

Page 5: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Problem domain/Erlang properties

• Light-weight concurrency

•Asynchronous message passing

• Process isolation

• Error handling

•Complex coordination

• Soft real-time

•Continuous evolution of system

5

Page 6: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erlang is a functional language

• Immutable data

•No looping constructs

• Pattern matching is ubiquitous

6

Page 7: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Communication

•Asynchronous message passing

- Scales well

- Suits multi-core

- needs only limited synchronisation

• Each process has a single message queue

• Selective receive

• Suitable as a building block

7

Page 8: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

The BEAM

The main Erlang implementation

Will cover:

• Processes/scheduling

•Memory management

•Communication

• Error handling

(Bogdan’s Erlang Abstract Machine, now Björn’s)

8

Page 9: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Processes and scheduling

•Want light-weight concurency

•Must have processes (isolation)

➡Implement processes ourselves (green processes)

•They are really light-weight

•Complete control of scheduling

•Not a general machine

9

Page 10: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Processes and scheduling

• Pre-emptive scheduling

- Scheduled as cooperating coroutines

•One run-queue per thread

•Multi-core/multi-thread ➡ multi-queues- Process stealing

•No really viable alternatives

10

Page 11: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Memory management/GC

• Soft real-time requires unobtrusive GC

•Must ensure process isolation

• Stop-the-world collector

vs.

interactive/concurrent collector

- independent of parallelism

11

Page 12: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Memory management/GC

Alternatives:

• Shared heap

• Separate process heaps

•Hybrid

12

Page 13: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Memory management/GC

Erlang does NOT require separate heaps and message copying!

• Immutable data means we can safely share

13

Page 14: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Memory management/GC

Shared heap

•Reduces copying of data

- Messages shared

•Complicates GC

- must use incremental/concurrent collector

• Less well-suited to multi-core

•Complicates handling of processes

14

Page 15: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Memory management/GC

Separate process heaps

• Increases copying of data

- messages copied

• Simplifies GC

- can use stop-the-world per process collector

• Fits well on multi-core

• Scales well

• Simplifies handling of processes

15

Page 16: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Memory management/GC

Hybrid heaps

•Reduces copying of data

- messages on shared heap

•May in part be determined at compile-time

•Complicates GC

• Less well-suited on multi-core

16

Page 17: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Memory management/GC

Erlang BEAM uses very restricted hybrid heaps

•Mainly separate heaps

- most of the benefits of separate heaps

• Some shared data

- get some benefits of shared data

- without too many of the complications

17

Page 18: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Alternative communication

• Share memory communication

- synchronisation woes - locking, mutexes ...

- scalability?

- error handling

• STM (Software Transactional Memory)

- scalability?

•Go concurrency motto

- "Do not communicate by sharing memory; instead, share memory by communicating"

18

Page 19: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erjang - Erlang on the JVM

A real Erlang on the JVM

Will cover:

•Why the JVM?

•How it runs Erlang code

•Concurrency/scheduling

•Memory management/GC

•Miscellaneous

19

Page 20: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erjang - Why the JVM?

• Erjang is different from the BEAM

- it has different properties

•Very mature VM

•Wide-spread VM

- Erlang can run in MANY more places

• Improved interface between Erlang and other JVM languages

•Access to libraries

(Kresten wanted to learn Erlang)

20

Page 21: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erjang - Running Erlang code

•Uses BEAM VM assembler code as source to generate Java .class files

- helps ensure compatibility

21

Page 22: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erjang - Concurrency

•Uses Kilim to provide concurrency and message passing

- ultra light-weight threads

- message passing with shared messages

•Cooperative coroutines

22

Page 23: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erjang - Scheduling

• Pre-emptive scheduling

- Scheduled as cooperating coroutines

•One run-queue per thread

•Multi-core/multi-thread ➡ multi-queues

23

Page 24: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erjang - Memory management/GC

•Uses standard JVM memory management/GC

- shared heap

- stop-the-world collector

➡Cannot guarantee soft real-time behaviour (yet)

24

Page 25: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Erjang - Miscellaneous

•Needs special handling for tail-call optimisation

(a must for functional languages)

- BEAM compiler generates different calls

- two entry points for each function

- common body

25

Page 26: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

• The Erlang User Conference brings together the best minds and names in Erlang Programming

• This year, the Erlang User Conference will be held in a brand new location – the exciting, spacious building of the München Bryggeriet.

• An enticing addition to the 2011 conference will be two further tracks.

• We will also be holding a day of tutorials on 4 November.

• In the 3 days prior to the conference, 31 October – 2 November, we will be holding an Erlang University with a selection of Erlang courses suitable for all levels of expertise.

26

Page 27: The design and implementation of a scalable concurrent virtual machine (Robert Virding)

© 1999-2011 Erlang Solutions Ltd.

Questions?

Thank you

Robert Virding

[email protected]

27