Java Developer GraalVM&ReactiveProgramming v1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Safe Harbor

The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development,
release, timing, and pricing of any features or functionality described for Oracle’s products may change
and remains at the sole discretion of Oracle Corporation.

Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and
prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed
discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and
Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q
under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019
and Oracle undertakes no duty to update any statement in light of new information or future events.

Copyright © 2019 Oracle and/or its affiliates.


The love-hate relationship bw and the

Copyright © 2019 Oracle and/or its affiliates.


Intro

Java riding at the top of all prog lang. for the last 20 years
There are 12+ Millions Java Developers – What do they want?
How to make the Oracle database relevant for that community?

Copyright © 2019 Oracle and/or its affiliates.


Copyright © 2019 Oracle and/or its affiliates.

Polyglot Programming: GraalVM


database
standalone
GraalVM Architecture

Clojure

Truffle Languages

JVM Languages Language Implementation API (Truffle)

GraalVM Compiler

HotSpot VM
GraalVM Native Images

• Instant startup;
• Low memory footprint;
• Works with memory management;
• AOT-compiled using the GraalVM compiler.
Microservice Frameworks: Startup Time

35 ms
Helidon 1030 ms
988 ms

37 ms
Micronaut 2087 ms
2101 ms

16 ms
Quarkus 952 ms
940 ms

0 ms 500 ms 1000 ms 1500 ms 2000 ms 2500 ms


Native Image JDK 12 JDK 8
Microservice Frameworks: Memory Usage

31 MB
Helidon 116 MB
106 MB

41 MB
Micronaut 172 MB
180 MB

17 MB
Quarkus 125 MB
121 MB

0 MB 20 MB 40 MB 60 MB 80 MB 100 MB 120 MB 140 MB 160 MB 180 MB 200 MB


Maximum Memory Size

Native Image JDK 12 JDK 8


Twitter uses GraalVM compiler in
production to run their Scala
microservices
• Peak performance: +10%
• Garbage collection
time: -25%
• Seamless migration
The rich ecosystem of CUDA-X libraries is now available for
GraalVM applications.

GPU kernels can be directly launched from GraalVM languages


such as R, JavaScript, Scala and other JVM-based languages.
Oracle Database Access with JDBC (Oracle internal)

Native image error with JDBC code


• GraalVM supports the OpenJDK java.lang.reflect package, which is different
from sun.reflect.Reflection
• We are following up with OpenJDK

Thread startup and class initialization during the native image generation
• Must set a flag to allow image building with an incomplete classpath
$ native-image --initialize-at-build-time \ ❶
--allow-incomplete-classpath \ ❷
--no-fallback \
-cp ".:ojdbc8.jar" \
TestConnection

• Looking into starting threads lazily, at a cost

Native Image is still available as an Early Adopter Technology

Copyright © 2019 Oracle and/or its affiliates.


Copyright © 2019 Oracle and/or its affiliates.

Reactive Programming – Reactive Streams


Reactive Programming and Reactive Streams
https://www.reactivemanifesto.org/
• Reactive programming: a programming model that facilitates scalability and stability by
creating event-driven non-blocking functional pipelines that react to availability and
processability of resources.

• Reactive Streams: Asynchronous DB Access with Back Pressure

I can take <n> messages


request(n)/cancel()

Subscriber Publisher
(User Java code) Send <n> messages (Driver)
data

onSubscribe()
subscribe() onNext()
onError()
onComplete()
Confidential – Oracle Internal/Restricted/Highly Restricted
JDBC Reactive Extensions

• The Oracle Database 20c JDBC drivers include extensions to support


Asynchronous and Reactive database access

• Based on java.util.concurrent.Flow

• The implementation uses NIO Selector so no threads block waiting on the


database

• Minimal API. Not every use case supported

• No expectation that this will become a Java standard

Copyright © 2019 Oracle and/or its affiliates.


JDBC Reactive Extensions
Connection Creation (OracleConnectionBuilder):
Publisher<OracleConnection> buildConnectionPublisherOracle()
Connection Closing (OracleConnection):
SQL Execution (OraclePreparedStatement):
Publisher<Success> closeAsyncOracle()
Publisher<Boolean> executeAsyncOracle()
Publisher<Long> executeUpdateAsyncOracle()
Publisher<Long> executeBatchAsyncOracle() Transaction Closing (OracleConnection):
Publisher<OracleResultSet> executeQueryAsyncOracle() Publisher<Success> commitAsyncOracle()
Publisher<Success> rollbackAsyncOracle()
Row Fetching (OracleResultSet):
Publisher<T> publisherOracle(Function<OracleRow, T> f)
Notes
LOB I/O (OracleBlob):
Publisher<byte[]> publisherOracle(long position)
Subscriber<byte[]> subscriberOracle(long position) • Support for reading and writing BFILE, BLOB, and
CLOB
LOB I/O (OracleClob): • Only one async operation at a time. Subsequent calls
Publisher<String> publisherOracle(long position)
Subscriber<String> subscriberOracle(long position) to the Connection or its dependents block except for
cancel, isClosed, etc
• Compatible with reactive stream libraries that
support Flow

Copyright © 2019 Oracle and/or its affiliates.


Using JDBC Reactive Extension with Reactor

