29
Detecting Problems in Database Access Code of Large Scale Systems 1 Mohamed Nasser, Parminder Flora Tse-Hsun(Peter) Chen Ahmed E. Hassan Weiyi Shang

CSER2016 - Detecting Problems in Database Access Code of Large Scale Systems

Embed Size (px)

Citation preview

1

Detecting Problems in Database Access Code of Large Scale Systems

Mohamed Nasser, Parminder Flora

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

Existing static analysis tools focus on general anti-patterns in the code

2

Coverity PMD Google error-prone

Facebook InferFindBugs

However, these tools do not detect problems related to how developers use frameworks.

Over 67% of Java developers use Object-Relational Mapping (Hibernate) to access databases

3

22%67%

There is a huge need for framework-specific tools

4

Developers leverage MANY frameworks, but existing tools only support detecting general anti-patterns in the code.

An example class with Java ORM code

5

@Entity@Table(name = “user”)public class User{

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

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

@OneToMany(fetch=FetchType.EAGER)List<Team> teams;

… other getter and setter methods

User.javaUser class is mapped to “user”

table in DB.

id is mapped to the column “id” in the

user table.

A user can belong to multiple teams.

Eagerly retrieve associated teams when retrieving a

user object.

Accessing the database using ORM

6

User u = findUserByID(1);

ORMdatabase

select u from user where u.id = 1;

u.setName(“Peter”);

update user set name=“Peter” where user.id = 1;

Objects SQLs

@Transaction

Developers are often not aware of database access

Wow! I don’t need to worry

about DB code!

ORM code with performance anti-patterns

7

Bad systemperformance

We found that performance problems are common in ORM code (MSR

2016).

Implementing DBChecker

8

Source code

• Static anti-pattern detection tools.

• DBChecker looks for both functional and performance anti-patterns.

• DBChecker is integrated in industrial practice.

Overview of the presentation

9

Anti-patterns Lessons learned when adopting the tool in practice

Overview of the presentation

10

Lessons learned when adopting the tool in practice

Anti-patterns

ORM excessive data anti-patternClass User{ @OneToMany (fetch=FetchType.EAGER)

List<Team> teams;}

User u = findUserById(1);u.getName();EOF

11

Objects

SQL

Eagerly retrieve teams from DB

User Table Team Table

join Team data is never used!

The performance impact of under-optimal ORM code can be significant (ICSE2014, TSE2016).

Nested transaction anti-pattern

12

@Transaction(Propogation.REQUIRED)getUser(){ updateUserGroup(u) …}

Create a DB transaction

@Transaction(Propogation.REQUIRES_NEW)

Conflicting configurations may cause transaction timeout

Misconfigurations can cause both functional and performance problems (ICSE 2016, FSE 2016).

Limitation of current static analysis tools

13

Annotations are lost when converting source code to byte code.

Do not consider how developers configure frameworks.

@Transaction(Propogation.REQUIRED)@EAGER

Many problems are related to

framework configurations.

Many configurations are

set through annotations.

Overview of the presentation

14

Lessons learned when adopting the tool in practice

Most discussed anti-patterns are related to

incorrect usage of frameworks.

Anti-patterns

Overview of the presentation

15

Lessons learned when adopting the tool in practice

Most discussed anti-patterns are related to

incorrect usage of frameworks.

Anti-patterns

Handling a large number of detection results

16

• Developers have limited time to fix detected problems.

• Need to help developers prioritize their efforts.

17

Prioritizing based on DB tablesUser

Time zone

• Problems related to large or frequently-accessed tables are ranked higher (more likely to be performance bottlenecks).

• Problems related to highly dependable tables are ranked higher.

Developers have different backgrounds

18

• Not all developers are familiar with these frameworks and databases.

• Developers may not take the problems seriously if they don’t understand the impact.

Educating developers about the detected problems

19

• We hosted several workshops to educate developers about the impact and cause of the problems.

• Walk developers through examples of detected problems.

• May learn new anti-patterns from developers.

Overview of the presentation

20

Lessons learned when adopting the tool in practice

Most discussed anti-patterns are related to

incorrect usage of frameworks.

We prioritize problems based on DB tables, and

educate developers about the problems.

Anti-patterns

21

22

23

24

25

26

27

28

29

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