SlideShare a Scribd company logo
1 of 56
Reactive Relational
Database Connectivity
Maarten Smeets
@MaartenSmeetsNL
Who am I?
Who is Maarten?
• Software architect at AMIS / Conclusion
• Active community member
(e.g. blogging, presenting, writing articles)
@MaartenSmeetsNL
https://nl.linkedin.com/in/smeetsm
Maarten.Smeets@amis.nl
@MaartenSmeetsNL
What is the CJIB
• The Central Judicial Collection Agency
part of the Ministry of Justice and Security in the Netherlands
• The CJIB is responsible for collecting a range of different fines, such as traffic
fines and punitive orders.
• Works together with EU Member States when it comes to collecting fines.
• Plays a key enforcement role in decisions relating to criminal matters, such as
• court rulings
• decisions made by one of the Public Prosecution Service’s public
prosecutors
• Located in Leeuwarden, Friesland
Where do I work?
@MaartenSmeetsNL
The CJIB and Java
• 1400 people. ICT department of around 325 people. 100 Java developers
• 30 teams using Scrum and SAFe. Tight integration between business and IT
• Solid CI/CD pipelines and release train
• Automated testing using Cucumber, Gherkin
• Code quality checks using SonarQube
• Bamboo, Jenkins, Puppet, Git, Maven, Vault
• Running on
• CentOS 7
• OpenJDK 11, Spring Boot in containers on Kubernetes
CJIB ICT
@MaartenSmeetsNL
Disclaimer
• The performance tests mentioned in this presentation were conducted with intention to obtain information on
what performance differences can be expected from running R2DBC vs JDBC. A best effort has been made to
conduct an unbiased test. Still, performance depends on many parameters such as hardware, specifics of the
framework implementation, the usage of different back-ends, concurrency, versions of libraries, OS, virtualization
and various other factors. I cannot provide any guarantees that the same or similar results will be achieved with
other than tested configurations. The use of these results is at your own risk. I shall in no case accept liability for
any loss resulting from the use of the results or decisions based on them.
@MaartenSmeetsNL
What do you need
to access a relational database from Java?
Lets look at a JDBC stack
@MaartenSmeetsNL
JDBC. What is it?
• Java Database Connectivity
• Released in 1997 by Sun Microsystems in JDK 1.1
• Provides an API to access relational databases
@MaartenSmeetsNL
JDBC. What is it?
• Java Database Connectivity
• Released in 1997 by Sun Microsystems in JDK 1.1
• Provides an API to access relational databases
Don’t do this!
Use a framework
@MaartenSmeetsNL
JDBC driver and connection pool
Java Persistence API (JPA)
Service
Controller
Client
JVM
HTTP
Business logic
Object Relational Mapping (ORM)
Repositories, DAOs, transaction management
Exposed endpoints
Database access
@MaartenSmeetsNL
Java from service to database.
A Spring JDBC stack
Service
Spring
WebMVCorWebflux
SpringDataJPA
Business
logic
Repository
ORM
Database
access
SQL
HTTP
Controller
Client
JDBCdriver
connectionpool
@MaartenSmeetsNL
Java from service to database.
A Spring JDBC stack
Service
Spring
WebMVCorWebflux
SpringDataJPA
Business
logic
Repository
ORM
Database
access
SQL
HTTP
Controller
Client
JDBCdriver
connectionpool
JDBC specific
@MaartenSmeetsNL
A relational database
Department
# deptNo
*name
Employee
# empNo
*name
* deptNo
SELECT emp.name
FROM Employee emp, Department dept
WHERE emp.deptNo=dept.deptNo
AND dept.name=‘Administration’
SQL
Primary key
Foreign key
@MaartenSmeetsNL
Java: Entities using JPA annotations
Employees Departments
Class
Attributes
Methods
Relation
Table
Column
@MaartenSmeetsNL
Repository
Bridge the gap between datasource and business logic
• Predefined operations on entities
CrudRepository: FindById, Save, Count, Delete
• Query derivation based on interface method name
countByDepartment, listByDepartment, deleteByDepartment
findByLastnameOrderByFirstnameAsc
• Define named queries
using JPQL or native SQL using @Query
@Query("select u from User u where u.emailAddress = ?1")
User findByEmailAddress(String emailAddress);
@MaartenSmeetsNL
JDBC and threads
• A thread per database call
JDBC consumes a thread per database call
• Blocks while waiting
JDBC blocks the thread until the call is done or it is interrupted
• Connections consume threads
• The connection pool can block threads
If more connections than the pool size are required,
the connection pool blocks the requesting thread
@MaartenSmeetsNL
JDBC and threads
https://medium.com/@filia.aleks/r2dbc-vs-jdbc-19ac3c99fafa
Lots of threads
Most threads are blocked
Lots
@MaartenSmeetsNL
CPU cost
• Few threads can run in parallel
Motherboard sockets have CPUs. CPUs have cores. Cores handle threads.
A single core handles a single thread or 2 threads with hyperthreading (HT)
E.g. my laptop: 1 socket, 1 CPU, 12 cores, 24 threads (with HT)
• More threads might require blocking and switching
If the system requires more threads than can be accommodated,
e.g. if many threads are blocked due to waiting for a database result or connection
it might have to switch between threads (storing and restoring state)
Switching between threads is called context switching
this is computationally expensive
Thread 1 Thread 2
User code
Kernel code
User code
Kernel code
User code
Kernel code
User code
Context switch
Context switch
Context switch
@MaartenSmeetsNL
Memory cost
Reserved memory is virtual (but process private)
Committed memory is actually mapped to RAM or swap
• Java 8
Reserved and Committed memory is close to a number of threads * 1MB
• Java 11
No longer aggressively allocates up to Reserved Memory at the time of thread creation
Committed memory is much lower. Other threads of the same process can use it!
• Java 12
JEP 346: Promptly return unused committed memory from G1
after a period of low application activity
https://dzone.com/articles/how-much-memory-does-a-java-thread-take
@MaartenSmeetsNL
Consequences
Of how JDBC and JPA use threads
• Scaling
– At high concurrency blocking threads
causes increased overhead and throughput drops
@MaartenSmeetsNL
• Long running operations
– Stuck threads
– Thread starvation
– Application responsiveness
Consequences
Of how JDBC and JPA use threads
@MaartenSmeetsNL
We can do better!
@MaartenSmeetsNL
R2DBC
Reactive Relational Database Connectivity
• Non-blocking
Provides a fully-reactive non-blocking API
No more ‘one thread per connection’
@MaartenSmeetsNL
R2DBC
Reactive Relational Database Connectivity
• Open
Provides an open standard
for driver vendors to implement
@MaartenSmeetsNL
R2DBC
Reactive Relational Database Connectivity
• More efficient usage of resources
@MaartenSmeetsNL
R2DBC
Reactive Relational Database Connectivity
• More efficient usage of resources
• More responsive applications
@MaartenSmeetsNL
R2DBC
Reactive Relational Database Connectivity
• More efficient usage of resources
• More responsive applications
• Handle high concurrency efficiently
@MaartenSmeetsNL
Implementing R2DBC
@MaartenSmeetsNL
Java from service to database.
A Spring R2DBC stack
Service
Spring
WebMVCorWebflux
SpringDataR2DBC
Business
logic
Repository
ORM
Database
access
SQL
HTTP
Controller
Client
R2DBCdriver
connectionpool
@MaartenSmeetsNL
Spring Data R2DBC
• No JPA
Reactive Repositories are not supported by JPA
So no JPA! No Hibernate, EclipseLink, OpenJPA
@MaartenSmeetsNL
Spring Data R2DBC
• No JPA
Reactive Repositories are not supported by JPA
So no JPA! No Hibernate, EclipseLink, OpenJPA
• No Spring Data REST
Reactive Repositories are not supported by Spring Data REST
You have to manually write your controller implementation
@MaartenSmeetsNL
Spring Data R2DBC
• No JPA
Reactive Repositories are not supported by JPA
So no JPA! No Hibernate, EclipseLink, OpenJPA
• No Spring Data REST
Reactive Repositories are not supported by Spring Data REST
You have to manually write your controller implementation
• No JPA annotations
Spring Data R2DBC uses Spring Data annotations on entities instead of JPA
– org.springframework.data.annotation.* instead of javax.persistence.*
@MaartenSmeetsNL
Spring Data R2DBC
• No JPA
Reactive Repositories are not supported by JPA
So no JPA! No Hibernate, EclipseLink, OpenJPA
• No Spring Data REST
Reactive Repositories are not supported by Spring Data REST
You have to manually write your controller implementation
• No JPA annotations
Spring Data R2DBC uses Spring Data annotations on entities instead of JPA
– org.springframework.data.annotation.* instead of javax.persistence.*
• Less functionality
Spring Data R2DBC lacks some functionality
– Generate a schema from entities
– Executing an SQL script on startup
@MaartenSmeetsNL
Spring Data R2DBC
Spring Data R2DBC Spring Data JPA (JDBC)
Uses Hibernate or other JPA
Hibernate Reactive (Vert.X)
Object Relational Mapping X X X
Transaction management X X X
Reactive repositories X
Blocking repositories X
Caching X X
Lazy loading X X
Write behind X X
Reactive interfaces Reactor (Flux, Mono) Mutiny (Multi, Uni)
‘The Quarkus team is exploring various alternatives to bridging the gap between the JPA and Reactive worlds.’
https://quarkus.io/guides/spring-data-jpa
@MaartenSmeetsNL
Spring Data
Web
Database driver
Spring Data JPA Spring Data R2DBC
@MaartenSmeetsNL
Spring Data JPA
Entity
Repository
Entity
Repository
Spring Data R2DBC
@MaartenSmeetsNL
Spring Data JPA
Entity
Repository
Entity
Repository
Spring Data R2DBC
No generated value
No schema generation
from entities
No JPA annotations
No Spring Data REST annotations possible
@MaartenSmeetsNL
Blocking RestController Non-blocking RestController
@MaartenSmeetsNL
Blocking RestController Non-blocking RestController
@MaartenSmeetsNL
Performance of R2DBC
@MaartenSmeetsNL
R2DBC and threads
https://medium.com/@filia.aleks/r2dbc-vs-jdbc-19ac3c99fafa
Few threads
Little blocking
@MaartenSmeetsNL
But does it actually perform better?
Let’s do a benchmark!
Driver
ORM
Web
@MaartenSmeetsNL
Some details about the measures
• GET requests
Simple GET requests using wrk
to fetch data from a Postgres database
GET
@MaartenSmeetsNL
Some details about the measures
• GET requests
Simple GET requests using wrk
to fetch data from a Postgres database
• Priming
First 10 seconds priming at high load.
To initialize the connection pool and load classes.
GET
@MaartenSmeetsNL
Some details about the measures
• GET requests
Simple GET requests using wrk
to fetch data from a Postgres database
• Priming
First 10 seconds priming at high load.
To initialize the connection pool and load classes.
• Dedicated resources
4 CPU threads for the load generator
4 CPU threads for the service
4 CPU threads for the database
OpenJDK 11 on Ubuntu 18.04, 2Gb heap for the JVM
GET
@MaartenSmeetsNL
About the data processing
Python!
• Parsing output
JupyterLab
@MaartenSmeetsNL
About the data processing
Python!
• Parsing output
JupyterLab
• Data processing
Pandas, Numpy
@MaartenSmeetsNL
About the data processing
Python!
• Parsing output
JupyterLab
• Data processing
Pandas, Numpy
• Visualisation
Matplotlib
@MaartenSmeetsNL
Latency / response times
Lower is better!
• At high concurrency R2DBC gives better response times
• WebFlux gives better response times than Web MVC
• Even one reactive component (R2DBC or Webflux)
improves response times
@MaartenSmeetsNL
Throughput
Higher is better!
• Throughput of R2DBC is better than JDBC
at high concurrency
• Web MVC + JDBC
does best at low concurrency
starts to perform worse at high concurrency
• R2DBC and WebFlux show more stable throughput
• WebFlux with JDBC gives worst throughput
at any concurrency
@MaartenSmeetsNL
Memory usage per request
Lower is better!
• Web MVC + JDBC uses least memory
at low concurrency
• R2DBC uses less memory per request than JDBC
at high concurrency
@MaartenSmeetsNL
CPU usage per request
Lower is better!
• Web MVC + JDBC does best
at low concurrency
• R2DBC uses less CPU than JDBC
at high concurrency
• Web MVC + JDBC uses more CPU per request
as concurrency increases
• A single non-blocking component
causes a more stable CPU usage per request
@MaartenSmeetsNL
Summary performance tests
• At low concurrency
Web MVC + JDBC gives best response times and throughput
Uses resources more efficiently than R2DBC
@MaartenSmeetsNL
Summary performance tests
• At low concurrency
Web MVC + JDBC gives best response times and throughput
Uses resources more efficiently than R2DBC
• At high concurrency
R2DBC gives better response times and throughput
R2DBC uses resources more efficiently
@MaartenSmeetsNL
A look into the future
Oracle 20c Oracle Database JDBC drivers are fiber-ready. Fibers impose some
restrictions on user code. The Oracle Database JDBC drivers to be released in
Oracle 20c have been tweaked to fully support fibers. As fibers are not yet part
of the JDK, the 20c JDBC drivers do not use fibers. They will work properly with
any user code that does use fibers though. So when Loom is integrated into the
JDK, you can use the 20c or later Oracle Database JDBC drivers and get the full
benefit.
Douglas Surber, JDBC architect at Oracle
@MaartenSmeetsNL
References
• Spring: Blocking vs non-blocking: R2DBC vs JDBC and WebFlux vs Web MVC
https://bit.ly/R2DBC_performance
• Sample code and test scripts
https://bit.ly/R2DBC_sample
• Homepage R2DBC
https://r2dbc.io/
• Spring Data R2DBC
https://spring.io/projects/spring-data-r2dbc
Questions

