common jboss data grid architectures

75
Common JBoss Data Grid Architectures Ray Tsang ([email protected] ) Solution Architect, Red Hat June 10, 2013

Upload: phungmien

Post on 30-Dec-2016

229 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Common JBoss Data Grid Architectures

Common JBoss Data Grid Architectures

Ray Tsang ([email protected]) Solution Architect, Red Hat

June 10, 2013

Page 2: Common JBoss Data Grid Architectures

© Ray Tsang, All Rights Reserved

Page 3: Common JBoss Data Grid Architectures

Lots of Reads Web Service

Application

Web Service Web Service

Page 4: Common JBoss Data Grid Architectures

Use Design Patterns

Application

Service Layer

DAO

Web Service Web Service Web Service

Page 5: Common JBoss Data Grid Architectures

Easy!

Application

Service Layer

DAO

Web Service Web Service Web Service

Cache

Cache

Page 6: Common JBoss Data Grid Architectures

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

1. Cached?

2. If not in Cache, Load It

3. Store in Cache

Page 7: Common JBoss Data Grid Architectures

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

2. Update Cache

1. Write Data to System or Record

Page 8: Common JBoss Data Grid Architectures

© Ray Tsang, All Rights Reserved

Page 9: Common JBoss Data Grid Architectures

JVM

Application

Service Layer

DAO

Cache

•  Embedded in your application

•  Same JVM •  Faster access to

cached objects

Page 10: Common JBoss Data Grid Architectures

JVM

Application

Service Layer

DAO

Cache

JVM Heap

Application

Cache?

Page 11: Common JBoss Data Grid Architectures

Manage Size of Cache •  Eviction

– Max number of elements

•  Expiration – Expire after lifespan, or max idle

•  Hit Ratio

Page 12: Common JBoss Data Grid Architectures

Use Cases!

See Documentation for Embedded Library Mode vs Remote Server mode differences

Non-­Java

Share Data

Application Data

Advanced API

Transaction

JPA 2LC

Page 13: Common JBoss Data Grid Architectures

© Ray Tsang, All Rights Reserved

Page 14: Common JBoss Data Grid Architectures

JDG Server JVM

Application

Service Layer

DAO

Cache Cache

Cache Client Hot Rod

REST Memcached

Page 15: Common JBoss Data Grid Architectures

JDG Server CRM Application

Cache Cache

Cache

Hot Rod

Self Service

Mobile

PHP Application Memcached

REST

Hot Rod

Page 16: Common JBoss Data Grid Architectures

JDG Server Web Application

Cache Cache

Cache

Hot Rod

External Loader Hot Rod

Page 17: Common JBoss Data Grid Architectures

Use Cases!

Transaction

Advanced API

Share Data

Non-­Java

Big Data

See Documentation for Embedded Library Mode vs Remote Server mode differences

Page 18: Common JBoss Data Grid Architectures

© Ray Tsang, All Rights Reserved

Page 19: Common JBoss Data Grid Architectures

Embedded Cache Remote Cache

Replicated

Distributed

Page 20: Common JBoss Data Grid Architectures

Node 1

Replicated

Cache

Node 2

Cache

Node N

Cache

Page 21: Common JBoss Data Grid Architectures

App Server

Web App

Service Layer

DAO

Web Content

App Server

Web App

Service Layer

DAO

Web Content

Replicated Lo

ad B

alan

cer

Page 22: Common JBoss Data Grid Architectures

Use Cases!

Big Data Heavy Reads

Extreme Redundancy

Heavy Write

Scaling Application Data

Page 23: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node 3

Cache A

B

C

Page 24: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node 3

Cache A

A

B

B C

C

N-­Copies for Redundancy

Page 25: Common JBoss Data Grid Architectures

Node 1

Cache

A B

Node 2

Cache

B C

Node 3

Cache

A

Node 4

Cache

More Capacity!

B

Page 26: Common JBoss Data Grid Architectures

Node 1

Cache

A B

Node 2

Cache

B C

Node 3

Cache

A

Node 4

Cache

