Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance...

32
Configuring Apache Derby for Performance and Durability Olav Sandstå Database Technology Group Sun Microsystems Trondheim, Norway

Transcript of Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance...

Page 1: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Configuring Apache Derby for Performance and Durability

Olav SandståDatabase Technology GroupSun MicrosystemsTrondheim, Norway

Page 2: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

• Background> Transactions, Failure Classes, Derby Architecture

• Configuring Derby> Durability of data> Performance

• Performance Tips• Derby Performance

> Comparing Derby, MySQL and PostgreSQL

Overview

Page 3: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Properties of Transactions

Atomicity - “all or nothing”

Consistency - “from one valid state to another valid state”

Isolation - “independent of other running transactions”

Durability - “no committed transaction will be lost”

Page 4: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Failure Classes

• Process: > Derby or the JVM crashes

• Operating System: > the operating system crashes

• Hardware: > CPU, memory or disks fail

• Site: > fire, earthquakes, etc

• “Drunken DBA”: > DBA accidentally deletes or changes data

“If anything can go wrong, it will”

Murphy's Law

Page 5: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Log and Data

Derby Architecture: Client-ServerJava Virtual Machine

JDBC

SQL

AccessStorage

Database buffer

Network ServerApplication

JDBC ApplicationJDBC

ApplicationJDBC

Page 6: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Durability and Performance

Page 7: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Durability and Performance

Durability Performance

“Want all changesto data to be

written to disk”

“Want read andwrite access to dataat memory speed”

Page 8: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Data and Log Devices

Log device:> Sequential write of

transaction log> Synchronous as part of

commit> Group commit

Data device:> Data in database buffer

regularly written to disk as part of checkpoint

> Data read from disk on demand

Java Virtual Machine

Derby

Databasebuffer

Logbuffer

Log and Data

Page 9: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance:Separate Data and Log DevicesLog on separate disk:• utilize sequential write

bandwidth on disk• Configuration:

JDBC connection url:

logDevice=<path>

Performance tip: Use separate disks for data and log device

Page 10: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Disk ActivityData and log on one disk: Data and log on separate disks:

Disk head movement for 5

seconds of database activity

Page 11: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance and Durability:Log Device Configuration

Durability:• Log to disk before

commit

Performance:• A disk write is “slow”

(3-10 ms)

Options:• Disk's write cache:

> disabled> enabled

• Disable durability:> derby.system.durability =test

Page 12: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Effect of Disk Log Configurations

WARNING: Write cache reduces probability of successfulrecovery after power failure

Page 13: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Crash Recovery

durability = test

Write cache

No write cache

durability = test

Write cache

No write cache

0

1

2

3

4

5

6

7

8

9

10

Process crash Power failure

Failed to recover

Loss of updates

Successfull recovery

Durability tip: Disable the disk's write cache on the log device

Page 14: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Durability:Preparing for Disk Failures

Log device:• mirror log on two disks

(RAID-1)• must use OS support

for mirroring

Data device:• backup

Java Virtual Machine

Derby

Databasebuffer

Logbuffer

Log Log Data

Page 15: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Backup

Offline backup:• Stop Derby database• Copy database files

Online backup:• Backup while Derby server is running• New in Derby 10.2: non-blocking online backup• Supports archiving of log files

Page 16: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Online Backup

