200 likes | 339 Views
Baratine in Practice. Date: 2014-06-17 Location: San Diego JUG. Nam Nguyen Software Engineer Caucho Technology, Inc. Baratine in Practice. Download Install Our first @ResourceService - @Modify - Multiple counters Concepts @Service - implement an example @Workers
E N D
Baratine in Practice Date: 2014-06-17 Location: San Diego JUG Nam Nguyen Software Engineer Caucho Technology, Inc.
Baratine in Practice Download Install Our first @ResourceService - @Modify - Multiple counters Concepts @Service - implement an example @Workers - implement an example Type of services chart Partitioning and clustering
Task: Baratine quick start - Download - Install - Our first service http://doc.baratine.io/v0.8/manual/quick-start/
Java @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; } } WebSocket OUTBOX INBOX HTTP REST HTTP Polling JOURNAL KEY-VALUE DB (internal)
What You Get + Insane low-latency concurrent performance assign thread 1. incrementAndGet() 2. incrementAndGet() 3. addAndGet() 4. decrementAndGet() 5. incrementAndGet() assign thread 6. incrementAndGet() 7. ... NO BLOCKING / LOCKING ! very CPU cache friendly (for both data and instructions) • CPU core uninterrupted during batch • no context switching • no pausing • thread screams through entire batch Batch A Batch B
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
Performance Characteristics Requests per Second Baratine Batch Size / Clients
Performance Characteristics ServiceA to ServiceB within the same JVM Requests per Second - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Baratine Batch Size / Clients
Reliable to Batch assign thread @BeforeBatch 1 incrementAndGet() 2. addAndGet() 3. addAndGet() 4. decrementAndGet() 5. incrementAndGet() 6. incrementAndGet() @AfterBatch - flush writes assign thread @BeforeBatch 7. ... Safe to process in batches. @OnCheckpoint
Putting it All Together • Freed to operate in memory safely! ▲Operational Data
@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; } }
@Service Barebones service, basis of @ResourceService Singleton, 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!
@Service Less magic: you have fine-grained control + @Journal + @OnRestore + @OnCheckpoint + @OnActive + @BeforeBatch + @AfterBatch
@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
Types of Services (manual)
Partitioning and Clustering /auction/222 /auction/555 /auction/888 /auction/111 /auction/444 /auction/999 192.168.1.100 192.168.1.101 /auction/000 /auction/333 /auction/666 /auction/777 192.168.1.102 Resources are partitioned by its service URL and ID
State of Baratine GPL Been in active development for over 2 years v0.8.3 (alpha) http://baratine.io (alpha) Thank you! stealth <
The End Q and A