C

Rebalanced!

Page 27: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Load Balancer HTTP

Oh No!

Page 28: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Page 29: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “C”

Page 30: Common JBoss Data Grid Architectures

Use Cases!

Good Reads

Great Redundancy

Big Data Scaling

Good Writes

Non-­Hot Rod

Page 31: Common JBoss Data Grid Architectures

© Ray Tsang, All Rights Reserved

Page 32: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Load Balancer REST

Oh No!

Page 33: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Load Balancer REST

A

Copy to L1 Cache

Page 34: Common JBoss Data Grid Architectures

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Load Balancer REST

A

Page 35: Common JBoss Data Grid Architectures

Use Cases!

Distributed Cache

Not Using Hot Rod Mostly Reads

Memory Consumption

High Saturation

Page 36: Common JBoss Data Grid Architectures

JDG Cluster (Distributed)

JDG Server N

Cache A C

JDG Server 2

Cache

B C

JDG Server 1

Cache A

B

App Server

Web App

Service Layer

DAO

Cache

App Server

Web App

Service Layer

DAO

Cache

Hot Rod

Hot Rod

Client

Client

Load Balancer

Page 37: Common JBoss Data Grid Architectures

JDG Cluster (Distributed)

JDG Server N

Cache A C

JDG Server 2

Cache

B C

JDG Server 1

Cache A

B

App Server

Web App

Service Layer

DAO

Cache

App Server

Web App

Service Layer

DAO

Cache Hot Rod

Client

Client

Load Balancer

I need “A”

HTTP

Page 38: Common JBoss Data Grid Architectures

JDG Cluster (Distributed)

JDG Server N

Cache A C

JDG Server 2

Cache

B C

JDG Server 1

Cache A

B

App Server

Web App

Service Layer

DAO

Cache

App Server

Web App

Service Layer

DAO

Cache

Client

Client

Load Balancer

I need “A”

HTTP

Retrieved

From Remote Cache A

Page 39: Common JBoss Data Grid Architectures

JDG Cluster (Distributed)

JDG Server N

Cache A’ C

JDG Server 2

Cache

B C

JDG Server 1

Cache A’

B

App Server

Web App

Service Layer

DAO

Cache

App Server

Web App

Service Layer

DAO

Cache

Client

Client

Load Balancer

Save “A”

HTTP

A’

Update Copy

A

Page 40: Common JBoss Data Grid Architectures

JDG Cluster (Distributed)

JDG Server N

Cache A’ C

JDG Server 2

Cache

B C

JDG Server 1

Cache A’

B

App Server

Web App

Service Layer

DAO

Cache

App Server

Web App

Service Layer

DAO

Cache

Client

Client

Load Balancer

Save “A”

HTTP

A’

A

Invalidate “A”

Page 41: Common JBoss Data Grid Architectures

Use Cases!

Scaling

Keep Data Close

Share Data

Heavy Read

Heavy Write

Page 42: Common JBoss Data Grid Architectures

Configure Remote Cache <server> … <profile> … <subsystem xmlns="urn:infinispan:server:core:5.2" default-­cache-­

container="clustered”> <cache-­container name="clustered" default-­cache="default"> <cache-­container> <distributed-­cache name=”RemoteUsersCache" mode="SYNC" start="EAGER"/> </cache-­container> </subsystem> </profile> </server>

Page 43: Common JBoss Data Grid Architectures

Embedded + Remote <?xml version="1.0" encoding="UTF-­8"?> <infinispan …> … <namedCache name=“EmbeddedUsersCache”> <clustering mode="invalidation">…</clustering> <loaders> <remoteStore shared=”true” remoteCache=”RemoteUserCache" rawValues="true"> <servers> <server host=”remoteServer”/> </servers> <connectionPool maxActive="10" exhaustedAction="CREATE_NEW" /> <async enabled="true" /> <!– or false, depending on your use case -­-­> </remoteStore> </loaders> </namedCache> … </infinispan>

Page 44: Common JBoss Data Grid Architectures

JDG Cluster (Los Angeles)