• Backup:> SYSCS_UTIL.SYSCS_BACKUP_DATABASE('/home/ba

ckup/061012')

• Backup and archive log:> SYSCS_UTIL.SYSCS_BACKUP_AND_ENABLE_LOG_

ARCHIVE_MODE('/home/backup/061012', 1)

Derby Databasebuffer

Archive Log Active Log Data Backup

Page 17: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Restore and Roll-Forward Recovery

• Situation:> Database is corrupted> Disk with database has errors

• Restore and roll-forward recovery using:> JDBC connection url:

– 'jdbc:derby:myDB;rollForwardRecoveryFrom=/home/backup'

Help!!

Derby Databasebuffer

Archive Log Active Log Data Backup

Page 18: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Backup and Restore Strategy

• Define it> Derby configuration

– Mirrored disks for log?> Backup configuration

– Online or offline?– Archived log?

> Restore strategy

• Implement it> Ensure it runs regularly

• TEST IT!> One day you will need it!!

Page 19: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Failure Classes: Summary

Category Approach

Process crash Automatic recovery

OS crash Automatic recovery

Hardware failures Backup, mirrored log disks, archive log

Site failures Backup

“Drunken DBA” Backup

Page 20: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance Tips

Page 21: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance Tips 1:Database Buffer• Cache of frequently used

data pages in memory• Cache-miss leads to a

read from disk (or file system cache)

• Size: > default 4 MB> derby.storage. pageCacheSize

Performance tip: • increase the size of the database buffer to get

frequently accessed data in memory

Page 22: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance Tips 2:Use Prepared Statements• Compilation of SQL

statements is expensive:> Derby generates Java

byte code and loads generated classes

• Prepared statements eliminate this cost

Performance tip:• USE prepared

statements • and REUSE them

PreparedStatement Statement

0

0.25

0.5

0.75

1

1.25

1.5

1.75

2

2.25

2.5

2.75

System time

User time

CP

U u

sage

(m

s/tx

)

Page 23: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance Tips 3:Avoid Table ScansTwo ways of locating data:• Table scan: reads the entire table• Index: finds the data by reading a few blocksAvoid table scans:• Use indexes to optimize frequently used access

paths:– CREATE INDEX....

• BUT: indexes are not free – needs to be maintainedPerformance tip: • Create and use indexes

Page 24: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance Tips 4:Use the Derby Tools• Know the load on the database:

> derby.language.logStatementText=true

• Check the query plan:> derby.language.logQueryPlan=true

• Use run-time statistics:> SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)> SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS()

• Optimizer Overrides (New in 10.2)Performance tip: • Use Derby's tools to understand the query execution

Page 25: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance of Apache Derby 10.2

Page 26: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Apache Derby 10.2

Performance improvements:• Client-server:

> reduced number of round-trips between client and server> reduced CPU usage in Derby network server> improved streaming of LOBs

• SQL Optimizer:> improved optimization> support for Optimizer Overrides

30-70% increasedthroughput on simple queries

Page 27: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Comparing Performance

Load clients:1. “TPC-B like” load:

> 3 updates, 1 insert, 1 select

2. Single-record SELECT:> one record by primary key

Test platform:• 2 x 2.4 Ghz AMD Opteron• Solaris 10• Sun Java SE 6

Databases:• Derby 10.1.2.1• Derby 10.2.1.6• MySQL 5.0• PostgreSQL 8.0

Page 28: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Throughput: TPC-BMain-memory database (10 MB): Disk-based database (10 GB):

Page 29: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Throughput: Single-record SelectMain-memory database (10 MB): Disk-based database (10GB):

Page 30: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Performance Improvement Activities

General:• SQL optimizer

improvementsCPU usage:• Improve use of

synchronization to reduce lock contention

• Reduce object allocations/garbage collection

Client-Server:• Improve LOB streamingDisk IO:• Allow concurrent

read/write operations on data files

• Reduce number of disk updates during log write

Page 31: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Summary

Durability:• Write log to two disks

> write cache on disk is dangerous

• Backup regularly> include archive log

• Have a strategy for backup and recovery> TEST IT!!

Performance:• Separate data and log on

different disks• Configure database buffer

to keep most used data• Use indexes• Use the Derby tools:

> query plan> optimizer overrides> timing statistics

Page 32: Configuring Apache Derby for Performance and Durability · Apache Derby 10.2 Performance improvements: •Client-server: >reduced number of round-trips between client and server >reduced

Configuring Apache Derby for Performance and Durability

Olav Sandstå[email protected]