More Related Content

Similar to R2DBC Reactive Relational Database Connectivity

Observability in real time at scale
Observability in real time at scaleObservability in real time at scale
Observability in real time at scaleBalvinder Hira
 
W-JAX Performance Workshop - Database Performance
W-JAX Performance Workshop - Database PerformanceW-JAX Performance Workshop - Database Performance
W-JAX Performance Workshop - Database PerformanceAlois Reitbauer
 
OUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worldsOUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worldsAndrew Morgan
 
Jethro for tableau webinar (11 15)
Jethro for tableau webinar (11 15)Jethro for tableau webinar (11 15)
Jethro for tableau webinar (11 15)Remy Rosenbaum
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivityVaishali Modi
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivityVaishali Modi
 
Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Markus Eisele
 
adap-stability-202310.pptx
adap-stability-202310.pptxadap-stability-202310.pptx
adap-stability-202310.pptxMichael Ming Lei
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Lucas Jellema
 
Development of concurrent services using In-Memory Data Grids
Development of concurrent services using In-Memory Data GridsDevelopment of concurrent services using In-Memory Data Grids
Development of concurrent services using In-Memory Data Gridsjlorenzocima
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Modelkunj desai
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2divzi1913
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET Journal
 
Silicon Valley JUG meetup July 18, 2018
Silicon Valley JUG meetup July 18, 2018Silicon Valley JUG meetup July 18, 2018
Silicon Valley JUG meetup July 18, 2018Oracle Developers
 
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web Service700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web ServiceEvan Chan
 
