sun java db, - campus kalvskinnet – ntnu€¦ · sun java db, a small, easy to ... openbsd,...

46
Sun Java DB, a small, easy to use, pure Java RDBMS Bernt Marius Johnsen Database Technology Group Sun Microsystems [email protected]

Upload: dangduong

Post on 11-Jul-2018

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Sun Java DB,a small, easy to use, pure Java RDBMS

Bernt Marius JohnsenDatabase Technology Group Sun [email protected]

Page 2: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 2

Database Technology Group• Database Technology Group

> Responsible for database technology within Sun> Trondheim, California, Bangalore

• Databases> HADB (aka. Clustra)> Java DB (aka. Derby)> Testing & evaluation of other databases (e.g. 

PostgreSQL)> Evaluation of databases for internal Sun use> New DB technologies

Page 3: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 3

Java DB Overview

Ready for the challenge?

Page 4: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 4

What is Java DB?• Sun's supported distribution of Apache Derby• Open Source Database Technology

> Pure Java> Easy to use> Small footprint> Standards based> Complete relational database engine> Secure

Page 5: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 5

Three organizations. Three brands. One product

Page 6: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 6

A short Java DB History• 1996: Cloudscape founded• 1997: JBMS Released• 1999: Cloudscape acquired by Informix• 2001: IBM acquired DB part of Informix• 2004: IBM donated Cloudscape to Apache as Derby• July 2005: Derby graduated from Apache Incubator• December 2005: Sun announces Java DB• Current stable release: 10.1.3.1

Page 7: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 7

Complete Relational Engine• Tables• Indexes• Views• Triggers• Joins• Procedures (Java)• Functions (Java)

• Temporary tables• Foreign keys• Constraints• Cursors• Transactions• Isolation levels• ACID

Page 8: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 8

Complete Relational Engine contd.

• Multi­user• Deadlock detection• Crash recovery• Backup & restore• Cost based optimizer• Data caching• Statement caching• Write ahead logging• Group commit

Page 9: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 9

Complete Relational Engine contd.

• Multiple databases per system• Multiple systems per read­only database• Embedded

> application in same VM as engine

• Client/Server > application in another VM than the engine> somewhere else in the network

Page 10: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 10

Pure Java• Database code written in Java• Write Once Run Anywhere

> Requires a J2SE 1.3, J2SE 1.4, J2SE 5.0 or Java SE 6 virtual machine

> Any hardware, any operating system, any vendor

• Single binary does run everywhere> Solaris, Solaris x86, Linux, FreeBSD, NetBSD, 

OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, OS/390, …

• Database on­disk format is platform independent

Page 11: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 11

Small Footprint• Engine jar file is around 2MB

> 600kB when compressed with Pack200> Optional jar files

> Network server ~150kB> Tools ~200kB

• Runtime memory use> Dependent on application, data caching etc.> Can run when Java heap memory restricted to 4MB> Runs on machines with only 16MB physical memory

Page 12: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 12

Java DB Security• On­disk database encryption• Builtin, LDAP or pluggable authentication• Simple authorization via configuration• Java Security Manager enabled

Note: SQL users and GRANT/REVOKE will be available in 10.2

Page 13: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 13

Standards Based• SQL

> SQL92, SQL99, SQL2003, SQL/XML, …

• Java> J2SE 1.3, 1.4, 5.0, Java SE 6> J2ME/OSGi

• JDBC> 2.0, 3.0, 4.0 > J2EE – Passed CTS for J2EE 1.4 & 1.3> JSR 169 (JDBC for CDC)

