Implementing Garbage Collection for Active Objects on Top of Erlang - - PowerPoint PPT Presentation

implementing garbage collection for active objects on top
SMART_READER_LITE
LIVE PREVIEW

Implementing Garbage Collection for Active Objects on Top of Erlang - - PowerPoint PPT Presentation

Implementing Garbage Collection for Active Objects on Top of Erlang Sigmund Hansen Master thesis autumn 2014 Problem ABS is a modeling language for distributed systems ABS has an Erlang back end Back end cannot collect garbage


slide-1
SLIDE 1

Implementing Garbage Collection for Active Objects on Top of Erlang

Sigmund Hansen Master thesis autumn 2014

slide-2
SLIDE 2

Problem

◮ ABS is a modeling language for distributed systems ◮ ABS has an Erlang back end ◮ Back end cannot collect garbage processes

slide-3
SLIDE 3

Goals

The garbage collector should be:

◮ Fast

It should not considerably slow down simulations

◮ Comprehensive

It should collect most or all garbage

◮ Correct

It should not collect resources required later

slide-4
SLIDE 4

ABS Overview

◮ Executable models ◮ Functional subset ◮ Object-oriented ◮ Concurrency:

◮ Active objects ◮ Scheduling in Concurrent Object Groups (COGs) ◮ RPC with message passing

slide-5
SLIDE 5

Erlang Overview

◮ Concurrency:

◮ Actor model ◮ Message passing

◮ Fault-tolerant ◮ Functional

slide-6
SLIDE 6

Garbage Collection Overview

Automatic memory management for dynamically allocated memory.

◮ Reference counting ◮ Tracing

◮ Object graph traversal ◮ De-allocation of unmarked objects

slide-7
SLIDE 7

Active Object Collection

◮ Kept alive by associated process ◮ Must kill the process ◮ High-level implementation

slide-8
SLIDE 8

Choice of Algorithm

◮ Reference counting cannot collect cyclic garbage. ◮ Killing processes, not collecting memory,

i.e. no moving collectors

◮ Greater risk with non-standard collection algorithms

Mark and sweep that stops the world implemented.

slide-9
SLIDE 9

Stopping the World

◮ No interrupts ◮ Stop by messaging ◮ Tasks and scheduling must stop

slide-10
SLIDE 10

Blocking Operations

◮ Blocking on futures ◮ Blocking on object instantiation ◮ Inappropriate COG state during block

slide-11
SLIDE 11

COG State Machine (Before)

Not running Running None found

[runnable task found] token, task error [no runnable task found] new task, task state changed, task error new task, task state changed

slide-12
SLIDE 12

COG State Machine (After)

Not0running Stopped

Resume0state

Running None0found Blocked

Blocked0task

  • k

stop0world [runnable0task0found] token, task0error [no0runnable0task0found] new0task, task0state0changed, task0error, inc/dec0reference0count stop0world resume0world [reference0count0!=00, Resume0state0=0Not0running] stop0world new0task, task0state0change, inc/dec0reference0count stop0world running0task0state changed0to0blocked blocked0task0state changed0to0runnable stop0world resume0world [reference0count0!=00, Resume0state0=0Blocked] new0task, task0state0change, inc/dec0reference0count get0references, inc/dec0reference0count resume0world [reference0count0=00]

slide-13
SLIDE 13

Stopping Running Tasks

◮ Will reduce waiting ◮ COG messages task ◮ Task then blocks

slide-14
SLIDE 14

Asynchronous Method Calls on Inactive Objects

◮ Task initialization is synchronous ◮ Waits until object is activated ◮ Respond to GC messages while waiting

slide-15
SLIDE 15

Tasks Created While the World is Stopping

◮ Task is created by a future ◮ Stopped COGs do not receive task creation messages ◮ Futures temporarily become roots and keep parameters

slide-16
SLIDE 16

Future State Machine (Before)

Loop

Result

init Await_start

Parameters

Await_completion

Started Task completed Task error

slide-17
SLIDE 17

Future State Machine (After)

Wait Loop

Result

init Await_start

Parameters get_references Started Started get_references Task complete Task error die

slide-18
SLIDE 18

A Complete View

  • f COGs and Futures

Why is it required?

slide-19
SLIDE 19

Marking Phase

◮ Messages all grays in parallel ◮ BN+1 = BN ∪ GN ◮ GN+1 = References(GN) \ BN+1 ◮ Sweeps when gray set is empty

slide-20
SLIDE 20

Sweeping

◮ Identifies white objects ◮ Identifies white futures ◮ Sends message to kill them ◮ Resume message sent to COGs

slide-21
SLIDE 21

Collecting COGs with Reference Counting

◮ Counts objects left in group ◮ COG stops if world resumes and it is empty ◮ Messages garbage collector

slide-22
SLIDE 22

Static analysis

◮ Types that may contain references ◮ Reaching unawaited futures ◮ Other potential analyses:

◮ Loops with synchronization points ◮ Deep functions

slide-23
SLIDE 23

Triggering Garbage Collection

When should garbage be collected:

◮ On time? ◮ Number of objects and futures? ◮ Process ratio?

slide-24
SLIDE 24

Data Collection

◮ Garbage collector state changes ◮ Number of objects and futures swept ◮ Memory usage and number of objects, futures and COGs

slide-25
SLIDE 25

Test Cases