700 Queries Per Second with Updates: Spark As A Real-Time Web Service
700 Queries Per Second with Updates: Spark As A Real-Time Web Service700 Queries Per Second with Updates: Spark As A Real-Time Web Service
700 Queries Per Second with Updates: Spark As A Real-Time Web ServiceSpark Summit
 

Similar to R2DBC Reactive Relational Database Connectivity (20)

Observability in real time at scale
Observability in real time at scaleObservability in real time at scale
Observability in real time at scale
 
W-JAX Performance Workshop - Database Performance
W-JAX Performance Workshop - Database PerformanceW-JAX Performance Workshop - Database Performance
W-JAX Performance Workshop - Database Performance
 
OUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worldsOUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
 
Midao JDBC presentation
Midao JDBC presentationMidao JDBC presentation
Midao JDBC presentation
 
Jethro for tableau webinar (11 15)
Jethro for tableau webinar (11 15)Jethro for tableau webinar (11 15)
Jethro for tableau webinar (11 15)
 
Meteor + React
Meteor + ReactMeteor + React
Meteor + React
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19
 
Presto
PrestoPresto
Presto
 
adap-stability-202310.pptx
adap-stability-202310.pptxadap-stability-202310.pptx
adap-stability-202310.pptx
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)
 
Development of concurrent services using In-Memory Data Grids
Development of concurrent services using In-Memory Data GridsDevelopment of concurrent services using In-Memory Data Grids
Development of concurrent services using In-Memory Data Grids
 
