Top Banner
Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG
21

Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

Dec 15, 2015

Download

Documents

Rocco Lorance
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: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

1

Baratine in Practice

Nam NguyenSoftware Engineer

Caucho Technology, Inc.

Date: 2014-06-17Location: San Diego JUG

Page 2: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

2

Baratine in PracticeDownloadInstallOur first @ResourceService

- @Modify- Multiple counters

Concepts@Service

- implement an example @Workers

- implement an exampleType of services chartPartitioning and clustering

Page 3: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

3

Task: Baratine quick start

- Download- Install- Our first service

http://doc.baratine.io/v0.8/manual/quick-start/

Page 4: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

@Journal@ResourceService(“public:///counter/{_id}”)public class CounterServiceImpl{ private long _id; private long _counter; public long get() { return _counter; }

@Modify public long incrementAndGet() { return ++_counter; }

@Modify public long decrementAndGet() { return --_counter; }

@Modify public long addAndGet(long value) { _counter = _counter + value;

return _counter; }}

4

Page 5: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

jonathan hughes optiminsight

@Journal@ResourceService(“public:///counter/{_id}”)public class CounterServiceImpl{ private long _id; private long _counter; public long get() { return _counter; }

@Modify public long incrementAndGet() { return ++_counter; }

@Modify public long decrementAndGet() { return --_counter; }

@Modify public long addAndGet(long value) { _counter = _counter + value;

return _counter; }}

INBOX

JOURNALKEY-VALUE DB

(internal)

5

OUTBOXHTTP Polling

HTTP REST

WebSocket

Java

Page 6: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

6

What You Get

+ Insane low-latency concurrent performance

assign thread1. incrementAndGet()2. incrementAndGet()3. addAndGet()4. decrementAndGet()5. incrementAndGet()

assign thread6. incrementAndGet()7. ...

NO BLOCKING / LOCKING ! CPU cache stays hot (for both data and instructions)

Batch A

Batch B

• CPU core uninterrupted during batch• no context switching• no pausing• thread screams through entire batch

Page 7: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

7

Batch Programming

assign thread@BeforeBatch

1 incrementAndGet()2. addAndGet()3. addAndGet()4. decrementAndGet()5. incrementAndGet()6. incrementAndGet()

@AfterBatch- flush writes

assign thread@BeforeBatch

7. ...

Leave expensive operations to be executed at the end of the batch.

Inbox is empty at this point

Page 8: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

8

Performance Characteristics

1 2 4 8 16 32

Batch Size / Clients

Requests per Second

Baratine

Page 9: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

9

Performance Characteristics

1 2 4 8 16 32

Requests per Second

Baratine

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ServiceA to ServiceB within the same JVM

Page 10: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

10

Reliable to Batch

assign thread@BeforeBatch

1 incrementAndGet()2. addAndGet()3. addAndGet()4. decrementAndGet()5. incrementAndGet()6. incrementAndGet()

@AfterBatch- flush writes

assign thread@BeforeBatch7. ...

Safe to process in batches.

@OnCheckpoint

Page 11: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

11

Putting it All Together

Freed to operatein memory safely!

▲ Operational Data

Page 12: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

12

@Journal@ResourceService(“public:///counter/{_id}”)public class CounterServiceImpl{ private long _id; private long _counter; public long get() { return _counter; }

@Modify public long incrementAndGet() { return ++_counter; }

@Modify public long decrementAndGet() { return --_counter; }

@Modify public long addAndGet(long value) { _counter = _counter + value;

return _counter; }}

Page 13: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

13

@Service

Barebones service, basis of @ResourceServiceSingleton, only one instance within a JVM

- No @Modify- No automatic restore- No automatic paging- No automatic checkpointing- No automatic query support- No automatic partitioning

Warning: hardcore!

Page 14: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

14

@Service

Less magic: you have fine-grained control

+ @Journal+ @OnRestore+ @OnCheckpoint+ @OnActive+ @BeforeBatch+ @AfterBatch

Page 15: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

15

Task: implement a logging service with a @Service

Page 16: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

16

@Workers

A @Service with a thread-pool acting on the inbox. Example: hibernate, SAP, MySQL, legacy, integration

- Does not fully benefit from batching- Not single-threaded

+ Can block+ Multi-threaded

Page 17: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

17

Task: implement a @Workers @Service

Page 18: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

18

Types of ServicesAnnotation: @ResourceService @Service @Workers

Batching ✓ ✓ ✓*

Journaling ✓ ✓

Checkpointing ✓ ✓

Paging ✓

Partitioning ✓

Resource ID’s ✓

Search ✓

Threaded-ness single single multi

Can Block? ✓

Performance ★★★☆ ★★★★ ★☆☆☆

(manual)

Page 19: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

19

Partitioning and Clustering

/auction/111/auction/444/auction/999

/auction/222/auction/555/auction/888

/auction/000/auction/333/auction/666/auction/777

192.168.1.100

192.168.1.102

192.168.1.101

Resources are partitionedby its service URL and ID

Page 20: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

20

State of Baratine

GPL

Been in active development for over 2 years

v0.8.3 (alpha)

http://baratine.io (alpha)

Thank you!

stealth<

Page 21: Baratine in Practice Nam Nguyen Software Engineer Caucho Technology, Inc. 1 Date: 2014-06-17 Location: San Diego JUG.

21

The End

Q and A