◮ Ping pong

Basic test with cyclic garbage

◮ Sequences

Unstoppable loop

◮ Prime Sieve

Long-running tasks

◮ MapReduce - Indexing

Real-world test case

slide-26
SLIDE 26

Ping Pong - Time

Collection scheme Real time Relative Relative without idle Before GC 1274 ms 100.0 % 100.0 % Never collect 1257 ms 98.6 % 93.5 % Always collect 1854 ms 145.5 % 311.3 % Collect on count 1293 ms 101.4 % 106.7 % Collect on time 1261 ms 98.9 % 94.9 % + Stop running 1265 ms 99.2 % 96.5 % Collect on either 1290 ms 101.2 % 105.5 % + Stop running 1298 ms 101.8 % 108.4 %

slide-27
SLIDE 27

Ping Pong - No GC

250 500 750 14 16 18 Total Memory in MiB 0 ms 100 ms 200 ms 300 ms 400 ms 500 ms

Time

variable cogs

  • bjects

futures

slide-28
SLIDE 28

Ping Pong - Always collecting

100 200 300 12.5 15.0 17.5 20.0 22.5 Total Memory in MiB 0 ms 1220 ms 2440 ms 3660 ms 4880 ms 6100 ms

Time

variable cogs

  • bjects

futures

slide-29
SLIDE 29

Ping Pong - By count

20 40 60 13.5 14.0 14.5 15.0 15.5 Total Memory in MiB 0 ms 140 ms 280 ms 420 ms 560 ms 700 ms

Time

variable cogs

  • bjects

futures

slide-30
SLIDE 30

Ping Pong - Timed

50 100 150 200 13.5 14.0 14.5 15.0 15.5 16.0 16.5 Total Memory in MiB 0 ms 100 ms 200 ms 300 ms 400 ms 500 ms

Time

variable cogs

  • bjects

futures

slide-31
SLIDE 31

Infinite Ping Pong - No GC

50000 100000 150000 300 600 900 1200 Total Memory in MiB 0 ms 31120 ms 62240 ms 93360 ms 124480 ms 155600 ms

Time

variable cogs

  • bjects

futures

slide-32
SLIDE 32

Infinite Ping Pong - Timed

2000 4000 6000 8000 50 100 Total Memory in MiB 0 ms 11900 ms 23800 ms 35700 ms 47600 ms 59500 ms

Time

variable cogs

  • bjects

futures

slide-33
SLIDE 33

Sequences - Time

Collection scheme Real time Relative Relative without idle Before GC 1395 ms 100.0 % 100.0 % Never collect 1439 ms 103.2 % 111.2 % Always collect 39159 ms 2807.2 % 9662.1 % Collect on count 16801 ms 1204.4 % 4001.0 % Collect on time 1622 ms 116.3 % 157.5 % + Stop running 1530 ms 109.7 % 134.1 % Collect on either 17054 ms 1222.6 % 4065.1 % + Stop running 12614 ms 904.3 % 2940.8 %

slide-34
SLIDE 34

Sequences - No GC

1000 2000 3000 4000 5000 20 30 40 50 60 70 Total Memory in MiB 0 ms 720 ms 1440 ms 2160 ms 2880 ms 3600 ms

Time

variable cogs

  • bjects

futures

slide-35
SLIDE 35

Sequences - Timed

1000 2000 3000 4000 5000 20 30 40 50 60 Total Memory in MiB 0 ms 860 ms 1720 ms 2580 ms 3440 ms 4300 ms

Time

variable cogs

  • bjects

futures

slide-36
SLIDE 36

Sequences - Timed stopping running processes

200 400 600 16 20 24 Total Memory in MiB 0 ms 700 ms 1400 ms 2100 ms 2800 ms 3500 ms

Time

variable cogs

  • bjects

futures

slide-37
SLIDE 37

Prime Sieve - Time

Collection scheme Real time Relative Relative without idle Before GC 1448 ms 100.0 % 100.0 % Never collect 1453 ms 100.3 % 101.1 % Always collect 1903 ms 131.4 % 201.6 % Collect on count 1482 ms 102.4 % 107.6 % Collect on time 1454 ms 100.4 % 101.3 % + Stop running 1542 ms 106.5 % 120.9 % Collect on either 1472 ms 101.6 % 105.3 % + Stop running 1545 ms 106.7 % 121.6 %

slide-38
SLIDE 38

Indexing - Time

Collection scheme Real time Relative Relative without idle Before GC 1356 ms 100.0 % 100.0 % Never collect 1373 ms 101.2 % 104.7 % Always collect 5043 ms 371.8 % 1134.2 % Collect on count 1408 ms 103.9 % 114.7 % Collect on time 1398 ms 103.1 % 111.7 % + Stop running 1405 ms 103.6 % 113.9 % Collect on either 1410 ms 104.0 % 115.3 % + Stop running 1434 ms 105.7 % 121.9 %

slide-39
SLIDE 39

Conclusion

Timed trigger gives acceptable results.

◮ Acceptably fast ◮ Mark and sweep is complete ◮ Measures taken stopping the world to ensure correctness

slide-40
SLIDE 40

Discussion

Testing with infinite loops have discouraging results. Future work to lower overhead may be needed:

◮ Optimize stopping the world ◮ Optimize marking ◮ Concurrent collection ◮ Change of algorithm