Kafka & Hadoop in Rakuten
Kafka & Hadoop in RakutenKafka & Hadoop in Rakuten
Kafka & Hadoop in Rakuten
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database Connectivity
 
Silicon Valley JUG meetup July 18, 2018
Silicon Valley JUG meetup July 18, 2018Silicon Valley JUG meetup July 18, 2018
Silicon Valley JUG meetup July 18, 2018
 
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web Service700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
 
700 Queries Per Second with Updates: Spark As A Real-Time Web Service
700 Queries Per Second with Updates: Spark As A Real-Time Web Service700 Queries Per Second with Updates: Spark As A Real-Time Web Service
700 Queries Per Second with Updates: Spark As A Real-Time Web Service
 

More from Maarten Smeets

Google jib: Building Java containers without Docker
Google jib: Building Java containers without DockerGoogle jib: Building Java containers without Docker
Google jib: Building Java containers without DockerMaarten Smeets
 
Introduction to Anchore Engine
Introduction to Anchore EngineIntroduction to Anchore Engine
Introduction to Anchore EngineMaarten Smeets
 
Performance Issue? Machine Learning to the rescue!
Performance Issue? Machine Learning to the rescue!Performance Issue? Machine Learning to the rescue!
Performance Issue? Machine Learning to the rescue!Maarten Smeets
 
