JavaDbJazoon07

download JavaDbJazoon07

of 35

Transcript of JavaDbJazoon07

  • 8/11/2019 JavaDbJazoon07

    1/35

    Java DB Performance

    Olav Sandst

    Sun Microsystems, Trondheim, Norway

    Submission ID: 86

  • 8/11/2019 JavaDbJazoon07

    2/35

    AGENDA

    ! "ava D# introduction

    ! $on%i&urin& "ava D# %or 'er%ormance

    ! (ro&rammin& ti's

    ! )nderstandin& "ava D# 'er%ormance

    ! O'en*source database 'er%ormance

  • 8/11/2019 JavaDbJazoon07

    3/35

    Java DB

    ! Sun+s su''orted distribution o% 'ache Derby

    - all develo'ment done in the 'ache Derby community

    ! $om'lete S./ database includin&:

    - views, tri&&ers, stored 'rocedures, %orei&n 0eys

    - multi*user transaction su''ort! Security:

    - data encry'tion, client authentication, 12NT3245O4

    ! Standard based:

    - "D#$ 7 and S./93993;3 "ava, bundled in Sun "D 6 and 1lass%ish

    ! The database%or "ava a''lications

  • 8/11/2019 JavaDbJazoon07

    4/35

    Java DB Architecture: Embedded

    Log and Data

    "

    ava5irtualMachine

    "D#$

    S./

    ccess

    Stora&eDatabase buffer

    ''lication! Include derby?arin your

    class'ath

    ! #oot the "ava D# en&ine=@

    Class.forName(org.apache.derby.jdbc.

    EmbeddedDriver);

    ! $reate a new database

    Connection conn

    Driver!anager.getConnection(jdbc"derby"dbName; #

    createtr$e);

    =@ O'tional when runnin& with "D 6

  • 8/11/2019 JavaDbJazoon07

    5/35

    Java DB Architecture: Client-erver

    Log and Data

    "ava 5irtual Machine

    "D#$

    S./ccess

    Stora&eDatabase buffer

    Networ0 ServerApplication

    "D#$

    Application"D#$

    Application"D#$

  • 8/11/2019 JavaDbJazoon07

    6/35

    AGENDA

    ! "ava D# introduction

    ! Configuring Java DB for !erformance

    ! (ro&rammin& ti's

    ! )nderstandin& "ava D# 'er%ormance

    ! O'en*source database 'er%ormance

  • 8/11/2019 JavaDbJazoon07

    7/35

    Performance "i! #:e!arate Data and Log Devices

    Log on se!arate dis$:! )tiliAe seBuential write bandwidth

    on dis0

    ! $on%i&uration:

    "D#$ connection url:

    logDevice%path&

    Performance ti!:

    ! )se se'arate dis0s %or data and lo& device

  • 8/11/2019 JavaDbJazoon07

    8/35

    Dis$ Activit%

    Disk head movementfor 5 seconds ofdatabase activity

    Data and lo&

    on same dis0

    Data and lo&on se'arate dis0s

  • 8/11/2019 JavaDbJazoon07

    9/35

    Performance "i! &:"une Database Buffer i'e

    ! $ache o% %reBuently used data'a&es in memory

    ! $ache*miss leads to read %romdis0

    ! SiAe:- de%ault 7 M#

    - derby.storage.pageCache'ie

    Performance ti!:

    ! Increase the siAe o% the database bu%%er to &et %reBuently accesseddata in memory

  • 8/11/2019 JavaDbJazoon07

    10/35

    Performance and Durabilit%:Data and Log Devices

    Log device:! SeBuential write o% transaction

    lo&

    ! Synchronous as 'art o% commit

    ! 1rou' commit

    Data device:

    ! Data re&ularly written to dis0 as'art o% chec0'oint

    ! Data read %rom dis0 on demandData

    "ava 5irtual Machine

    "ava D#

    Database

    buffer

    Log

    buffer

    Log

  • 8/11/2019 JavaDbJazoon07

    11/35

    Performance "i! (:"rade Durabilit% for Performance

    Log device configuration:! Dis0+s write cache:

    - disabled

    - enabled

    ! Disable durability: derby.system.d$rabilitytest

    - lo& %lushed to dis0 after commit

    )A*N+NG:Crite cache reduces 'robability o% success%ul recovery a%ter'ower %ailure

  • 8/11/2019 JavaDbJazoon07

    12/35

    Log Device Configuration:Effect on Durabilit%

    durabilit%

    , test

    )rite

    cache

    No rite

    cache

    durabilit%

    , test

    )rite

    cache

    No rite

    cache

    =

    ;

    7

    6

    E

    8

    9

    = Process crash Poer failure

    .ailed to recover

    Loss of u!dates

    uccessfull recover%

    Test

    Durabilit% ti!:Disable the dis0+s write cache on the lo& device

  • 8/11/2019 JavaDbJazoon07

    13/35

    Performance "i! /:0se Embedded Java DB

    (er%ormance advanta&es:

    ! saves inter*'rocess or servercommunication

    ! reduces $() usa&e

    ! reduces hardware cost

    (otential issues:

    ! scalability Fone machine@

    ! "5M con%i&uration

    "D#$Java DB

    A!!lication

  • 8/11/2019 JavaDbJazoon07

    14/35

    Glassfish and Java DB:Client-erver vs Embedded1 e2am!le

    $lient*Server 4mbedded

    =

    ;

    7

    6

    E8

    9

    =

    ==

    =

    =;

    Throu&h'ut

    $lient*Server 4mbedded

    E

    =

    =

    =

    =E

    E

    ;

    ;

    ;

    ;E

    $() )sa&e Fms@

    "ava D# 1lass%ish

    "D#$Java DB

    GlassfishGlassfish

    "D#$Glassfish

    Java DB

  • 8/11/2019 JavaDbJazoon07

    15/35

    AGENDA

    ! "ava D# introduction

    ! $on%i&urin& "ava D# %or 'er%ormance

    ! Programming ti!s

    ! )nderstandin& "ava D# 'er%ormance

    ! O'en*source database 'er%ormance

  • 8/11/2019 JavaDbJazoon07

    16/35

    Performance "i! 3:0se Pre!ared tatements

    ! $om'ilation o% S./ statements is eG'ensive:'tatement s c.create'tatement();

    hile (...) *s.e+ec$te,$ery('E-EC / 012! t 34E1E a # id);

    5

    - &enerates "ava byte code and loads &enerated classes

    ! (re'ared statements eliminate this cost:

    6repared'tatement s c.prepare'tatement('E-EC / 012! t 34E1E a 7);

    hile (...) * s.set8nt(9: id);

    s.e+ec$te,$ery();5

    - &enerated "ava byte code can be "IT com'iled

  • 8/11/2019 JavaDbJazoon07

    17/35

    0se Pre!ared tatements1 e2am!le

    "hrough!ut: CP0 usage:

    (re'aredStatement Statement

    E

    =

    =

    =

    =E

    E

    $()

    usa&eFms

    3tG@

    Performance ti!:

    ! 0E 're'ared statements * and *E0Ethem

  • 8/11/2019 JavaDbJazoon07

    18/35

    =8

    Performance "i! 4:Avoid "able cans

    Two ways o% locatin& data:! Table scan: reads the entire table

    ! IndeG: %inds the data by readin& a %ew bloc0s

    void table scans:

    ! )se indeGes to o'timiAe %reBuently used access 'aths:

    C1EE 8NDE< inde+Name 2N tableName (col$mn)

  • 8/11/2019 JavaDbJazoon07

    19/35

    =9

    Avoid "able cans1 e2am!le

    = = = = = = = M

    =

    =

    =

    =

    =

    =2etrieval time %or one record

    IndeG

    No indeG

    Table siAe Fnumber o% records@

    2es'onsetimeFms@

    Performance ti!:

    ! $reate and use indeGes

  • 8/11/2019 JavaDbJazoon07

    20/35

    Performance "i! 5:6el! the Database to Perform

    "D#$ ti's:

    ! $lose "D#$ ob?ects a%ter in use

    - $onnections, Statements, 2esultSets, Streams

    ! )se transactions * do not rely on auto*commit

    - (articularly %or insert3u'date3delete o'erations! #atch u'dates reduce networ0 tra%%ic

  • 8/11/2019 JavaDbJazoon07

    21/35

    AGENDA

    ! "ava D# introduction

    ! $on%i&urin& "ava D# %or 'er%ormance

    ! (ro&rammin& ti's

    ! 0nderstanding Java DB !erformance

    ! O'en*source database 'er%ormance

  • 8/11/2019 JavaDbJazoon07

    22/35

    Performance "i! 7:8no the Load and the *esource 0sage

    ! now the load on the database:derby.lang$age.log'tatemente+ttr$e

    - all eGecuted Bueries written to derbylo&

    ! now how the Bueries are eGecuted:

    derby.lang$age.log,$ery6lantr$e

    ! .uery*'lan and run*time statistics:

    '='C'>?8-.'='C'>'E>1?N8!E'8'8C'(9)'='C'>?8-.'='C'>'E>'8'8C'>8!8N@(9)'='C'>?8-.'='C'>@E>1?N8!E'8'8C'()

    ! )se OS and "ava tools to %ind resource usa&e:

    - $(), memory, dis0 IO %or lo& and data device

    Performance ti!:

    ! )se the available tools to understand what the database is doin& andwhere resources are s'ent

  • 8/11/2019 JavaDbJazoon07

    23/35

    E2am!le:9uer% Plan and *un-time tatistics

    AA enable r$nBtime statistics'tatement s c.create'tatement();s.e+ec$te?pdate(C-- '='C'>?8-.'='C'>'E>1?N8!E'8'8C'(9));s.e+ec$te?pdate(C-- '='C'>?8-.'='C'>'E>'8'8C'>8!8N@(9));

    AA e+ec$te $ery1es$lt'et rs s.e+ec$te,$ery('E-EC 9.c from 9:

    here 9.c .c and 9.c % FGG);hile (rs.ne+t()) *5rs.close();

    AA retrieve $ery plan and r$nBtime statisticsrs s.e+ec$te,$ery(H-?E'

    '='C'>?8-.'='C'>@E>1?N8!E'8'8C'());rs.ne+t();'tring str rs.get'tring(9);'ystem.o$t.println(,$ery 6lan" # str);

    T= T

    "oin

    (ro?

  • 8/11/2019 JavaDbJazoon07

    24/35

    7

    Performance "i! :;!timi'er ;verrides

    ! Override eGecution strate&y selected by o'timiAer! Horce use o% s'eci%ic indeG:

    'E-EC / 012! t9 BBDE1I=B6126E18E' inde+t9>c9

    34E1E c99

    ! Horce use o% constraint:

    'E-EC / 012! t9 BBDE1I=B6126E18E' constraintc

    34E1E c99 and cJ

    ! Horce s'eci%ic "OIN order and "OIN strate&y:

    'E-EC / 012! KBDE1I=B6126E18E' join2rder08

  • 8/11/2019 JavaDbJazoon07

    25/35

    ;!timi'er ;verrides E2am!le

    'E-EC t9.c 012! KBDE1I=B6126E18E' join2rder08

  • 8/11/2019 JavaDbJazoon07

    26/35

    Performance "i! #>:0nderstand Loc$ing +ssues

    ! /oc0 based concurrency control! Isolation level:

    - 2educin& isolation level increases concurrency

    ! /oc0 escalation:

    - De%ault: escalation %rom ro loc$sto table loc$swhen loc0sare set on the table

    - derby.locLs.escalationhreshold9GG

    - -2CM I-E t9 8N *'41EE

  • 8/11/2019 JavaDbJazoon07

    27/35

    0nderstand Loc$ing +ssues

    2etrieve loc0 in%ormation:

    'E-EC / 012! '='C'>[email protected]>I-E

  • 8/11/2019 JavaDbJazoon07

    28/35

    AGENDA

    ! "ava D# introduction

    ! $on%i&urin& "ava D# %or 'er%ormance

    ! (ro&rammin& ti's

    ! )nderstandin& "ava D# 'er%ormance

    ! ;!en-source database !erformance

  • 8/11/2019 JavaDbJazoon07

    29/35

    9

    Java DB #>?(: Performance +m!rovements

    4mbedded:! reduced synchroniAation K conteGt switches

    ! reduced $() usa&e

    ! reduced number o% dis0 u'dates to lo& device

    ! concurrent read3writes on data device

    $lient*server:

    ! im'roved streamin& o% /O#s

    S./ O'timiAer:

    ! im'roved o'timiAation ;*> increased

    throu&h'ut onsim'le Bueries

  • 8/11/2019 JavaDbJazoon07

    30/35

    Performance +m!rovement1 e2am!le

    )'&radin& to Sun "D 6 and "ava D# =;= beta:

    /oad: Select one record in a table

    4mbedded: $lient*server:

  • 8/11/2019 JavaDbJazoon07

    31/35

    ;=

    ;!en-ource Database Performance

    Databases:! "ava D# =;= beta

    - embedded

    - client*server

    ! (ost&reS./ 8=8

    ! MyS./ ;;

    - with InnoD#

    Load clients:#? elect load:

    = sin&le*record select

    &? 0!date load:

    ; u'dates, = insert, = select

    "est Configuration:

    ! LOut*o%*the*boG

    ! M# database bu%%er

    ! Data and lo& on se'arate dis0s! SunHire vA F MD O'teron@

    ! Solaris =, Sun "ava S4 6

  • 8/11/2019 JavaDbJazoon07

    32/35

    ;

    "hrough!ut: ingle-record elect

    Main*memory database F= M#@: Dis0*based database F= 1#@:

  • 8/11/2019 JavaDbJazoon07

    33/35

    ;;

    "hrough!ut: 0!date Load

    Main*memory database F= M#@: Dis0*based database F= 1#@:

  • 8/11/2019 JavaDbJazoon07

    34/35

    ummar%

    ! Trade*o%%s between durability and 'er%ormance

    - 0now your reBuirements and select care%ully

    ! now what in%luence 'er%ormance

    - "ava D# con%i&uration

    - user a''lication! Ti's and tools to %ind and solve 'er%ormance bottlenec0s

    "ava D# (er%orms

    - $om'arable to other o'en*source databases

  • 8/11/2019 JavaDbJazoon07

    35/35

    ;lav andst@ htt!:develo!ers?sun?comavadbun icros%stems olavsun?com