Download presentation
Presentation is loading. Please wait.
Published bySimon Walton Modified over 9 years ago
1
Making Database Applications Perform Using Program Analysis Alvin Cheung Samuel Madden Armando Solar-Lezama MIT Owen Arden Andrew C. Myers Cornell
2
Developing Database Applications 2/1/13NEDB '132 Application Server SQL Database Java Application Logic SQL Query
3
Developing Database Applications 2/1/13NEDB '133 SQL Database Java Application Logic PL/SQL Stored Procedures SQL Query Application Server
4
Developing Database Applications 2/1/13NEDB '134 SQL Database Java Application Logic PL/SQL Stored Procedures SQL Query Application Server Language Choice for Application Logic Application Distribution Program analysis to the rescue!
5
StatusQuo Express application logic in ways that programmers are comfortable with Job of compiler & runtime to determine the most efficient implementation 2/1/13NEDB '135
6
Two Key Technologies Infer queries from imperative code Migrate computation between servers for optimal performance 2/1/13NEDB '136
7
Relational Operations in Imperative Code 2/1/13NEDB '137 List getUsersWithRoles () { List users = getUsersFromDB(); List roles = getRolesFromDB(); List results = new ArrayList(); for (User u : users) { for (Role r : roles) { if (u.roleId == r.id) results.add(u); }} return results; } SELECT * FROM user SELECT * FROM role List getUsersWithRoles () { return executeQuery( “SELECT u FROM users u, roles r WHERE u.roleId == r.id ORDER BY u.roleId, r.id”; } convert to
8
Relational Operations in Imperative Code 2/1/13NEDB '138 List getUsersWithRoles () { List users = getUsersFromDB(); List roles = getRolesFromDB(); List results = new ArrayList(); for (User u : users) { for (Role r : roles) { if (u.roleId == r.id) results.add(u); }} return results; } List getUsersWithRoles () { return executeQuery( “SELECT u FROM users u, roles r WHERE u.roleId == r.id ORDER BY u.roleId, r.id”; } convert to Goal Find a variable that we can rewrite into a SQL expression output variable results
9
Query By Synthesis (QBS) Identify potential code fragments –i.e., regions of code that fetches persistent data and return values Find SQL expressions for output variables Try to prove that those expressions preserve program semantics –if so, convert the code! 2/1/13NEDB '139
10
Initial Code Fragments Identification Find program points that retrieve persistent data Run an inter-procedural analysis that: –determine where persistent data are used –delimit code fragment to analyze 2/1/13NEDB '1310
11
Search for Output Expressions 2/1/13NEDB '1311 List getUsersWithRoles () { List users = query(select * from users); List roles = query(select * from roles); List results = []; for (User u : users) { for (Role r : roles) { if (u.roleId == r.id) results = results : [] }} return results; } Infinite search space size! users roles results
12
Constraints for Output Expressions 2/1/13NEDB '1312 List getUsersWithRoles () { List users = query(select * from users); List roles = query(select * from roles); List results = []; for (User u : users) { for (Role r : roles) { if (u.roleId == r.id) results = results : [] }} return results; } users roles results If output expression outer loop invariant outer loop terminates thenoutput expression is true and is true Still need a smarter way to search results = π user ( users roleId = id roles ) results = π user ( users[0.. i] roleId = id roles )
13
Search for Output Expressions and Invariants Use program synthesis as search engine 2/1/13NEDB '1313 Symbolic desc. of search space Solution constraints Expression that satisfies all the constraints Symbolic manipulation Counter-example driven search
14
Experiments 2/1/13NEDB '1314
15
Real-world Evaluation 2/1/13NEDB '1315 Wilos (project management application) – 62k LOC Operation type# Fragments found # Fragments converted Projection11 Selection1310 Join77 Aggregation1110 Total3328
16
Performance Evaluation: Join Query 2/1/13NEDB '1316 Nested-loop join Hash join! O(n 2 ) O(n)
17
Developing Database Applications 2/1/13NEDB '1317 SQL Database Java Application Logic PL/SQL Stored Procedures SQL Query Application Server Application Distribution
18
Running Example discount = executeQuery("select discount from customers where id = " + cid); totalAmount = orderTotal * (1 – discount); credit = executeQuery("select credit from customers where id = " + cid); if (credit < totalAmount) printToConsole("Only " + credit + " in account!"); else executeUpdate("update customer set credit = " + (credit – totalAmount) + " where id = " + cid); 2/1/1318NEDB '13
19
Actual Execution discount = executeQuery("select discount from customers where id = " + cid); totalAmount = orderTotal * (1 – discount); credit = executeQuery("select credit from customers where id = " + cid); if (credit < totalAmount) printToConsole("Only " + credit + " in account!"); else executeUpdate("update customer set credit = " + (credit – totalAmount) + " where id = " + cid); 2/1/1319NEDB '13 DB APP DB
20
Actual Execution discount = executeQuery("select discount from customers where id = " + cid); totalAmount = orderTotal * (1 – discount); credit = executeQuery("select credit from customers where id = " + cid); if (credit < totalAmount) printToConsole("Only " + credit + " in account!"); else executeUpdate("update customer set credit = " + (credit – totalAmount) + " where id = " + cid); 2/1/1320NEDB '13 network communication DB APP DB
21
Speeding up Execution discount = executeQuery("select discount from customers where id = " + cid); totalAmount = orderTotal * (1 – discount); credit = executeQuery("select credit from customers where id = " + cid); if (credit < totalAmount) printToConsole("Only " + credit + " in account!"); else executeUpdate("update customer set credit = " + (credit – totalAmount) + " where id = " + cid); 2/1/1321NEDB '13 DB APP DB
22
Speeding up Execution discount = executeQuery("select discount from customers where id = " + cid); totalAmount = orderTotal * (1 – discount); credit = executeQuery("select credit from customers where id = " + cid); if (credit < totalAmount) printToConsole("Only " + credit + " in account!"); else executeUpdate("update customer set credit = " + (credit – totalAmount) + " where id = " + cid); 2/1/1322NEDB '13 data dependency DB APP DB control dependency
23
Speeding up Execution discount = executeQuery("select discount from customers where id = " + cid); totalAmount = orderTotal * (1 – discount); credit = executeQuery("select credit from customers where id = " + cid); if (credit < totalAmount) printToConsole("Only " + credit + " in account!"); else executeUpdate("update customer set credit = " + (credit – totalAmount) + " where id = " + cid); 2/1/1323NEDB '13 DB Server DB APP DB control dependency data dependency
24
Introducing Pyxis “Store-procedurizes” DB apps and pushes computation to the DB Adaptively controls the amount of computation pushed to DB for optimal performance No programmer intervention required 2/1/1324NEDB '13
25
Using Pyxis 2/1/13NEDB '1325
26
How Pyxis Works 2/1/13NEDB '1326 Instrument Partition Monitor App Server DB Server Deploy Java SQL Java SQL Java SQL Java SQL Java SQL Java SQL Java SQL Java SQL Java control transfer
27
How Pyxis Works 2/1/13NEDB '1327 Monitor App Server DB Server Deploy Java SQL Java SQL Java control transfer Instrument Partition Java SQL Java SQL Java SQL Java SQL Java SQL Java SQL Java
28
Generating Program Partitions Deploy and profile application as-is Construct a dependence graph of program statements –captures both control and data flow Formulate linear program from profile data and dependence graph –solution gives a partitioning of the source code 2/1/13NEDB '1328
29
Executing Partitioned Programs Pyxis compiler translates partitioned code into standard Java code Pyxis runtime executes compiled Java code –runtime is just another Java program running on a standard JVM –includes monitoring component to determine partition switching 2/1/13NEDB '1329
30
Experiments 2/1/13NEDB '1330
31
Experiment Setup TPC-C Java implementation –20 terminals issuing new order transactions –DB server has 16 cores total –Compared against two implementations: JDBC: everything on app server except for JDBC stmts Manual: custom “store procedurized” implementation where everything is on the DB server 2/1/1331NEDB '13
32
TPC-C on 16-core DB machine 2/1/1332NEDB '13 Pyxis generated implementation: 3x latency reduction 1.7x thruput increase
33
StatusQuo Ease DB application development Convert imperative program statements into declarative SQL Fully automatic code partitioning using application and server characteristics db.csail.mit.edu/statusquo 2/1/13NEDB '1333
34
Backup 2/1/13NEDB '1334
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.