Performance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMsPerformance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMsMaarten Smeets
 
Performance of Microservice frameworks on different JVMs
Performance of Microservice frameworks on different JVMsPerformance of Microservice frameworks on different JVMs
Performance of Microservice frameworks on different JVMsMaarten Smeets
 
VirtualBox networking explained
VirtualBox networking explainedVirtualBox networking explained
VirtualBox networking explainedMaarten Smeets
 
Microservices on Application Container Cloud Service
Microservices on Application Container Cloud ServiceMicroservices on Application Container Cloud Service
Microservices on Application Container Cloud ServiceMaarten Smeets
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsMaarten Smeets
 
All you need to know about transport layer security
All you need to know about transport layer securityAll you need to know about transport layer security
All you need to know about transport layer securityMaarten Smeets
 
Webservice security considerations and measures
Webservice security considerations and measuresWebservice security considerations and measures
Webservice security considerations and measuresMaarten Smeets
 
Machine learning with R
Machine learning with RMachine learning with R
Machine learning with RMaarten Smeets
 
WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!Maarten Smeets
 
Oracle SOA Suite 12.2.1 new features
Oracle SOA Suite 12.2.1 new featuresOracle SOA Suite 12.2.1 new features
Oracle SOA Suite 12.2.1 new featuresMaarten Smeets
 
How to build a cloud adapter
How to build a cloud adapterHow to build a cloud adapter
How to build a cloud adapterMaarten Smeets
 
WebLogic authentication debugging
WebLogic authentication debuggingWebLogic authentication debugging
WebLogic authentication debuggingMaarten Smeets
 

More from Maarten Smeets (16)

Google jib: Building Java containers without Docker
Google jib: Building Java containers without DockerGoogle jib: Building Java containers without Docker
Google jib: Building Java containers without Docker
 
Introduction to Anchore Engine
Introduction to Anchore EngineIntroduction to Anchore Engine
Introduction to Anchore Engine
 
Performance Issue? Machine Learning to the rescue!
Performance Issue? Machine Learning to the rescue!Performance Issue? Machine Learning to the rescue!
Performance Issue? Machine Learning to the rescue!
 
Performance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMsPerformance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMs
 
Performance of Microservice frameworks on different JVMs
Performance of Microservice frameworks on different JVMsPerformance of Microservice frameworks on different JVMs
Performance of Microservice frameworks on different JVMs
 
VirtualBox networking explained
VirtualBox networking explainedVirtualBox networking explained
VirtualBox networking explained
 
Microservices on Application Container Cloud Service
Microservices on Application Container Cloud ServiceMicroservices on Application Container Cloud Service
Microservices on Application Container Cloud Service
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck Threads
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
All you need to know about transport layer security
All you need to know about transport layer securityAll you need to know about transport layer security
All you need to know about transport layer security
 
Webservice security considerations and measures
Webservice security considerations and measuresWebservice security considerations and measures
Webservice security considerations and measures
 
Machine learning with R
Machine learning with RMachine learning with R
Machine learning with R
 
WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!WebLogic Scripting Tool made Cool!
WebLogic Scripting Tool made Cool!
 
Oracle SOA Suite 12.2.1 new features
Oracle SOA Suite 12.2.1 new featuresOracle SOA Suite 12.2.1 new features
Oracle SOA Suite 12.2.1 new features
 
How to build a cloud adapter
How to build a cloud adapterHow to build a cloud adapter
How to build a cloud adapter
 
WebLogic authentication debugging
WebLogic authentication debuggingWebLogic authentication debugging
WebLogic authentication debugging
 

Recently uploaded

Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

