Fuel

74
RMod 1 Mariano Martinez Peck [email protected] http://marianopeck.wordpress.com/ Monday, August 22, 2011

description

ESUG 2011, Edinburgh

Transcript of Fuel

Page 1: Fuel

RMod

1

Mariano Martinez [email protected]

http://marianopeck.wordpress.com/

Monday, August 22, 2011

Page 2: Fuel

THANKS a lot!!!

2

SummerTalk 2011

Student: Martin DiasMentor: Mariano Martínez Peck

Monday, August 22, 2011

Page 3: Fuel

Object references

3

Monday, August 22, 2011

Page 4: Fuel

Object graph

4

Monday, August 22, 2011

Page 5: Fuel

5

An objet graph serializer.

Monday, August 22, 2011

Page 6: Fuel

Serialize

6

Input: an object graph

Output: stream of bytes

Monday, August 22, 2011

Page 7: Fuel

Materialize(deserialize)

7

Output: an object graph

Input: stream of bytes

Monday, August 22, 2011

Page 8: Fuel

Once serialized...

8

Database File Memory Socket

Stream of bytes

Monday, August 22, 2011

Page 9: Fuel

Fuel’s main goals

Provide fast object serialization and materialization.

Be flexible and easy to customize.

Have a good OO design, well tested and benchmarked.

No need of special support from the VM.

Be a general purpose serializer.

Allow tools to be built on top of Fuel.9

Monday, August 22, 2011

Page 10: Fuel

Key features Fast serialization and materialization.

Class reshape support.

Serialization of any kind of object.

Cycles support.

Global objects references.

Buffered writing.

Support for some “hook methods”.10

Monday, August 22, 2011

Page 11: Fuel

Key Characteristics

Pickle format.

Objects grouped in clusters.

Analysis phase before writing.

Stack over recursion.

Two phases for writing instances and references.

Iterative graph recreation.11

Monday, August 22, 2011

Page 12: Fuel

Pickle format

12

Invest more time in serialization so that objects can then be materialized much faster.

Monday, August 22, 2011

Page 13: Fuel

Grouping objects in clusters

13

“Similar” objects (they share writing/loading information) are grouped together in clusters. The most common case, yet not the

only one, takes place when a class is a cluster for its instances.

Monday, August 22, 2011

Page 14: Fuel

14

Monday, August 22, 2011

Page 15: Fuel

14

Each jar has a specific type of element

Monday, August 22, 2011

Page 16: Fuel

14

Each jar has a specific type of element

Jars are in order

Monday, August 22, 2011

Page 17: Fuel

14

Label: - What’s inside? - How much?Each jar has

a specific type of element

Jars are in order

Monday, August 22, 2011

Page 18: Fuel

14

Label: - What’s inside? - How much?

Different sizes and different amounts of elements

Each jar has a specific type of element

Jars are in order

Monday, August 22, 2011

Page 19: Fuel

14

Label: - What’s inside? - How much?

Different sizes and different amounts of elements

Each jar has a specific type of element

Jars are in order

s/jar/cluster

Monday, August 22, 2011

Page 20: Fuel

14

Label: - What’s inside? - How much?

Different sizes and different amounts of elements

Each jar has a specific type of element

Jars are in order

s/jar/cluster

Monday, August 22, 2011

Page 21: Fuel

14

Label: - What’s inside? - How much?

Different sizes and different amounts of elements

Jars are in order

s/jar/cluster

Each cluster has a specific type of object

Monday, August 22, 2011

Page 22: Fuel

14

Label: - What’s inside? - How much?

Different sizes and different amounts of elements

Jars are in order

s/jar/cluster

Each cluster has a specific type of object

Monday, August 22, 2011

Page 23: Fuel

14

Label: - What’s inside? - How much?

Different sizes and different amounts of elements

s/jar/cluster

Each cluster has a specific type of object

Clusters are in order

Monday, August 22, 2011

Page 24: Fuel

14

Label: - What’s inside? - How much?

Different sizes and different amounts of elements

s/jar/cluster

Each cluster has a specific type of object

Clusters are in order

Monday, August 22, 2011

Page 25: Fuel

14

Different sizes and different amounts of elements

s/jar/cluster

Each cluster has a specific type of object

Clusters are in order

Label: - Cluster ID - Amount of

objects

