GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Post on 06-May-2015

721 views 0 download

Transcript of GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Tom FullerCoherent Logic Limited

Introduction to theGrails Infinispan Plugin

Overview

• A story• Design principles• Code examples• Conclusion

Why all the stress?

ApplicationServer

ApplicationServer

Traffic spike = trouble

Hits per minute

0100002000030000400005000060000700008000090000

100000

10:01

10:02

10:03

10:04

10:05

10:06

10:07

10:08

10:09

10:10

10:11

10:12

10:13

10:30

10:40

10:43

10:45

10:50

Hits per minute

(CC) griffithchris

(CC) Mr. Gunn

Refactor here, optimise there…

ApplicationServer

ApplicationServer

Again – a traffic spike = trouble

Hits per minute

0

20000

40000

60000

80000

100000

120000

140000

10:0

1

10:0

2

10:0

3

10:0

4

10:0

5

10:0

6

10:0

7

10:0

8

10:0

9

10:1

0

10:1

1

10:1

2

10:1

3

10:3

0

10:4

0

10:4

3

10:4

5

10:5

0

10:5

5

Hits per minute

(CC) amboo who?

(CC) Stephi 2006

Just buy bigger servers

ApplicationServer

ApplicationServer

Traffic spike = trouble

Hits per minute

0

50000

100000

150000

200000

250000

10:0

1

10:0

2

10:0

3

10:0

4

10:0

5

10:0

6

10:0

7

10:0

8

10:0

9

10:1

0

10:1

1

10:1

2

10:1

3

10:3

0

10:4

0

10:4

3

10:4

5

10:5

0

10:5

5

Hits per minute

(CC) fireflythegreat

(CC) Ray_from_LA

Replicate here, replicate there…

ApplicationServer

ApplicationServer

ApplicationServer

No surprise – a traffic spike =trouble

Hits per minute

0

50000

100000

150000

200000

250000

300000

350000

400000

10:01

10:03

10:05

10:07

10:09

10:11

10:13

10:40

10:45

10:55

11:05

Hits per minute

(CC) Tweek

Where we’re at:

• Optimisation alone won’t solve thisproblem.

• Neither will larger servers.• Scaling the application server and

databases doesn’t work.

(CC) Mattastic!

A solution that works!

ApplicationServer

ApplicationServer

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Infinispan

• Based in part on code from JBoss Cache• Licensed under the LGPL• Is a distributed in-memory data grid• Has competition• As of May 2011 Infinispan is officially

supported by Red Hat.

Hits per minute

0

100000

200000

300000

400000

500000

600000

10:01

10:03

10:05

10:07

10:09

10:11

10:13

10:40

10:45

10:55

11:05

Hits per minute

Traffic spike = not a problem!

Just grow the grid!

* NOTE: Caveat with session clustering.

ApplicationServer

ApplicationServer

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Design Principles of the GrailsInfinispan Plugin

(CC) El Bibliomata

We aim to help developers:

Work with Grails and Groovy naturally.

We aim to help developers:

Work with Grails and Groovy naturally.Avoid and diagnose problems quickly.

We aim to help developers:

Work with Grails and Groovy naturally.Avoid and diagnose problems quickly.Save time.

Configuring Infinispan in Grailsdevelopment {

infinispan = {register {

cacheManager {named "matrixCacheManager"

configured {externally {

using "grails-app/conf/infinispan/infinispan-config.xml"}

}caches "agentCache", “citiesCache"

}queryHelper {

named "agentQueryHelper"referencing "agentCache"properties queryHelperPropertiesclasses infinispantestapp.Agent, infinispantestapp.SuperHero

}}

}}

}

Configuring Infinispan in Grailsproduction {

infinispan = {register {

cacheManager {named "matrixCacheManager"configured {

declaratively {using globalConfigurationusing configuration

}}caches "agentCache", "illinoisCitiesCache"

}queryHelper {

named "agentQueryHelper"referencing "agentCache"properties queryHelperPropertiesclasses infinispantestapp.Agent, infinispantestapp.SuperHero

}}

}}

}

Use the cacheLoadAgentCacheController {

def agentCachedef index = {

for (int ctr in 1..1000) {agentCache.put (

"person id $ctr",new Agent (name:"Agent Smith",weapon:"gun")

)}

}}

Execute a transactional operation

cache.transactionally {cache.put(someKey, someValue);cache.remove(someOtherKey);

}

Query and iterate over the results

def term = new Term (WEAPON, GUN)def termQuery = new TermQuery (term)

def results = agentCache.query (queryHelper,Agent, termQuery)

results.each {log.info ("it: $it")

}

Add closures as listeners

agentCache.onCacheEntryCreated {log.info ("Cache entry created: $it")

}

Food for Thought

• Infinispan 5.0 is currently underdevelopment and will deliver fork/join andmap/reduce implementations.

• Infinispan can help reduce costs for anydata source.

• Infinispan can be very useful in the cloudand service-oriented architectures (SOA).

App lica tionServer

App lica tionServer

App lica tionServer

App lica tionServer

C u sto m erIn fo rm atio n

App lica tionServer

App lica tionServer

A n a ly tics

P ro d u ctin fo rm atio n

P aym en tp ro cess in g ,

S h ip p in g

App lica tionServer

App lica tionServer

O rd erp ro cess in g

P artn erreg istra tio n

P artn er & p ro d u ctin fo rm atio n

App lica tionServer

App lica tionServer

O rd erh isto ry O rd er

h isto ry

Conclusion

• Three attempts that failed to deliver asolution that could cope with the load.

• Design principles behind the GrailsInfinispan Plugin.

• Example code.• Further documentation is available at

http://www.grails.org/plugin/infinispan

Any questions?

Contact meEmail:

thomas.fuller@coherentlogic.com