+ All Categories
Home > Software > How to Speed up your Database

How to Speed up your Database

Date post: 11-May-2015
Category:
Upload: hazelcast
View: 383 times
Download: 1 times
Share this document with a friend
Description:
www.hazelcast.com
Popular Tags:
19
© 2014 Hazelcast Inc. How to speed up your Database. DAVID BRIMLEY SENIOR SOLUTIONS ARCHITECT
Transcript
Page 1: How to Speed up your Database

© 2014 Hazelcast Inc.

How to speed up your Database.

DAVID BRIMLEYSENIOR SOLUTIONS ARCHITECT

Page 2: How to Speed up your Database

© 2014 Hazelcast Inc.

About me

2

"Senior Solutions Architect for Hazelcast.

Oracle Coherence @ HSBC 2007-2010 Gemfire @ Nomura 2010 - 2013

Worked for Major Investment Banks in the City of London.

Java Programmer since 1998.

David Brimley @dbrimley

Page 3: How to Speed up your Database

© 2014 Hazelcast Inc.

Agenda - 40 Minutes + Q&A time.

• Introduction to Hazelcast.

• The Slow Database problem.

• Adding Hazelcast for faster queries.

• And doing the same for inserts and updates.

• Q&A

3

Page 4: How to Speed up your Database

© 2014 Hazelcast Inc.

Introduction to Hazelcast

• Hazelcast the Open Source Projectwww.hazelcast.org""

• Hazelcast the Companywww.hazelcast.com

4

Page 5: How to Speed up your Database

© 2014 Hazelcast Inc.

The Slow Database Problem

• Traditional Databases are hard to scale.

• They cost a lot in time and effort.

• Common solution is a Cache.""

• IMDG like Hazelcast give horizontal scalability.

5

Page 6: How to Speed up your Database

© 2014 Hazelcast Inc.

The Hazelcast Approach

• Cluster of JVM that all contribute memory.

• Client API can work against Maps.

• Query using Predicates or SQL like strings.""

• Faster Reads using the Cache.

• Faster Update/Inserts using write-behind.

6

Page 7: How to Speed up your Database

© 2014 Hazelcast Inc.

The Test Suite

• Postgres 9.3.4 installed on a Macbook Pro Dual Core with 16gb RAM and 256gb SSD.

• Dataset : Stackoverflow Public Dump (47gb)

• Hazelcast 3.2

7

Page 8: How to Speed up your Database

© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.

The Simple Postgres Java DAO

8

Page 9: How to Speed up your Database

© 2014 Hazelcast Inc.

Step 1 : Configure the Hazelcast Distributed Map."A) MapStore for connecting Hazelcast to the Database."B) Configure Indexes for faster In Memory Query of Map."

"

Integrating Hazelcast in 4 steps

9

" <map name="user"> <map-store enabled="true"> <class-name>com.craftedbytes.hazelcast.dao.UserMapStore</class-name> <write-delay-seconds>30</write-delay-seconds> </map-store> <indexes> <index ordered="true">location</index> </indexes> </map>

"

Page 10: How to Speed up your Database

© 2014 Hazelcast Inc.

Integrating Hazelcast in 4 steps

Step 2 : Code your MapStore implementation"

10

"public class UserMapStore implements MapStore<Integer, User> { " private UserDAO userDao = new UserDAO(); " private UserMapStore() {} " @Override public void store(Integer userKey, User user) { userDao.insertUser(user); } @Override public User load(Integer userKey) { return userDao.getUser(userKey); } " @Override public Map<Integer, User> loadAll(Collection<Integer> userKeys) { return userDao.loadAll(userKeys); } "

Page 11: How to Speed up your Database

© 2014 Hazelcast Inc.

Integrating Hazelcast in 4 steps

Step 3 : Query against a Java Map !"

11

" @Override public Collection<User> getUserByLocation(String location){ return userMap.values(Predicates.equal("location", location)); } " @Override public User getUser(Integer userKey) { return userMap.get(userKey); } " @Override public void removeUser(Integer userKey) { userMap.evict(userKey); } " @Override public void addUsers(Map<Integer,User> users) { userMap.putAll(users); } ""

Page 12: How to Speed up your Database

© 2014 Hazelcast Inc.

Integrating Hazelcast in 4 steps

Step 4 : Start your cluster !

Hazelcast will prime from Database using the loadAllKeys method from your MapStore.""No changes were required to the Database.

12

Page 13: How to Speed up your Database

© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.

Hazelcast for faster reads

13

Page 14: How to Speed up your Database

© 2014 Hazelcast Inc.

Hazelcast will read through to Database

• If you only load a subset of data from your whole set.

• Hazelcast will use the MapStore to read to the Database to cache a Map Entry on a Cache Miss.

14

Page 15: How to Speed up your Database

© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.

Hazelcast read-through to DB

15

Page 16: How to Speed up your Database

© 2014 Hazelcast Inc.

Hazelcast can make updates faster as well

• A Map put can be async to the Database.

• Write behind stores records and writes to DB after delay.

• The User doesn’t have to wait for the DB to complete, once entry hits cache the transaction is complete.

16

Page 17: How to Speed up your Database

© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.© 2014 Hazelcast Inc.

Hazelcast write-behind to DB

17

Page 18: How to Speed up your Database

© 2014 Hazelcast Inc.

Q&A

ANY QUESTIONS?

18

Page 19: How to Speed up your Database

© 2014 Hazelcast Inc.


Recommended