Monday, August 22, 2011

Page 26: Fuel

14

Different sizes and different amounts of elements

s/jar/cluster

Each cluster has a specific type of object

Clusters are in order

Label: - Cluster ID - Amount of

objects

Monday, August 22, 2011

Page 27: Fuel

14

s/jar/cluster

Each cluster has a specific type of object

Clusters are in order

Label: - Cluster ID - Amount of

objects

Different sizes and different amounts of

objects

Monday, August 22, 2011

Page 28: Fuel

Pickle format basic

15

Stream

Monday, August 22, 2011

Page 29: Fuel

Pickle format basic

15

Stream

Monday, August 22, 2011

Page 30: Fuel

Pickle format basic

15

Stream

Monday, August 22, 2011

Page 31: Fuel

Pickle format basic

15

Stream

Monday, August 22, 2011

Page 32: Fuel

16

Why the pickle format is so fast in materialization?

Standard serializers Fuel pickle format

Monday, August 22, 2011

Page 33: Fuel

16

Why the pickle format is so fast in materialization?

Standard serializers Fuel pickle format

Recursive

materialization Iterative

materialization

Monday, August 22, 2011

Page 34: Fuel

Pickle advantages

Batch/Bulk/Iterative materialization.

Efficient since types are stored and fetch only once.

Fast because at materialization we know the size of everything.

The generated stream is smaller.

More next....

17

Monday, August 22, 2011

Page 35: Fuel

There is no silver bullet...

18

Fast serialization

(without pickle)

Slow serialization(with pickle)

Monday, August 22, 2011

Page 36: Fuel

Fuel requires

Traversing the object graph.

Mapping each object to a specific cluster.

19

This is done in a phase before serialization called “Analysis”.

Monday, August 22, 2011

Page 37: Fuel

Analysis phase

20

cluster1 aPointcluster2 x y

......

... ...

key (a cluster) value (a set)