R2DBC Reactive Relational Database Connectivity

  • 2. @MaartenSmeetsNL Who am I? Who is Maarten? • Software architect at AMIS / Conclusion • Active community member (e.g. blogging, presenting, writing articles) @MaartenSmeetsNL https://nl.linkedin.com/in/smeetsm Maarten.Smeets@amis.nl
  • 3. @MaartenSmeetsNL What is the CJIB • The Central Judicial Collection Agency part of the Ministry of Justice and Security in the Netherlands • The CJIB is responsible for collecting a range of different fines, such as traffic fines and punitive orders. • Works together with EU Member States when it comes to collecting fines. • Plays a key enforcement role in decisions relating to criminal matters, such as • court rulings • decisions made by one of the Public Prosecution Service’s public prosecutors • Located in Leeuwarden, Friesland Where do I work?
  • 4. @MaartenSmeetsNL The CJIB and Java • 1400 people. ICT department of around 325 people. 100 Java developers • 30 teams using Scrum and SAFe. Tight integration between business and IT • Solid CI/CD pipelines and release train • Automated testing using Cucumber, Gherkin • Code quality checks using SonarQube • Bamboo, Jenkins, Puppet, Git, Maven, Vault • Running on • CentOS 7 • OpenJDK 11, Spring Boot in containers on Kubernetes CJIB ICT
  • 5. @MaartenSmeetsNL Disclaimer • The performance tests mentioned in this presentation were conducted with intention to obtain information on what performance differences can be expected from running R2DBC vs JDBC. A best effort has been made to conduct an unbiased test. Still, performance depends on many parameters such as hardware, specifics of the framework implementation, the usage of different back-ends, concurrency, versions of libraries, OS, virtualization and various other factors. I cannot provide any guarantees that the same or similar results will be achieved with other than tested configurations. The use of these results is at your own risk. I shall in no case accept liability for any loss resulting from the use of the results or decisions based on them.
  • 6. @MaartenSmeetsNL What do you need to access a relational database from Java? Lets look at a JDBC stack
  • 7. @MaartenSmeetsNL JDBC. What is it? • Java Database Connectivity • Released in 1997 by Sun Microsystems in JDK 1.1 • Provides an API to access relational databases
  • 8. @MaartenSmeetsNL JDBC. What is it? • Java Database Connectivity • Released in 1997 by Sun Microsystems in JDK 1.1 • Provides an API to access relational databases Don’t do this! Use a framework
  • 9. @MaartenSmeetsNL JDBC driver and connection pool Java Persistence API (JPA) Service Controller Client JVM HTTP Business logic Object Relational Mapping (ORM) Repositories, DAOs, transaction management Exposed endpoints Database access
  • 10. @MaartenSmeetsNL Java from service to database. A Spring JDBC stack Service Spring WebMVCorWebflux SpringDataJPA Business logic Repository ORM Database access SQL HTTP Controller Client JDBCdriver connectionpool
  • 11. @MaartenSmeetsNL Java from service to database. A Spring JDBC stack Service Spring WebMVCorWebflux SpringDataJPA Business logic Repository ORM Database access SQL HTTP Controller Client JDBCdriver connectionpool JDBC specific
  • 12. @MaartenSmeetsNL A relational database Department # deptNo *name Employee # empNo *name * deptNo SELECT emp.name FROM Employee emp, Department dept WHERE emp.deptNo=dept.deptNo AND dept.name=‘Administration’ SQL Primary key Foreign key
  • 13. @MaartenSmeetsNL Java: Entities using JPA annotations Employees Departments Class Attributes Methods Relation Table Column
  • 14. @MaartenSmeetsNL Repository Bridge the gap between datasource and business logic • Predefined operations on entities CrudRepository: FindById, Save, Count, Delete • Query derivation based on interface method name countByDepartment, listByDepartment, deleteByDepartment findByLastnameOrderByFirstnameAsc • Define named queries using JPQL or native SQL using @Query @Query("select u from User u where u.emailAddress = ?1") User findByEmailAddress(String emailAddress);
  • 15. @MaartenSmeetsNL JDBC and threads • A thread per database call JDBC consumes a thread per database call • Blocks while waiting JDBC blocks the thread until the call is done or it is interrupted • Connections consume threads • The connection pool can block threads If more connections than the pool size are required, the connection pool blocks the requesting thread
  • 17. @MaartenSmeetsNL CPU cost • Few threads can run in parallel Motherboard sockets have CPUs. CPUs have cores. Cores handle threads. A single core handles a single thread or 2 threads with hyperthreading (HT) E.g. my laptop: 1 socket, 1 CPU, 12 cores, 24 threads (with HT) • More threads might require blocking and switching If the system requires more threads than can be accommodated, e.g. if many threads are blocked due to waiting for a database result or connection it might have to switch between threads (storing and restoring state) Switching between threads is called context switching this is computationally expensive Thread 1 Thread 2 User code Kernel code User code Kernel code User code Kernel code User code Context switch Context switch Context switch
  • 18. @MaartenSmeetsNL Memory cost Reserved memory is virtual (but process private) Committed memory is actually mapped to RAM or swap • Java 8 Reserved and Committed memory is close to a number of threads * 1MB • Java 11 No longer aggressively allocates up to Reserved Memory at the time of thread creation Committed memory is much lower. Other threads of the same process can use it! • Java 12 JEP 346: Promptly return unused committed memory from G1 after a period of low application activity https://dzone.com/articles/how-much-memory-does-a-java-thread-take
  • 19. @MaartenSmeetsNL Consequences Of how JDBC and JPA use threads • Scaling – At high concurrency blocking threads causes increased overhead and throughput drops
  • 20. @MaartenSmeetsNL • Long running operations – Stuck threads – Thread starvation – Application responsiveness Consequences Of how JDBC and JPA use threads
  • 22. @MaartenSmeetsNL R2DBC Reactive Relational Database Connectivity • Non-blocking Provides a fully-reactive non-blocking API No more ‘one thread per connection’
  • 23. @MaartenSmeetsNL R2DBC Reactive Relational Database Connectivity • Open Provides an open standard for driver vendors to implement
  • 24. @MaartenSmeetsNL R2DBC Reactive Relational Database Connectivity • More efficient usage of resources
  • 25. @MaartenSmeetsNL R2DBC Reactive Relational Database Connectivity • More efficient usage of resources • More responsive applications
  • 26. @MaartenSmeetsNL R2DBC Reactive Relational Database Connectivity • More efficient usage of resources • More responsive applications • Handle high concurrency efficiently
  • 28. @MaartenSmeetsNL Java from service to database. A Spring R2DBC stack Service Spring WebMVCorWebflux SpringDataR2DBC Business logic Repository ORM Database access SQL HTTP Controller Client R2DBCdriver connectionpool
  • 29. @MaartenSmeetsNL Spring Data R2DBC • No JPA Reactive Repositories are not supported by JPA So no JPA! No Hibernate, EclipseLink, OpenJPA
  • 30. @MaartenSmeetsNL Spring Data R2DBC • No JPA Reactive Repositories are not supported by JPA So no JPA! No Hibernate, EclipseLink, OpenJPA • No Spring Data REST Reactive Repositories are not supported by Spring Data REST You have to manually write your controller implementation
  • 31. @MaartenSmeetsNL Spring Data R2DBC • No JPA Reactive Repositories are not supported by JPA So no JPA! No Hibernate, EclipseLink, OpenJPA • No Spring Data REST Reactive Repositories are not supported by Spring Data REST You have to manually write your controller implementation • No JPA annotations Spring Data R2DBC uses Spring Data annotations on entities instead of JPA – org.springframework.data.annotation.* instead of javax.persistence.*
  • 32. @MaartenSmeetsNL Spring Data R2DBC • No JPA Reactive Repositories are not supported by JPA So no JPA! No Hibernate, EclipseLink, OpenJPA • No Spring Data REST Reactive Repositories are not supported by Spring Data REST You have to manually write your controller implementation • No JPA annotations Spring Data R2DBC uses Spring Data annotations on entities instead of JPA – org.springframework.data.annotation.* instead of javax.persistence.* • Less functionality Spring Data R2DBC lacks some functionality – Generate a schema from entities – Executing an SQL script on startup
  • 33. @MaartenSmeetsNL Spring Data R2DBC Spring Data R2DBC Spring Data JPA (JDBC) Uses Hibernate or other JPA Hibernate Reactive (Vert.X) Object Relational Mapping X X X Transaction management X X X Reactive repositories X Blocking repositories X Caching X X Lazy loading X X Write behind X X Reactive interfaces Reactor (Flux, Mono) Mutiny (Multi, Uni) ‘The Quarkus team is exploring various alternatives to bridging the gap between the JPA and Reactive worlds.’ https://quarkus.io/guides/spring-data-jpa
  • 36. @MaartenSmeetsNL Spring Data JPA Entity Repository Entity Repository Spring Data R2DBC No generated value No schema generation from entities No JPA annotations No Spring Data REST annotations possible
  • 41. @MaartenSmeetsNL But does it actually perform better? Let’s do a benchmark! Driver ORM Web
  • 42. @MaartenSmeetsNL Some details about the measures • GET requests Simple GET requests using wrk to fetch data from a Postgres database GET
  • 43. @MaartenSmeetsNL Some details about the measures • GET requests Simple GET requests using wrk to fetch data from a Postgres database • Priming First 10 seconds priming at high load. To initialize the connection pool and load classes. GET
  • 44. @MaartenSmeetsNL Some details about the measures • GET requests Simple GET requests using wrk to fetch data from a Postgres database • Priming First 10 seconds priming at high load. To initialize the connection pool and load classes. • Dedicated resources 4 CPU threads for the load generator 4 CPU threads for the service 4 CPU threads for the database OpenJDK 11 on Ubuntu 18.04, 2Gb heap for the JVM GET
  • 45. @MaartenSmeetsNL About the data processing Python! • Parsing output JupyterLab
  • 46. @MaartenSmeetsNL About the data processing Python! • Parsing output JupyterLab • Data processing Pandas, Numpy
  • 47. @MaartenSmeetsNL About the data processing Python! • Parsing output JupyterLab • Data processing Pandas, Numpy • Visualisation Matplotlib
  • 48. @MaartenSmeetsNL Latency / response times Lower is better! • At high concurrency R2DBC gives better response times • WebFlux gives better response times than Web MVC • Even one reactive component (R2DBC or Webflux) improves response times
  • 49. @MaartenSmeetsNL Throughput Higher is better! • Throughput of R2DBC is better than JDBC at high concurrency • Web MVC + JDBC does best at low concurrency starts to perform worse at high concurrency • R2DBC and WebFlux show more stable throughput • WebFlux with JDBC gives worst throughput at any concurrency
  • 50. @MaartenSmeetsNL Memory usage per request Lower is better! • Web MVC + JDBC uses least memory at low concurrency • R2DBC uses less memory per request than JDBC at high concurrency
  • 51. @MaartenSmeetsNL CPU usage per request Lower is better! • Web MVC + JDBC does best at low concurrency • R2DBC uses less CPU than JDBC at high concurrency • Web MVC + JDBC uses more CPU per request as concurrency increases • A single non-blocking component causes a more stable CPU usage per request
  • 52. @MaartenSmeetsNL Summary performance tests • At low concurrency Web MVC + JDBC gives best response times and throughput Uses resources more efficiently than R2DBC
  • 53. @MaartenSmeetsNL Summary performance tests • At low concurrency Web MVC + JDBC gives best response times and throughput Uses resources more efficiently than R2DBC • At high concurrency R2DBC gives better response times and throughput R2DBC uses resources more efficiently
  • 54. @MaartenSmeetsNL A look into the future Oracle 20c Oracle Database JDBC drivers are fiber-ready. Fibers impose some restrictions on user code. The Oracle Database JDBC drivers to be released in Oracle 20c have been tweaked to fully support fibers. As fibers are not yet part of the JDK, the 20c JDBC drivers do not use fibers. They will work properly with any user code that does use fibers though. So when Loom is integrated into the JDK, you can use the 20c or later Oracle Database JDBC drivers and get the full benefit. Douglas Surber, JDBC architect at Oracle
  • 55. @MaartenSmeetsNL References • Spring: Blocking vs non-blocking: R2DBC vs JDBC and WebFlux vs Web MVC https://bit.ly/R2DBC_performance • Sample code and test scripts https://bit.ly/R2DBC_sample • Homepage R2DBC https://r2dbc.io/ • Spring Data R2DBC https://spring.io/projects/spring-data-r2dbc

Editor's Notes

  1. https://www.codejava.net/frameworks/hibernate/java-hibernate-reverse-engineering-tutorial-with-eclipse-and-mysql
  2. Thus in theory at high concurrency Less threads required Less memory usage Less context switching Less CPU usage
  3. Thus in theory at high concurrency Less threads required Less memory usage Less context switching Less CPU usage
  4. Thus in theory at high concurrency Less threads required Less memory usage Less context switching Less CPU usage
  5. Thus in theory at high concurrency Less threads required Less memory usage Less context switching Less CPU usage
  6. Thus in theory at high concurrency Less threads required Less memory usage Less context switching Less CPU usage