JDG Server N

Cache A C

JDG Server 2

Cache

B C

JDG Server 1

Cache A

B

JDG Cluster (New York)

JDG Server N

Cache A C

JDG Server 2

Cache

B C

JDG Server 1

Cache A

B Cross Site Replication

Page 45: Common JBoss Data Grid Architectures

Use Cases!

Multiple Data Centers

Keep Data Close

Share Data

Online DR

Page 46: Common JBoss Data Grid Architectures

JBoss Data Grid

More Than Just a Cache!

© Ray Tsang, All Rights Reserved

Page 47: Common JBoss Data Grid Architectures

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

1. Cached?

2. If not in Cache, Load It

3. Store in Cache

Page 48: Common JBoss Data Grid Architectures

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

Get From JDG Not in Cache

Load It

Page 49: Common JBoss Data Grid Architectures

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

2. Update Cache

1. Write Data to System or Record

Page 50: Common JBoss Data Grid Architectures

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

Update Cache Persist Data

Page 51: Common JBoss Data Grid Architectures

Cache Stores •  JDBC •  Filesystem •  Open Source

–  JPA – MongoDB –  Cassandra

•  Write Your Own! – Map to your own

data

Page 52: Common JBoss Data Grid Architectures

System of Record

Application

Service / DAO

Cache

JDG Server 1

Cache

B C

JDG Server 2

Cache

B C

JDG Server N

Cache

B C

Page 53: Common JBoss Data Grid Architectures

JDG Cluster (Distributed)

JDG Server N

Cache A C

JDG Server 2

Cache

B C

JDG Server 1

Cache A

B

App Server

Web App

Service Layer

DAO

Cache

App Server

Web App

Service Layer

DAO

Cache

Hot Rod

Hot Rod

Client

Client

Load Balancer

Page 54: Common JBoss Data Grid Architectures

Application select * from … where … and lots and lots of where conditions …

Page 55: Common JBoss Data Grid Architectures

Application

Query Cache

select * from … where …

Tech Preview

Page 56: Common JBoss Data Grid Architectures

Annotated POJO @Indexed public class Book @Field String title;; @Field String description;; @Field @DateBridge(resolution=Resolution.YEAR)

Date publicationYear;; @IndexedEmbedded Set<Author> authors

= new HashSet<Author>();;

Tech Preview

Page 57: Common JBoss Data Grid Architectures

Query API SearchManager searchManager = Search.getSearchManager(cache);; Query query = … //any Apache Lucene Query // convert the Lucene query to a CacheQuery: CacheQuery cacheQuery = searchManager.getQuery( query );; // get the results List<Object> found = cacheQuery.list();;

Tech Preview

Page 58: Common JBoss Data Grid Architectures

Use Cases! Full Text Query

Big Data

Query Pagination

Sorting

Heavy Write

Page 59: Common JBoss Data Grid Architectures

Bring your code to the data •  Distributed Execution •  Map Reduce

Page 60: Common JBoss Data Grid Architectures

Map Reduce public class WordCountMapper implements Mapper<String,String,String,Integer> … public void map(String key, String value, Collector<String, Integer> collector) StringTokenizer tokens = new StringTokenizer(value);; while (tokens.hasMoreElements()) String s = (String) tokens.nextElement();; collector.emit(s, 1);;

Page 61: Common JBoss Data Grid Architectures

Map Reduce public class WordCountReducer implements Reducer<String, Integer> … public Integer reduce(String key, Iterator<Integer> iter) int sum = 0;; while (iter.hasNext()) Integer i = (Integer) iter.next();; sum += i;; return sum;;

Page 62: Common JBoss Data Grid Architectures

Use Cases!

Analytics Statistics

Distribute Work Heavy Write

Page 63: Common JBoss Data Grid Architectures

Embedded Library Mode! •  Map Reduce •  Transaction •  Query (Technical Preview)

•  Must Use Embedded Library Mode

Page 64: Common JBoss Data Grid Architectures

Data Grid as a Service

© Ray Tsang, All Rights Reserved

