common jboss data grid architectures

Post on 30-Dec-2016

230 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Common JBoss Data Grid Architectures

Ray Tsang (rtsang@redhat.com) Solution Architect, Red Hat

June 10, 2013

© Ray Tsang, All Rights Reserved

Lots of Reads Web Service

Application

Web Service Web Service

Use Design Patterns

Application

Service Layer

DAO

Web Service Web Service Web Service

Easy!

Application

Service Layer

DAO

Web Service Web Service Web Service

Cache

Cache

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

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

2. Update Cache

1. Write Data to System or Record

© Ray Tsang, All Rights Reserved

JVM

Application

Service Layer

DAO

Cache

•  Embedded in your application

•  Same JVM •  Faster access to

cached objects

JVM

Application

Service Layer

DAO

Cache

JVM Heap

Application

Cache?

Manage Size of Cache •  Eviction

– Max number of elements

•  Expiration – Expire after lifespan, or max idle

•  Hit Ratio

Use Cases!

See Documentation for Embedded Library Mode vs Remote Server mode differences

Non-­Java

Share Data

Application Data

Advanced API

Transaction

JPA 2LC

© Ray Tsang, All Rights Reserved

JDG Server JVM

Application

Service Layer

DAO

Cache Cache

Cache Client Hot Rod

REST Memcached

JDG Server CRM Application

Cache Cache

Cache

Hot Rod

Self Service

Mobile

PHP Application Memcached

REST

Hot Rod

JDG Server Web Application

Cache Cache

Cache

Hot Rod

External Loader Hot Rod

Use Cases!

Transaction

Advanced API

Share Data

Non-­Java

Big Data

See Documentation for Embedded Library Mode vs Remote Server mode differences

© Ray Tsang, All Rights Reserved

Embedded Cache Remote Cache

Replicated

Distributed

Node 1

Replicated

Cache

Node 2

Cache

Node N

Cache

App Server

Web App

Service Layer

DAO

Web Content

App Server

Web App

Service Layer

DAO

Web Content

Replicated Lo

ad B

alan

cer

Use Cases!

Big Data Heavy Reads

Extreme Redundancy

Heavy Write

Scaling Application Data

Node 1

Cache

Node 2

Cache

Node 3

Cache A

B

C

Node 1

Cache

Node 2

Cache

Node 3

Cache A

A

B

B C

C

N-­Copies for Redundancy

Node 1

Cache

A B

Node 2

Cache

B C

Node 3

Cache

A

Node 4

Cache

More Capacity!

B

Node 1

Cache

A B

Node 2

Cache

B C

Node 3

Cache

A

Node 4

Cache

C

Rebalanced!

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Load Balancer HTTP

Oh No!

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “C”

Use Cases!

Good Reads

Great Redundancy

Big Data Scaling

Good Writes

Non-­Hot Rod

© Ray Tsang, All Rights Reserved

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Load Balancer REST

Oh No!

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

Node 1

Cache

Node 2

Cache

Node N

Cache

A A B B

C C

I need “A”

Load Balancer REST

A

Use Cases!

Distributed Cache

Not Using Hot Rod Mostly Reads

Memory Consumption

High Saturation

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

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

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

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

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”

Use Cases!

Scaling

Keep Data Close

Share Data

Heavy Read

Heavy Write

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>

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>

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

Use Cases!

Multiple Data Centers

Keep Data Close

Share Data

Online DR

JBoss Data Grid

More Than Just a Cache!

© Ray Tsang, All Rights Reserved

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

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

Get From JDG Not in Cache

Load It

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

2. Update Cache

1. Write Data to System or Record

System of Record

Application

Service / DAO

Web Service Web

Service Web Service Cache

Update Cache Persist Data

Cache Stores •  JDBC •  Filesystem •  Open Source

–  JPA – MongoDB –  Cassandra

•  Write Your Own! – Map to your own

data

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

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

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

Application

Query Cache

select * from … where …

Tech Preview

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

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

Use Cases! Full Text Query

Big Data

Query Pagination

Sorting

Heavy Write

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

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);;

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;;

Use Cases!

Analytics Statistics

Distribute Work Heavy Write

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

•  Must Use Embedded Library Mode

Data Grid as a Service

© Ray Tsang, All Rights Reserved

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

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();;

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());;

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

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();;

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

JBoss Tusk – Smart Data •  Created by Justin Hayes (jhayes@redhat.com) •  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

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

Thanks!

Q & A

© Ray Tsang, All Rights Reserved

Ray Tsang (rtsang@redhat.com) Red Hat Solution Architect

© Ray Tsang, All Rights Reserved

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

top related