1) Traverse (#fuelAccept: aVisitor)2) Fill dictionary(#fuelSerializer)

Monday, August 22, 2011

Page 38: Fuel

Serialization

21

key (a cluster) value (a set)

serialize: anObject on: aStreammaterializeFrom: aStream

IDCluster

A cluster defines how its objects are serialized and materialized.

cluster1 aPointcluster2 x y

......

... ...

Monday, August 22, 2011

Page 39: Fuel

Stack over recursion

22

To traverse the object graph, Fuel uses a custom stack implementation rather than a recursion.

Monday, August 22, 2011

Page 40: Fuel

Basic stepsSerialization

1. Analyze.2. Serialize header.3. Serialize instances.4. Serialize references.5. Serialize root.

Materialization1. Materialize header.2. Materialize instances.3. Materialize references.4. Materialize root.

23

Monday, August 22, 2011

Page 41: Fuel

Fuel for software(so far)

Moose export utility.

SandstoneDB persistence.

Pier kernel persistence.

Newspeak language.

Marea (my own research project!).

24

Monday, August 22, 2011

Page 42: Fuel

Future Work

Continue efforts on performance optimization.

Create a tool for loading class and trait packages.

Support user-defined Singletons.

Fast statistics/brief info extraction of a stored graph.

Partial loading of a stored graph.25

Monday, August 22, 2011

Page 43: Fuel

Future work 2

Enable to deploy serialization and materialization behavior independently.

Support object replacement for serialization and materialization.

Allow cycle detections to be disabled.

Partial loading.

26

Monday, August 22, 2011

Page 44: Fuel

Serialization of primitive objects

27

Memory based stream

Monday, August 22, 2011

Page 45: Fuel

Serialization of primitive objects

27

Memory based stream

StOMPSRPFuel

Monday, August 22, 2011

Page 46: Fuel

Serialization of primitive objects

27

Memory based stream File based stream

StOMPSRPFuel

Monday, August 22, 2011

Page 47: Fuel

Serialization of primitive objects

27

Memory based stream File based stream

StOMPSRPFuel

FuelSRPStOMP

Monday, August 22, 2011

Page 48: Fuel

28

Materialization of primitive objects

Monday, August 22, 2011

Page 49: Fuel

28

Fuel

ImageSegment

StOMP

Materialization of primitive objects

Monday, August 22, 2011

Page 50: Fuel

Non primitive objects

29

Monday, August 22, 2011

Page 51: Fuel

Non primitive objects

29

StOMPSRPFuel

Monday, August 22, 2011

Page 52: Fuel

Non primitive objects

29

StOMPSRPFuel

Monday, August 22, 2011

Page 53: Fuel

Non primitive objects

29

FuelImageSegmentStOMP

StOMPSRPFuel

Monday, August 22, 2011

Page 55: Fuel

Excellent performance without special support from VM and good OO design.

Conclusionfor us

31

Monday, August 22, 2011

Page 56: Fuel

Fuel is a vehicle. It is infrastructure. You can build cool stuff on top of it.

Conclusionfor YOU

32

Monday, August 22, 2011

Page 57: Fuel

Thanks!

RMod

Mariano Martinez [email protected]

http://marianopeck.wordpress.com/

Monday, August 22, 2011

Page 58: Fuel

34

Concrete example

Monday, August 22, 2011

Page 59: Fuel

35

Monday, August 22, 2011

Page 60: Fuel

Analysis phase

3620

cluster1 aRectanglecluster2 anOrigin aCornercluster3 10

key (a cluster) value (a IdentitySet)

20 30 40

Analysis phase

Monday, August 22, 2011

Page 61: Fuel

Serializationinstances

phase

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

Monday, August 22, 2011

Page 62: Fuel

Serializationinstances

phase

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

Monday, August 22, 2011

Page 63: Fuel

Serializationinstances

phase

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

1 Rectangle 2 origi corne 1

instance variable names

instance count

instance variable count

class name

cluster ID

Monday, August 22, 2011

Page 64: Fuel

Serializationinstances

phase

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

1 Rectangle 2 origi corne 1

instance variable names

instance count

instance variable count

class name

cluster ID

Monday, August 22, 2011

Page 65: Fuel

Serializationinstances

phase

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

1 Rectangle 2 origi corne 1

1 Point 2 x y 2

instance variable names

instance count

instance variable count

class name

cluster ID

Monday, August 22, 2011

Page 66: Fuel

Serializationinstances

phase

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

1 Rectangle 2 origi corne 1

1 Point 2 x y 2

54 10 20 30 40

instance variable names

instance count

instance variable count

class name

cluster ID

Monday, August 22, 2011

Page 67: Fuel

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

aRectangle anOrigiaCorner20 40 10 30instancesIndex

(IdentityDictionary)

1 5 7 3 2 4 6

54 10 20 30 40

2

Serializationreferences

phase

instances

references

Monday, August 22, 2011

Page 68: Fuel

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

aRectangle anOrigiaCorner20 40 10 30instancesIndex

(IdentityDictionary)

1 5 7 3 2 4 6

54 10 20 30 40

2

2

3

Serializationreferences

phase

instances

references

Monday, August 22, 2011

Page 69: Fuel

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

aRectangle anOrigiaCorner20 40 10 30instancesIndex

(IdentityDictionary)

1 5 7 3 2 4 6

54 10 20 30 40

2

2

3

4 5 6 7

Serializationreferences

phase

instances

references

Monday, August 22, 2011

Page 70: Fuel

cluster1 aRectangle

cluster2 anOrigin aCorner

cluster3 10 20 30 40

aRectangle anOrigiaCorner20 40 10 30instancesIndex

(IdentityDictionary)

1 5 7 3 2 4 6

54 10 20 30 40

2

2

3

4 5 6 7

Serializationreferences

phase

instances

references

Monday, August 22, 2011

Page 71: Fuel

2

2

3

4 5 6 7

final stream

1 Rectangle 2 origi corne 1

1 Point 2 x y 2

54 10 20 30 40

{instances

{references

Monday, August 22, 2011

Page 72: Fuel

2

2

3

4 5 6 7

final stream

1 Rectangle 2 origi corne 1

1 Point 2 x y 2

54 10 20 30 40

{instances

{references

1{trailer

7 3{header clustersCount

objectsCounts

rootMonday, August 22, 2011

Page 73: Fuel

2

Materialization

instances {2 3

4 5 6 7

1 Rectangle 2 origin corner 1

1 Point 2 x y 2

5 4 1 2 3 4

{references

1{trailer

7 3{header clustersCount

objectsCounts

root

Monday, August 22, 2011

Page 74: Fuel

41

Monday, August 22, 2011