Page 65: Common JBoss Data Grid Architectures

App Server

EJB

Service EJB

DAO

Data

App Server

EJB

Service EJB

DAO

Data

EJB Call

Cache Store

Cache Store

Application

EJB Client Clustered -­ Distributed

Page 66: Common JBoss Data Grid Architectures

Enterprise Java Bean public interface CrudGridService<K, V> public void put(V object);; public void remove(K key);; public V findByKey(K key);; public Page<V> findAll(PageRequest pageRequest);; public Page<V> findAll(PageRequest pageRequest,

GenericQuery genericQuery);; public Long count();; public void clear();;

Page 67: Common JBoss Data Grid Architectures

Enterprise Java Bean protected Page<V> executePaginatedQuery(Query query, PageRequest pageRequest, Class<?> ... classes) List<V> items = null;; int totalResults = 0;; CacheQuery cq = searchManager.getQuery(query, classes);; if (pageRequest != null) totalResults = cq.getResultSize();; cq.firstResult((pageRequest.getPage() -­ 1) * pageRequest.getPageSize());; cq.maxResults(pageRequest.getPageSize());; if (pageRequest.getSort() != null) cq.sort(pageRequest.getSort());; List<Object> result = cq.list();; return new Page<V>(pageRequest, (List<V>) (List<?>) result, totalResults);; else items = (List<V>) (List<?>) cq.list();; return new Page<V>(new PageRequest(1, items.size()), items, items.size());;

Page 68: Common JBoss Data Grid Architectures

Enterprise Java Bean @Default @Stateless @Remote(UserGridService.class) @Clustered @TransactionManagement(TransactionManagementType.CONTAINER) @TransactionAttribute(…) public class UserGridServiceBean extends AbstractCrudGridServiceBean<String, User> implements UserGridService …

Page 69: Common JBoss Data Grid Architectures

Client UserGridService gridService = (UserGridService ) context .lookup(”ejb:grid-­service-­ear/grid-­service-­ejb/UserGridService!” + UserGridService.class.getName());; User user = gridService.findByKey(“raytsang”);; Page<User> users = gridService.findAll(new PageRequest(1, 10));; Page<User> users = gridService.findAll(new UserQuery(…), new PageRequest(1, 10));; UserTransaction txn = …;; txn.begin();; gridService.put(“raytsang”, updatedUser1);; gridService.put(“jane”, updatedUser2);; gridService.remove(“charlie”);; txn.commit();;

Page 70: Common JBoss Data Grid Architectures

Other Possibilities •  Create your own Data Grid Service

– Analytics with Map Reduce operations – Query

•  Multiple Intakes – EJB service, Web Service, or… –  Ingest data steam from a queue

Page 71: Common JBoss Data Grid Architectures

JBoss Tusk – Smart Data •  Created by Justin Hayes ([email protected]) •  JBoss Reference Architecture Suitable for

Addressing Big Data Integration Use Cases •  TB of Log Data, Activities, etc •  Need to swap out RDBMS and expensive/laborious

process with more scalable, cost effective one

Page 72: Common JBoss Data Grid Architectures

App Server App Server App Server

EJB

Ingester MDB

Service EJB

JDG Appliance Data

Stream

User Activity Stream

Mobile / Device

Data Stream

MRG

M / A

-­MQ

Red Hat Storage

Real Time Analytics

Long Term Storage

Data Transform

ation / Business R

ules

Page 73: Common JBoss Data Grid Architectures

Thanks!

Q & A

© Ray Tsang, All Rights Reserved

Page 74: Common JBoss Data Grid Architectures

Ray Tsang ([email protected]) Red Hat Solution Architect

© Ray Tsang, All Rights Reserved

Page 75: Common JBoss Data Grid Architectures

Links and Materials •  JBoss Tusk Presentation

–  http://rhsummit.files.wordpress.com/2012/03/hayes_jboss_enterprise_middleware_and_big_data1.pdf

•  JBoss Tusk Git Hub –  https://github.com/jboss-tusk/tusk