• DRDA V3> OpenGroup (http://www.opengroup.org/)

Page 14: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 14

Java DB Tools• ij – SQL scripting tool

> JDBC neutral, can be used against other JDBC drivers

• dblook – schema extraction tool for Derby• sysinfo – Derby version information

> Output useful for bug reporting in Jira

Page 15: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 15

Architecture: Fundamentally solid• Straight, solid state­of­the art technology• Well proven techniques (text­book)

> Aries> Indices are B­trees

• Modular architecture

Page 16: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 16

No separate SQL virtual machine• SQL compiled into Java byte­code• Run on standard Java VM

> Pro: Fast. Utilizes HotSpot> Con: Compilation + class­loading

SQL BytecodeMachine

instructions

HotSpot compilerQuery Parser & Compiler

Page 17: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 17

Pluggable Storage Architecture

EmbeddedDriver / NetworkServer

Optional configurable encryption layer using JCE

FileSystem

Zip/Jar JDBC? ...Memory

Database Engine

Page 18: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 18

Java DB performs!• Java DB performs well

> Comparable to competition 

• Java is not slow!> Just In Time (JIT) compilers compile interpreted byte 

code to native machine code

• We have studied and compared the performance of > Java DB> MySQL> PostgreSQL

Page 19: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 19

TPC/B­like load, In­memory DBDB 10MB, buffer 50MB, 400 branches

 0

 200

 400

 600

 800

 1000

 1200

 1400

 1600

 0  20  40  60  80  100

Tran

sacti

ons p

er se

cond

Number of clients

Derby embeddedDerby client/server

MySQL (InnoDB)PostgreSQL

Page 20: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 20

TPC/B­like load, Disk­bound DBDB 10GB, buffer 64MB, 400 branches

 0

 10

 20

 30

 40

 50

 60

 70

 0  20  40  60  80  100

TPS

Number of clients

Derby embeddedDerby client/server

MySQL (InnoDB)PostgreSQL

Page 21: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 21

Performance hints• Use (and reuse) prepare statements

> Not: “SELECT a FROM t WHERE b=4” + val> But: “SELECT a FROM t WHERE b=?”

• Put DB log and data on separate disks> Specify the logDevice attribute when creating DB

• Tune page cache size (default 4 MB)> derby.storage.pageCacheSize

• Use indices to avoid table scans> Check query plans 

(derby.language.logQueryPlan=true)

Page 22: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 22

Java DB Usage 

A powerful tool

Page 23: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 23

Embedded Java DB

Java Virtual Machine

Java DB

Applicationor App/Web Server

• Easy to use• Fast• Zero administration

Embedded JDBC Driver

Page 24: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 24

Embedded: Zero Administration

java -classpath derby.jar ...

Class.forName (“org.apache.derby.jdbc.EmbeddedDriver”);

DriverManager.getConnection (“jdbc:derby:foobar;create=true”);

Page 25: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 25

Read only DB­in­a­jar (or zip)

Java DB

Generate DBapplication

Embedded JDBC Driver

Java DB

Use DBapplication

Embedded JDBC Driver

jar cvf db.jar foobar

Page 26: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 26

Use of DB­in­a­jar

java -classpath derby.jar ...

DriverManager.getConnection (“jdbc:derby:(db.jar)foobar”);

java -classpath derby.jar:db.jar ...

DriverManager.getConnection (“jdbc:derby:classpath:foobar”);

... or ...

Page 27: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 27

Java DB

Use DBapplication

Embedded JDBC Driver

All­in­one­jar

Page 28: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 28

Use of All­in­a­jar

java -classpath all-in-one.jar ...

DriverManager.getConnection (“jdbc:derby:classpath:foobar”);

jar xf derby.jar

jar cf all-in-one.jar org myapp foobar

Page 29: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 29

DB­on­a­stick

Java DB

Application

Embedded JDBC Driver

Page 30: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 30

DB in a Browser

Browser

Ajax

Applet

• Small enough to fit in a browser

• Fast enough for interactive use

• See demo at http://developers.sun.com/prodtech/javadb/

Java DB

Embedded JDBC Driver

Page 31: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 31

• Nearly zero administration

• Standard protocol (DRDA)

• Many apps use one DB

Client/ServerApp

Java DB

DRDA

App App

NetworkDriver

NetworkDriver

NetworkDriver

Network Server

Page 32: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 32

C/S: Nearly Zero Administrationjava -jar derbynet.jar start -p 12345 -h ahost

Class.forName (“org.apache.derby.jdbc.ClientDriver”);

DriverManager.getConnection (“jdbc:derby://ahost:12345/foobar”);

java -classpath derbyclient.jar ...

Page 33: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 33

Combined Embedded/Server

Java DB

Application

Embedded Driver

AppNetw.Driver

DRDA

Netw

. Ser

ver

• Nearly Zero Administration

• No application change

Page 34: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 34

Combined Embedded/Server: Serverjava -Dderby.drda.startNetworkServer=true -Dderby.drda.host=ahost -Dderby.drda.port=12345-classpath derbynet.jar ...

Class.forName (“org.apache.derby.jdbc.EmbeddedDriver”);

DriverManager.getConnection (“jdbc:derby:foobar;create=true”);

Page 35: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 35

Combined Embedded/Server: Server #2java -classpath derbynet.jar ...

Class.forName (“org.apache.derby.jdbc.EmbeddedDriver”);

DriverManager.getConnection (“jdbc:derby:foobar;create=true”);

.......

NetworkServerControl server = new NetworkServerControl (InetAddress.getByName(“ahost”), 12345);

server.start(null);

.......

server.shutdown();

.......

Page 36: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 36

Combined Embedded/Server: Client

Class.forName (“org.apache.derby.jdbc.ClientDriver”);

DriverManager.getConnection (“jdbc:derby://ahost:12345/foobar”);

java -classpath derbyclient.jar ...

Page 37: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 37

Java DB Scaling• In principle unlimited: No architectural constraints• We have tested

> Databases up to 300GB> Up to 100 active connections

Page 38: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 38

Java DB Horizontal Scaling and HA• No built­in support• May be achieved somewhat with Sequoia (C­JDBC)

> Not like “the real thing” (e.g HADB and other “hardcore” HA solutions)

> Low performance> Limited JDBC/SQL support> Immature

• “Building Highly Available Database Applications for Apache Derby”, ApacheCon 2005. > http://c­jdbc.objectweb.org

Page 39: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 39

In­memory DB• What do you mean? 

> Java DB caches data in memory.

• Durability comes at a cost> Persist to disk as you go: Performance penalty> Persist at shutdown: Risky

• Possible to run Java DB with less durability: > -Dderby.system.durability=test

• SQL RDBMS> B­trees designed for efficient disk storage & retrieval> ACID (Atomicity, Consistency, Integrity, Durability)

Page 40: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 40

• Scrollable updatable result sets• Grant/Revoke• Online backup• Stronger Network Authentication• XML support for XPath• ... plus... unary +/­ in parameters, FOR UPDATE, Client timeout, 

Optimizer directives, trigonometric functions, internationalizing, invoke procedures from triggers, GROUP BY supports expressions, identity value restart, etc...

The Future: Java DB 10.2

Page 41: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 41

The Future: JDK 6 and JDBC4• We are bundling Java DB in JDK 6• We will support JDBC4 and have implemented

> Ease­of­development> Wrapper patterns> SQLException subclasses> Statement events> Lengthless streaming

Page 42: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 42

Issues we are working with• Performance

> Already 40% improvement single row select client/server

• Standards compliance• Standards completeness• In­memory store• SSL/TLS• JMX

Page 43: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 43

Java DB Usage

See extensive list at http://wiki.apache.org/db­derby/UsesOfDerby 

• Support in tools> e.g. Netbeans, Eclipse, Java Studio Creator

• Persistence> e.g. Apache JDO, Apache OJB, Hibernate, JPOX JDO

• Supported by Application Servers> e.g. Sun's J2EE SDK, JBOSS, Geronimo, Tomcat

• Supported by frameworks> e.g. Apache  Cocoon

Page 44: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 44

Community• http://db.apache.org/derby

> Download, read docs

• JIRA http://issues.apache.org/jira/browse/DERBY

> Report bugs, submit patches

• derby­[email protected]> Discuss experience, get help

• derby­[email protected]> Discuss developer issues

Page 45: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Q&A

Bernt Marius [email protected]@apache.org

Page 46: Sun Java DB, - Campus Kalvskinnet – NTNU€¦ · Sun Java DB, a small, easy to ... OpenBSD, MacOs, Windows, AIX, Z/OS, AS400, ... > Can run when Java heap memory restricted to 4MB

Java DB – JavaZone 2006 – Slide 46

What about the much faster and pure Java xxxxx in­memory DB

A C I D !