gr8conf 2011: grails infinispanplugin, tom fuller

37
Tom Fuller Coherent Logic Limited Introduction to the Grails Infinispan Plugin

Upload: gr8conf

Post on 06-May-2015

722 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Tom FullerCoherent Logic Limited

Introduction to theGrails Infinispan Plugin

Page 2: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Overview

• A story• Design principles• Code examples• Conclusion

Page 3: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Why all the stress?

ApplicationServer

ApplicationServer

Page 4: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 5: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) griffithchris

Page 6: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) Mr. Gunn

Page 7: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Refactor here, optimise there…

ApplicationServer

ApplicationServer

Page 8: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 9: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) amboo who?

Page 10: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) Stephi 2006

Page 11: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Just buy bigger servers

ApplicationServer

ApplicationServer

Page 12: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 13: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) fireflythegreat

Page 14: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) Ray_from_LA

Page 15: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Replicate here, replicate there…

ApplicationServer

ApplicationServer

ApplicationServer

Page 16: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 17: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) Tweek

Page 18: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Where we’re at:

• Optimisation alone won’t solve thisproblem.

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

databases doesn’t work.

Page 19: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

(CC) Mattastic!

Page 20: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

A solution that works!

ApplicationServer

ApplicationServer

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Cache

Page 21: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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.

Page 22: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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!

Page 23: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 24: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Design Principles of the GrailsInfinispan Plugin

(CC) El Bibliomata

Page 25: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

We aim to help developers:

Work with Grails and Groovy naturally.

Page 26: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

We aim to help developers:

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

Page 27: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

We aim to help developers:

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

Page 28: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

}}

}}

}

Page 29: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

}}

}}

}

Page 30: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Use the cacheLoadAgentCacheController {

def agentCachedef index = {

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

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

)}

}}

Page 31: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Execute a transactional operation

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

}

Page 32: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

}

Page 33: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Add closures as listeners

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

}

Page 34: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 35: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 36: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

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

Page 37: GR8Conf 2011: Grails Infinispanplugin, Tom Fuller

Any questions?

Contact meEmail:

[email protected]