High performance database applications with pure query and ibm data studio.bacvanski
1. Developing High Performance
Database Applications with
pureQuery and IBM Data
Studio
Dr. Vladimir Bacvanski, SciSpike
vladimir.bacvanski@scispike.com
0 1801
2. Show of Hands: What Data Access
Technology Have You Used?
Hibernate
EJB Entity
Beans
JDBC
iBatis/MyBatis
JPA
SQLJ
EJB: Enterprise Java Beans
• What’s most important to you? JPA: Java Persistence API
o Productivity
o Performance
o Security
o Portability
1
1801
3. Java Data Access – Two Views of the World
Writing Java code is so JSP
easy with this eclipse Spring QoS goals Runstats Another runaway
environment. XML http query! Where are
I wish it was that easy to Partition Stored these coming from?
mashup strategy Procedures JDBC? Hmmm…
get the SQL right. SQL
JSON Response REORG
JDBC Time!
This ORM doesn’t
allow me to leverage
all my database’s Inconsistent response
SQL. time? How long will it
take me to find the
JDBC offending application
sending bad SQL this
time?
I can’t believe I got called
out last week.
I wish I could see how
these queries will run in SQLJ
production. JPA
These ad-hoc queries
are dangerous. We
Application Database Developer need a library of tested
Why does this query Spring Developer & Administrator SQL interfaces.
take so long?
MyBatis, . . .
Static SQL? Sounds like Sometimes I need Another GRANT Can I examine the
another delay to getting POJOs, sometime JSON, request? This security SQL “before” the
my program deployed sometimes XML, what administration is out of application is
should I use? control. deployed?
1801
4. Data Mapping Approaches
• Application-Centric
o Top-Down
Top
o Object Domain Model Down
o Object Relational Mapping
o Well supported in dynamic
languages and frameworks
• Hybrid
Meet in the
o Meet in the middle Persistence Layer
Middle
o Can be challenging w/o comprising
• Data-Centric
o Bottom-UP
o Start with Relational Data Model
Bottom
o Not well supported in dynamic Up
languages and frameworks
3
1801
5. JPA, Hibernate, EJB vs. The Database
! DBA and SQL developer chasm
Where is the SQL coming from?
What is it?
Where is it?
How do we tune it?
How de we manage it?
! Performance Concerns:
Some vendors claim (unsurprisingly) that
Managed objects performs fine.
There are many user claims of bad
Managed object performance is bad on
the web.
! As always, the truth is in the middle.
And will depend on your app server,
application, database, etc ..
4
1801
6. Introducing pureQuery
A high-performance, data access platform to simplify
developing, managing, securing, and optimizing data
access.
pureQuery Components:
• Simple and intuitive API
o Enables SQL access to databases or in-memory Java objects
o Facilitates best practices
• IBM Data Studio (integrates with Rational Application Developer /
Rational Software Architect)
o Integrated development environment with Java and SQL support
o Improve problem isolation and impact analysis
• Optim pureQuery Runtime
o Flexible static SQL deployment for DB2
1801
7. pureQuery Balances Productivity and Control
Full SQL control Object-relational mapping Managed objects
Code all your SQL
JDBC / SQLJ
Use SQL templates, inline only
Spring
templates
MyBATIS
Add basic OR mapping and annotated-method style
pureQuery
Complex OR mapping and persistence management, but loss of controls
Hibernate
Adds container management option
OpenJPA
1801
8. Design Phase pureQuery close-up
Jump Start Application Design
• Generate SQL and Code from Database Objects
• Setup basic DAO Pattern
Existing JDBC to Static
• Reroute Dynamic Queries to Static Code Development Productivity
• Code Generation, Content Assist
• Database aware, Java SQL Editor
SQL Replacement
• Replace Query w/o changing source
SQL Performance
Metrics
• Find and sort query elapsed time
Oracle Support from Java
• Replace Query w/o changing
source
Java to SQL Integration
• Categorize by Java, SQL, Database ,
Packages, track back to line of code
Problem Determination
• Monitor WebSphere Connection
Pool, JDBC Driver, Network Static SQL
• Track back to SQL and line of • Lock in Access plans, Improve Security,
code in the application Consistent Performance
SQL Injection Prevention
• Lock down SQL for Dynamic
1801
10. Code Example: pureQuery
Employee%myEmp%=%db.queryFirst(%
%%%%%"SELECT%NAME,%ADDRESS,%PHONE_NUM%FROM%EMP%
%%%%%%WHERE%NAME=?",%Employee.class,%name);%
%
Even simpler, if we have a method getEmployee with a Java
annotation or XML file with SQL for the query:
Employee%myEmp%=%getEmployee(name);%
9
1801
11. IBM Optim pureQuery
Developer
• Reduce costs
o Increase system throughput
Design
o Improve developer productivity
Develop
o Move workload to zIIP and zAAP Code
Debug
• Improve quality of service Optimize Develop
Test
for new and existing Java applications Tune, Package
Models
o Improve performance Policies
Metadata
o Lock in access plans
o Speed up problem resolution
Operate Deploy Tester
• Reduce development time for new Java
applications
o Bridge Java and data
o Balance productivity and control
o Enhance developer and DBA collaboration
• Enhance security
o Limit user access
o Minimize SQL injection risk
o Improve audit readiness
1801
12. Why should DBAs care ?
• DBAs have little to no visibility of application SQL before deployment,
no opportunity for review and optimization
• Problem isolation takes days with contemporary environments such
as Java, PHP, .NET, etc. due to inability to trace SQL to Java
application and source code
• Constantly increasing Java application workload taxes existing
systems – need to fit more work into existing systems
• SQL injection represents an increasing risk to data security
1801
13. Why should Developers care ?
• Get data access right the first time!
• Get it done faster - Improved productivity
• Single environment that spans Java application and database
development
• Improved problem isolation and resolution
1801
14. How well does it work? – Java applications
• In-house testing shows significant performance improvements
Normalized Throughput by API for JDBC Type 4 Driver % increase/reduction in CPU per transaction compared
to JDBC using Type 4 driver
500
% increase/reduction in CPU per
400
25%
Normalized Throughput (ITR)
transn compared to JDBC
15%
300
524 6%
485
446
420
200 360
274
-14%
100
-35%
0 -50%
B2
ic
ic
ic
2
C
A
A
ic
ic
ic
t
B
JP
ta t
B
am
JP
Sta
ta t
am
at
EJ
JD
EJ
dS
St
yn
dS
yn
t.
iz n
dD
Op
tho
dD
tho
im
tho
Me
t
tho
Me
en
t
Op
Me
Me
Cli
pQ
pQ
t
ien
pQ
pQ
Cl
• IRWW – an OLTP workload, Type 4 driver
• Cache hit ratio between 70 and 85%
• 23 % improvement in throughput using pureQuery over dynamic JDBC
• 15% - 25% reduction on CPU per transaction over dynamic JDBC
13
1801
15. How well does it work? - .Net applications
! IRWW – OLTP application
! Application accesses DB2 for z/OS
• Throughput during static execution increased by 159% over dynamic SQL
execution assuming a 79% statement cache hit ratio
*Any performance data contained in this document were determined in various controlled laboratory environments and are for reference purposes only. Customers should not adapt these
performance numbers to their own environments as system performance standards. The results that may be obtained in other operating environments may vary significantly. Users of this
document should verify the applicable data for their specific environment.
14
1801
16. Optim pureQuery Runtime
• Control performance
o Decide at deployment time how the SQL is executed
o Understand and lock down the access plan for SQL
o Replace suboptimal SQL without changing the application
• Control security
o Prevent SQL injection
o Prevent execution of unauthorized SQL
o Better manage database security
• See inside applications that are driving your database
o Understand where SQL comes from
o Understand when frameworks and ORM’s are getting in the way
• Simplify problem determination and troubleshooting
o Correlate problem SQL with applications, ORM’s and frameworks
15
1801
17. How do I start with pureQuery?
• Existing applications
o Optimize existing JDBC (and .NET) applications
o No code changes needed
o Have to go through the client optimization process to get to static
SQL
• New applications
o Use the pureQuery API
o Development codes using one API regardless of whether it is
deployed dynamically or statically
o DBA deploys statically
o No need to go through client optimization process
• Other
o JPA, MyBatis, Hibernate
16
1801
18. pureQuery Facilitates Best Practices
• Supports both inline SQL and Java annotations (method)
• Intuitive interfaces for common data retrieval and manipulation
scenarios hides JDBC complexity
o Query First
o Homogeneous Batch
• Reduce network trips to the database
o Query Over Java Collections
o Heterogeneous Batch
• Use custom result handlers to map results to POJO’s, XML, JSON, …
17
1801
19. Data Studio SQL Capture
! Capture
– Determine SQL coming from application Capture
! Review
– Review SQL to identify issues
– Optimize Review Optimize Restrict
• Replace SQL with enhanced to SQL
– Restrict
• SQL approved list
! Configure
– Flag SQL to be in a package and configure
driver properties Configure Bind
– Bind
• Create packages according to configure
! Execute
– Switch to run with new configuration
Execute
18
1801
20. A Typical Application Architecture with
pureQuery
Implements the U/I or Presentation Layer
network protocols using
the business services
Business Service Layer
Never use the pureQuery
API directly. Gets data
from the Data Access
Layer Data Access Layer
pureQuery pureQuery makes this
Using the pure-query
layer easy, fast,
API to access the
consistent and traceable
database.
Provides a technology Database
neutral API to the data
used by the business
services
19
1801
21. RAD or RSA / IBM Data Studio
Data Centric Development Scenario
Write in Java Write in Java with pureQuery
Using RAD/RSA/Eclipse Using Data Studio in RAD
Presentation Application Objects Tables
• JSF2, Ajax … • Business Logic • Access to data • Data
Access generated
Java data objects
from code developed
in RAD
1801
23. How to get pureQuery?
• Bundled Offerings
o Part of DB2 LUW Advanced Enterprise Server Edition 10.1 and higher
• Can be deployed on any number of applications connecting to that DB2
server
o In DB2 Connect Application Server Advanced Edition
o Comes with DB2 Connect Unlimited Advanced Edition for System z
• Stand-alone Offerings
o InfoSphere Optim pureQuery Runtime for LUW
o InfoSphere Optim pureQuery Runtime for z/OS
1801
24. Conclusion: pureQuery Advantages
• Excellent performance
o Static and dynamic SQL is captured during test and optimized
before deployment
o Enables lock-in of access path
• Great productivity
o Excellent tool support through IBM Data Studio
• Shell share with Rational tools
o Mapping from SQL to Java captured and traceable
o Facilitates collaboration between DBA’s and developers
• Performance tuning, impact analysis
• Better security
o Limits SQL injection
o Controlled database access
23
1801
26. Getting in Touch
• Dr. Vladimir Bacvanski
o Email: vladimir.bacvanski@scispike.com
o Blog: http://www.OnBuildingSoftware.com/
o Twitter: http://twitter.com/OnSoftware
o LinkedIn: http://www.linkedin.com/in/VladimirBacvanski
1801