Microservice

advertisement
Baratine
Building high-performing resource services
Fast Resource Services
• In-memory services
• Batching
• CPU affinity/single-threaded
• Local persistent database
• Object Orientated
• Communication
• Resilience and Scalability
• Cloud/Failover
• Journaling
• Microservices
Microservice (noun) - ?
Baratine.io
In-Memory Services
Baratine in the field
Multitasking
Because we needed another word for
“unable to focus on task at hand”
Multitasking
In-Memory Service
Uninterrupted
Performance
• Single
threaded
• CPU affinity
• Batching
Batching
Log Service
Example
Multithreaded:
• synchronized
• write()
• flush()
• synchronized
• write()
• flush()
• synchronized
• write()
• flush()
Baratine:
•
•
•
•
write()
write()
write()
flush()
• Automatic batching! Where else can you get
that?
Ex: TCP can send 100 bytes as fast as 1 byte
Batching
Uninterrupted
Performance
• Single threaded
• Batching
• CPU affinity/singlethreaded
Performance In Context
Websocket (single) = 50,000
r/s
Websocket (batched) = 500,000
r/s
In-JVM messaging = 4,000,000
r/s
Resources
• In-memory services
• Batching
• CPU affinity/single-threaded
• Resources
• Locally Owned
• Communication
• Resilience and Scalability
• Cloud/Failover
• Journaling
• Microservices
Resources
What are
they?
• REST style URL-addressed
service
• Objected Oriented: data +
methods
/myauction/23456
• Auction
• Shopping Cart
• Atomic counter, list,
queue
@ResourceService
Def - Service that manages
resources
• Each resource owned by one
service
• Saved to local disk
• Replicated
• Partitioned by URL
Atomic Counter
@ResourceService(“public:///counter/{_id}”)
public class CounterServiceImpl
{
private long _id;
private long _counter;
@Modify
public long incrementAndGet()
{
return ++_counter;
}
}
@ResourceService
asy
nc
Fast Local Database
• Store and retrieve resources > key-value
store
• Async, implemented in Baratine services
• Journaled for performance & reliability
• Replicated
Resources
• In-memory services
• Batching
• CPU affinity/single-threaded
• Resources
• Locally Owned
• Communication
• Resilience and Scalability
• Cloud/Failover
• Journaling
• Microservices
Using a Service?
Protocols
• REST – For simple client (like Curl), Baratine provides a REST interface.
• Ajax RPC style – Simple RPC queries, can use a HTTP request where
the payload is the query and the response is the result.
• WebSockets – when websockets is available, provides better
performance
• HTTP long polling – as a WebSocket fallback, Baratine/JAMP can
fallback to HTTP long polling.
Python
PHP
Nodej
s
Communicate!
Jamp/Hamp
JAMP (JSON Active Message Protocol)
Gateway Service
Interfacing with existing
data
• Analytics/ Archive: streaming data for later
processing
• Loading data: using relational databases
• Examples: Hibernate / JPA , Hadoop , SAP , etc…
Resources
• In-memory services
• Batching
• CPU affinity/single-threaded
• Resources
• Locally Owned
• Communication
• Resilience and Scalability
• Cloud/Failover
• Journaling
• Microservices
Scaling & Failover
• Resource partitioning by URL
• Replicated Data
• Backup servers
Client
Bartender
• Manages failover and
scaling
• Baratine within a cluster
• Symmetrical, gossip
protocol
• Heartbeat
• Service pod topology
• Cloud/Dynamic Server
(EC2)
Service Journaling
• Saves inbox method
calls
• Checkpointing
• Recovers on restart
• Replicated for failover
Services
• In-memory services
• Batching
• CPU affinity/single-threaded
• Resources
• Locally Owned
• Communication
• Resilience and Scalability
• Cloud/Failover
• Journaling
• Microservices
Overview
1.
2.
3.
4.
5.
Key-value Store
Journal
Jamp
Bartender
Baratine File
System
6. Service Registry
7. Web Server
7 MB
(No external
dependencies)
Amdahl’s Law
Amdahl’s
Law:
The speedup of a program using multiple processors
in parallel computing is limited by the sequential
fraction of the program. For example, if 95% of the
program can be parallelized, the theoretical maximum
speedup using parallel computing would be 20× as
shown in the diagram, no matter how many
processors are used.
Serial & Parallel
A simple way to build high-performing resource services
• Partition resources for parallelism
• single CPU efficiencies
• CPU affinity
• Batching
• The same hardware can handle 10x to 100x the number of
requests, so you have less vertical scaling to manage. To put it
simply: Do more with less.
Baratine Services
Loosely
Coupled
Event-Driven
Asynchronous
Pub/Sub
Non-Blocking
AGILE!
Microservices
• In-memory services
• Batching
• CPU affinity/single-threaded
• Resources
• Locally Owned
• Communication
• Resilience and Scalability
• Cloud/Failover
• Journaling
• Microservices
Microservices
• Code that adheres to the
principles of SOA
• Faster Development
• Less Hardware
• True Scalability
• Easier to debug
Marton Abbott & Michael Fisher
Where are we now?
Synonyms…
?
Microservices vs SOA
SOA 2.0
Domain Driven Design
Reactive Manifesto
Silo’d Development
2006!
Steve
Jones
Example Code
Implementation
request
(s)
Interfac
e
Baratine Benefits
A simple way to build high-performing resource services
• Combining data + service = resource service
• Flexible REST/HTTP based communication - Do not need
dedicated client library! Writing a non-blocking,
asynchronous RPC service is as simple as writing a Java
class. Can communicate with (Ruby, Go, C#, Java, Python,
JavaScript, etc…).
Example Code
Server:
batc
h
reque
st
futur
e
resul
t
Inbox
wak
e
(Blocking
Does not
need to lock*
Service
Outbox
Performance In Context
Future(blocking) = 186,000 r/s
In-JVM messaging = 4,000,000
r/s
Related Architectures
No architecture specifically
designed for Microservices
Related Architectures
• EJB, JPA, JSF, Jcache, JaxRS
• Can integrate with Java EE
• ESB + Datagrid + Cache +
NoSQL db + Asynch API
•
•
•
•
Gridgain
Redis
MongoDB
Terracotta
Baratine + Existing
war
Cache
Browser/
Client
Load
Balancer
MySQL
UI
Service
Familiarity
Deployable
Maintainable?
Testable
Scalable?
File
System
App Server
Transition… Beer Break!
BACKUP
Baratine
Baratine is a new GPL distributed in-memory Java architecture for
building high-performance web services. Baratine presents a
unification of application and data within the same JVM in a singlethreaded model that goes above and beyond caching and NoSQL
databases. Its actor-based non-blocking architecture ushers in a new
wave of agile microservices that can be quickly built to be inherently
scalable. Baratine allows users to build new resilient services or
integrate their current services into a platform that can be deployed
to hundreds or thousands of servers.
Traditional Problems…
• Modify one => Modify
all
• Long release cycles
• Code Complexity
• A/B , UI testing
Overloaded
IDE/Container
• DB synchronization
• Cache Coherency
• Migration Schema
• Unable to update one
end without updating
another
Traditional Problems…
Decoupling legacy systems
is not easy and still reliant around
DB
Try to avoid distributed
transactions?
Architecture Details
Performance -Single threaded + InMemory
Baratine:
Traditional (Queue):
• Ask inbox for work
• Does 10 units of work
• Ask inbox for work
•…
• Ask queue for work
• Does 1 unit of work
• Ask queue for work
•…
Does not need to block
Needs to block (context switch)
Future(blocking) = 186,000 r/s
Websocket remoting = 500,000
r/s
Service messaging = 4,000,000
r/s
Baratine
• In-memory services
• Batching
• CPU affinity/single-threaded
• Local persistent database
• Object Orientated
• Communication
• Resilience
• Cloud/Failover
• Journaling
• Microservices
1992
C+
+
1995
Jav
a
2000
2003
2006
EJ
B
A HISTORY OF EVENTS
2007
2009
2011
2013
2014
Traditional Architecture
Architecture …
• Need to store and retrieve data > key-value store
• JVM restarts and you need a way to recover > Journal
• Need efficient communication across services > Jamp/
Web Server
• Management within cloud environment > Bartender
Architecture Details
• Deployment in the cloud > Baratine File System
• Need to identify services > Service Registry
• 7 MB!
Baratine
Single-threaded in-memory
services
• Baratine is a new distributed in-memory Java architecture for building highperformance web services.
• Baratine presents a unification of application and data in a singlethreaded model that goes beyond caching and NoSQL databases.
• Its actor-based architecture ushers in a new wave of agile microservices that
are built to be inherently scalable.
• Baratine allows users to build new resilient services or integrate their current
services into a platform that can be deployed to hundreds or thousands of
servers.
Example Programs
Real-Time National Debate
Program
Tailored Coupon App
• Authentication
• Clustered
• Performance
• Responsive
• Scalable
• Deployable
Can be achieved
with a Baratine
Download