Reactor
Application
A Reactor DAO
map() executes the SQL statements
filter() and returns a Flux data stream
reduce() Reactor
parallel() DAO class
… streamAllEmployees()
queryAllEmployees()

Reactive JDBC
Adapter class
Conversion bw Flow types and
org.reactivestreams types

JDBC Reactive
Extensions

Confidential – Oracle Internal/Restricted/Highly Restricted


public final class ReactorDemo {

private ReactorDemo() {}

private Mono<Integer> getSumOfAllSalaries() {


return ReactorEmployeeDAO.getInstance()
.streamAllEmployees()
.map(Employee::getSalary)
.filter(Optional::isPresent)
.map(Optional::get)
.reduce(0, (sum, salary) -> sum + salary);
}

public static void main(String[] args) {


ReactorDemo demo = new ReactorDemo();

demo.getSumOfAllSalaries()
.doOnSuccess(System.out::println)
.block();
}
}
Copyright © 2019 Oracle and/or its affiliates.
Using JDBC Reactive Extension with RxJava

RxJava
Application
An RxJava DAO
map() executes the SQL statements
filter() and returns a Flowable data stream
reduce() RxJava
blockingGet() DAO class
… streamAllEmployees()
queryAllEmployees()

Reactive JDBC
Adapter class
Conversion bw Flow types and
org.reactivestreams types

JDBC Reactive
Extensions

Confidential – Oracle Internal/Restricted/Highly Restricted


public class RxJavaDemo {
private Single<Integer> getSumOfAllSalaries() {
return RxJavaEmployeeDAO.getInstance()
.streamAllEmployees()
.map(Employee::getSalary)
.filter(Optional::isPresent)
.map(Optional::get)
.reduce(0, (sum, salary) -> sum + salary);
}

public static void main(String[] args) {


RxJavaDemo demo = new RxJavaDemo();

demo.getSumOfAllSalaries()
.doOnSuccess(System.out::println)
.blockingGet();
}
}

Copyright © 2019 Oracle and/or its affiliates.


Using JDBC Reactive Extension with Akka Streams

Akka Stream
Application
An Akka DAO
Filter() executes the SQL statements
Map() and returns a Sourcedata
runFold() stream
Reactor
toCompletableFuture() DAO class
join()
… streamAllEmployees()
queryAllEmployees()
mapMaterializedValue()
fromPublisher() Reactive JDBC
alsoTo() Adapter class
Conversion bw Flow types and
… org.reactivestreams types

JDBC Reactive
Extensions

Confidential – Oracle Internal/Restricted/Highly Restricted


private CompletionStage<Integer> getSumOfAllSalaries() {
Materializer materializer = ActorMaterializer.create(actorSystem);

return AkkaEmployeeDAO.getInstance()
.streamAllEmployees(materializer)
.map(Employee::getSalary)
.filter(Optional::isPresent)
.map(Optional::get)
.runFold(0,
(sum, salary) -> sum + salary,
materializer);
}

public static void main(String[] args) {


AkkaDemo demo = new AkkaDemo();
demo.getSumOfAllSalaries()
.thenAccept(System.out::println)
.toCompletableFuture()
.join();

demo.actorSystem.terminate();
}

}
Copyright © 2019 Oracle and/or its affiliates.
Modern Java Database Access: Async/Reactive, Fibers
operators (map, reduce, filters), Implements Java SE
concurrency modeling, reactive stream
monitoring, tracing interface (Flow)

3rd party
Reactive
Full Reactive Streams
Streams JDBC
Library * Reactive
Oracle
User JDBC
Extension
Java
Code (Fibers
Async call with non-blocking ready)
backpressure

Sync/blocking calls

❖ Reactor, RxJava and Akka Streams certified with JDBC Reactive Extensions
❖ Working on the Reactive Relational Database Connectivity (R2DBC) API for the Oracle Database
Copyright © 2019 Oracle and/or its affiliates.
Fibers is the Future of Java Scalability

• Fiber code is as scalable as async code but simpler


• Structured Concurrency
• Frameworks and libraries must change to take advantage of fibers
• Oracle Database 20c JDBC drivers are fiber-ready
• A Fiber blocked waiting on a database uses negligible resources
• Your Oracle JDBC code using 20c will work with Fibers without change
• Use exactly the same JDBC API we all know and love and get the scalability you need

Copyright © 2019 Oracle and/or its affiliates.


64

Database Streaming - Logical Architecture


• Protocol handling (Cloud, IoT, Oracle
REST, gRPC, FTP Kafka) Analytics
MQTT, AMQP, • Reactive Streams Ingestion with Cloud
IoT
Devices backpressure
Real time
DB as Kafla
• Autonomous, Multitenant, Analytics
Serverless
9 8 7 6 5 4 Consumer
• Kafka Subscriber (ingest topics)
Kafka 8 7 6 5 4 Kafka binary • Payload: JSON and others
Topics 7 6 5 4 Protocol / TCP • Data transformation & format
Fast
conversion Ingest
Streaming • Routing to Shards (On-Premises)
Agents • HA and high security Tables, AQ
Memoptimzed
Files • SDK for developers Rowstore

• Monitoring and Alerts


• Interface with Oracle Analytics
Cloud

Oracle Confidential – Internal/Restricted/Highly Restricted


Thank you!

You might also like