fse2016 - cacheoptimizer: helping developers configure caching frameworks for hibernate-based...

31
CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-Centric Web Applications 1 Mohamed Nasser, Parminder Flora Tse-Hsun(Peter) Chen Ahmed E. Hassan Weiyi Shang

Upload: blackberry

Post on 13-Jan-2017

88 views

Category:

Software


0 download

TRANSCRIPT

Page 1: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

1

CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based

Database-Centric Web Applications

Mohamed Nasser, Parminder Flora

Tse-Hsun(Peter) Chen Ahmed E. HassanWeiyi Shang

Page 2: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

– Over 1 billion page views per day– 44 billion SQL executions per day

– 8 billion minutes online everyday– Over 1.2 million photos a sec at

peak

Modern Database-Centric Web Applications: Millions of Users, Billions of Transactions

Page 3: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Gmail’s 25 to 55 minutes outage affected 42 million users.

Azure service was interrupted for 11hrs, affecting Azure users world-wide.

Down time of large-scale applications is very costly

Jan 24th Nov 19th Oct 28th

Facebook went down for 35 minutes, losing $854,700.

2014

Page 4: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Gmail’s 25 to 55 minutes outage affected 42 million users.

Azure service was interrupted for 11hrs, affecting Azure users world-wide.

Down time of large systems is very costly

Jan 24th Nov 19th Oct 28th

Facebook went down for 35 minutes, losing $854,700.

2014

Often caused by performance problems

Page 5: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

5

$1.6 billion loss for a one-second slowdown

Page 6: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

6

Slow database access is often the performance bottleneck

Page 7: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

7

Application-level caches improve performance

Hibernate

Application server

databaseUser

Need developers to manually tell the frameworks what should be cached!

Application-level caches

Page 8: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Over 67% of Java developers use Hibernate to access databases

8

22%67%

We focus on Hibernate due to its popularity, but our approach should be applicable to

other database technologies

Page 9: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

An example class with Hibernate code

9

@Entity@Table(name = “group”)@Cacheablepublic class Group{

@Column(name=“id”)private int id;

@Column(name=“name”)String groupName;

String User findGroupById(id){query = “select g from

Group where g.id = id”;

query.execute().cache(); }

Group.javaUser class is

mapped to “group” table in DB

id is mapped to the column “id” in the

user table

Query-level cache(cache query

result)

Object-level cache (cache retrieval by id)

There can be thousands of possible cache configurations

Page 10: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

10

Optimal cache configuration is often determined by how users use the application

Page 11: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Caching helps improve performance

11

Group g = findGroupByID(1);

Hibernatedatabase

App-levelcache

Application server

Group g = findGroupByID(1);

Group1

Page 12: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Hibernate App-levelcache

Sub-optimal cache configurations are harmful to performance

12

Group u = findGroupByID(1);

database

Application server

g.setName(“FSE”)

Group g = findGroupByID(1);

Group1

It is important to understand user behaviors in order to find the optimal cache

configuration

Page 13: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Problem: Understanding user behavior in production is very difficult

13

User

Hibernate

Application server

Optimal cache configuration evolves in production, which requires regular update

Instrumentation adds too much overhead!

Page 14: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Our solution: Recover user behaviors by analyzing readily-available logs

14

User

Source Code

Applicationserver Database

CacheOptimizer

Apply optimal cache config

Update executable

Page 15: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Overview of CacheOptimizer

15

Source Code

Database access

informationStatic analysis

Page 16: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Apply static analysis to extract database access information

16

@Get@Path(“/group/{id}”)Group getGroup(id){ getGroupById(id); …}

Group getGroupById(id){ select from Group g where g.id = id …}

Finding HTTP request handler methods by analyzing annotations

Apply inter-procedural data flow analysis to see if inputs from the HTTP request are used as querying criteria

Page 17: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Overview of CacheOptimizer

17

Source Code

Database access

information@Get@Path(‘/group/{id}’) select from Group u where g.id = id …

Static analysis

System running in production

Build

System

10.10.10.1 - - [11/Apr/2015:12:19:

30] 200 “GET /app/group/1 ” …

User database accesses

Page 18: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Example: Recovered database access

18

10.10.10.1 - - [11/Apr/2015:12:19:30] 200 “GET /app/group/1 ” 10.10.10.1 - - [11/Apr/2015:12:19:31] 200 “GET /app/group/2 ”10.10.10.1 - - [11/Apr/2015:12:19:32] 200 “GET /app/group/1 ”

@Get@Path(“/group/{id}”)Group getGroup(id){ … select from Group g where g.id = id …}

Read operation on Group table, record with id 1, time is 11/Apr/2015:12:19:30

Read operation on Group table, record with id 2, time is 11/Apr/2015:12:19:31

Read operation on Group table, record with id 1, time is 11/Apr/2015:12:19:32

Page 19: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Overview of CacheOptimizer

19

Source Code

Static analysis

System running in production

Build

System

10.10.10.1 - - [11/Apr/2015:12:19:

30] 200 “GET /app/group/1 ” …

User database accesses

Cache configuration

Database access

information@Get@Path(‘/group/{id}’) select from Group u where g.id = id …

Page 20: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Calculating optimal cache configuration via workload simulation

20

Incoming request

Cache hit

Invalidated cache

Read group with id 1

Update group with id 1

Cache consideration

No longer considered for

caching

TimeMiss ratio is ½ (one cache hit)

We keep track of the cache miss ratio for each potential cache location

Page 21: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Studied applications

Performance benchmarking

e-commence application> 35K LOC

Medical record application> 3.8M LOC

Simple open-sourceapplication for a pet clinic

3.3K LOC

21

• We use JMeter tests to simulate user behaviours

• Database is pre-populated with hundreds of MB of data

Page 22: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

Comparing throughput improvements under different cache configs

22

• CacheAll: Enable all caches

• Default: Cache configurations that are already added in the application (what developers think should be cached)

• CacheOptimizer: The optimal cache config discovered using CacheOptimizer

We compare three different cache configurations against having no cache (baseline)

Page 23: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

CacheOptimizer gives significant improvements over other configs

23

0%

50%

100%

150%

0%10%20%30%40%50%

% o

f thr

ough

put

impr

ovem

ent o

ver h

avin

g no

cac

he

CacheAll DefaultCacheOpt

0%

10%

20%

30%CacheAll DefaultCacheOpt

CacheAll DefaultCacheOpt

Page 24: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

24

Page 25: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

25

Page 26: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

26

Page 27: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

27

Page 28: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

28

Page 29: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

29

Page 30: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

30

Page 31: FSE2016 - CacheOptimizer: Helping Developers Configure Caching Frameworks for Hibernate-based Database-centric Web Applications

31

Tse-Hsun (Peter) Chen http://petertsehsun.github.io