An Evaluation of Spring Webflux: With Focus On Built in SQL Features
An Evaluation of Spring Webflux: With Focus On Built in SQL Features
Karl Dahlin
Abstract
In today’s society the need for more hardware efficient software since
some people think that the doubling of computer power for the same price
that Moore’s law predicted is no more. Reactive programming can be a
step in the right direction, this has led to an increase in interest in reactive
programming. This object of this thesis is to evaluate the possibility of
using reactive programming and R2DBC in Java to communicate with a
relation database. This has been done by creating two Spring applications
one using the standards JDBC and servlet stack and one using R2DBC and
the reactive stack. Then connecting them to a MySQL database and select-
ing and inserting values in to and from it and measuring the CPU usage,
memory usage and execution time. In addition to this the possibilities to
handle BLOBs in a good enough way were researched. The study shows
that there are both advantages and disadvantages with using R2DBC it
has basic support and it is based on good idea but at the time of this the-
sis it still needs more development before it can be used fully.
ii
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Acknowledgments
I would like to thank Easit for supplying a laptop to work on, office space
to work in, an assignment to solve, SQL database to work with and guid-
ance in certain areas during the work.
iii
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Table of Contents
Abstract ii
Acknowledgments iii
Table of Contents v
Terminology vi
1 Introduction 1
1.1 Background and problem motivation . . . . . . . . . . . . . . . 2
1.2 Overall aim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Concrete and verifiable goals . . . . . . . . . . . . . . . . . . . . 3
1.4 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6 Contributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Theory 4
2.1 Spring Framework . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Spring Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Model-view-Controller - MVC . . . . . . . . . . . . . . . . . . . 5
2.4 Reactive programming . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Structured Query Language - SQL – Database . . . . . . . . . . 6
2.6 Java Database Connectivity – JDBC . . . . . . . . . . . . . . . . 7
2.7 Reactive Relational Database Connectivity - R2BDC . . . . . . 7
2.8 Related work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Methodology 10
4 Choice of solution 12
4.1 Reactive Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.1.1 Spring webflux . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1.2 RxJava . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 SQL database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.1 PostgreSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.2 MsSQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2.3 MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.3 Chosen solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5 Implementation 18
5.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.2 Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.2.1 Spring MVC program (Servlet) . . . . . . . . . . . . . . . . . 19
5.2.2 Spring Webflux program (Reactive) . . . . . . . . . . . . . . . 20
5.3 Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
iv
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
6 Results 23
6.1 Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.1.1 JDBC program . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.1.2 R2DBC program . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.1.3 Reactive client . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.2 Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.2.1 JDBC program . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.2.2 R2DBC program . . . . . . . . . . . . . . . . . . . . . . . . . . 30
6.3 R2DBC program - BLOB handling . . . . . . . . . . . . . . . . . 46
7 Conclusions 48
7.1 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.2 Ethical considerations . . . . . . . . . . . . . . . . . . . . . . . . 51
References 53
v
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Terminology
Abbreviation Description
SQL Structured Query Language, programming language
for interacting with a relation database.
BLOB Binary Large OBject, a data type that can be stored in
a SQL database.
JDBC Java Database Connectivity, SQL database driver
specification
R2DBC Reactive Relational Database Connectivity, reactive
SQL database driver specification
vi
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
1. Introduction
More and more data is saved and accessed and there is no indication
of that trend turning, it is more likely that it will increase in the future
since there is continued development of technologies that generate
data, for example the Internet of Things and other smart devices.
1
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
This seems simple on the surface, but it can be deceptively complex for
two reasons: One, it’s hard to make applications work correctly when
you’re wrestling with synchronization and shared structures.
Two, it’s hard to scale efficiently when every blocking operation requires
an extra thread to just sit around and wait, and you’re at the mercy of
latency outside your control (e.g. slow remote clients and services).
2
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
3. Evaluate and present the result from the second, third goal and
potential other observations made during the tests and draw
conclusions.
1.4 Scope
This thesis will only consider the communication between a Java
program and a SQL database and not the rest of the changes that need
to be made to a Java program when rewriting it from using a servlet
stack to a reactive stack. It will also not test all the different ways of
communicating with a database.
1.5 Outline
Chapter 2 describes the relevant theory to the thesis. Chapter 3
describes the method that was used during the thesis. Chapter 4
presents the possible alternatives of frameworks for reactive Java, the
alternatives for SQL database and describes the chosen ones and why
they were chosen. Chapter 5 describes how the different programs
were implemented, the hardware and how the measurements were
conducted. Chapter 6 presents the results from the tests. Chapter 7
presents the conclusion based on the result, discussion of the result,
discussion of ethical aspects and presentations of suggestions for future
work.
1.6 Contributions
Rasmus Holm a fellow student constructed an unofficial LaTeX template
that was used when writing the report.
3
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
2. Theory
In this chapter information about subjects relevant to the study will be
presented and explained briefly. In addition some related work will be
presented.
• Care about API design. The Spring team puts a lot of thought
and time into making APIs that are intuitive and that hold up
across many versions and many years.
• Set high standards for code quality. The Spring Framework puts
a strong emphasis on meaningful, current, and accurate Javadocs.
The View or Views in plural. Is one or more interfaces with the Model
for a given situation and version. In object-oriented terms classes which
give us ”windows” onto the model although Views often are graphical
the do not have to be. Examples of Views:
5
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Views will know of the models existence and some of its nature. An
entry field might display or change an instance variable of some Model
class somewhere.
The Controller lets you manipulate a View. Controllers have the most
knowledge of platforms and operating systems. An over-simplification
is that the Controllers handles the input and the Views the output.
Just like Models have no knowledge of its Views, the Views have no
knowledge of its Controllers.[8]
There are many project specifying what reactive is and how to use it,
for example the The Reactive Manifesto[9] and Reactive Streams[10]
6
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
• Data definition
• Data manipulation
• Access control
• Data sharing
• Data integrity
There are two major sets of interfaces in the JDBC API one for the
application developers (driver users) and one lower-level for the driver
developers. [12]
7
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
[13]
The study differs from what i have done by using a different tool
for reactive Java and a different focus in the blocking vs non-blocking
comparison. It measures performance and latency of a web service
while this thesis focuses on database communication
8
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
The similarities between this study and mine is that both compare the
servlet stack and reactive stack in Spring. The difference is that the
study focuses on the amount of requests the web service can handle
and my thesis focuses on the communication with a database.
9
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
3. Methodology
The work I will do during this project is literary studies of different
internet sources, Java coding to implement two different Spring boot
programs and tests for the programs, evaluation and presentation of
the results.
To solve the first goal which is ”Test the following capabilities of the
programs when handling large amounts of data:” and the test sub-goals
”CPU consumption of the programs Memory usage of the programs, Measure
the execution time.” I will run the programs and measure the CPU usage,
memory usage and execution time of database commands and save the
result. The test will consist of inserting and selecting a large amount of
a data units from a SQL database using the features of Spring Webflux
and Spring MVC respectively. The execution time will be measured
from then a request is sent to the program until it has communicated
with a SQL database and after that returned a response to the request
sender. CPU usage will be measured by using a program to record the
CPU usage of the process during the tests. The memory usage will be
measured using a program to record the memory usage of the process
during the tests.
To solve the third goal which is ”Evaluate and present the result from
the second, third goal and potential other observations made during the tests and
draw conclusions.” I will present the result from the second goal in an
appropriate way then look at it and try to analyze the result and based
10
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
11
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
4. Choice of solution
When working with reactive Java you need to have both a reactive
framework for Java and a reactive database driver. There are several
SQL databases and frameworks for reactive Java that one can use,
in this thesis the SQL database drivers following JDBC and R2DBC
specifications will be used. In the following chapter I will mention a
couple of different SQL databases and frameworks for reactive Java and
what is the focus of this thesis and why.
12
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Class Description
Mono data sequences of 0..1
Flux data sequences of 0..N
Spring Webflux was added in version 5.0 of Spring,[17] version 5.0 was
released in Sep 2017 which mean that Spring Webflux has been released
for a little over 2 years at the time this thesis was conducted.
Figure 4.2 shows how the similarities and differences between the
reactive stack Webflux and the servlet stack Spring MVC.
Figure 4.2: Illustation of how Spring MVC differs from Spring Webflux
4.1.2 RxJava
RxJava makes Java reactive and is a library that implements ReactiveX
in java and builds on the Reactive Streams. RxJava uses the base
classes:[18]
13
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Class Description
Flowable 0..N flows, supporting Reactive-Streams and back-
pressure
Obervable 0..N flows, no backpressure
Single a flow of exactly 1 item or an error
Completable a flow without items but only a completion or error
signal
Maybe a flow with no items, exactly one item or an error
RxJava is currently on version 3.x, version 1.x reached it’s end of life in
March 31, 2018 and version 2.x will reach it’s end of life in February
28, 2021. [18] RxJava version 1.0 were released in Nov 2014.[19] Which
means that version 3.x is the current version, version 2.x is reaching
it’s end of life in about a year and version 1.x reached it’s end of life 2
years before this thesis were conducted.
4.2.1 PostgreSQL
Driver features of the R2DBC PostgreSQL driver according to the
developers[20]:
• SCRAM authentication
• TLS
14
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
• Explicit transactions
• Notifications
• Logical Decode
• Read and write support for all data types except LOB types (e.g.
BLOB, CLOB)
4.2.2 MsSQL
Driver features of the R2DBC MsSQL driver according to the developers
[21]:
• Transaction Control
The data types CLOB and BLOB is fully materialized in the client
before decoding, their next step is Execution of stored procedures and Add
support for TVP and UDTs. [21]
15
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
4.2.3 MySQL
Driver features of the R2DBC MySQL driver according to the
developers[22]:
Their next step is Prepared statements cache and Statement parser cache.
[22]
MySQL was chosen as the SQL database since it was the only driver
that claimed to have reactive support for BLOB and CLOB types and
16
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
I want to test how a reactive system handles that as well see section
4.2.3 for all the features of the driver. The MySQL driver also had
implemented all the support for simple SQL statements, all drivers had
this.
17
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
5. Implementation
In this chapter the implemented programs and their parts are described.
Figure 5.1 shows the planned overall layout of the system where the
Request sender is a program that sends requests to the different Spring
boot programs, Spring boot program is either the program with servlet
stack or the program with reactive stack. When measuring the CPU
usage, memory usage and execution time the programs will connect to
a remote SQL database, but when this is not the focus of the test some
tests will be run with the database running on the same machine as the
program. The version of Java that will be used in this thesis is Java 11.
5.1 Hardware
In this section the two laptops specs will be presented, the second one
is borrowed Easit.
18
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
The first laptop will be referred to as the first laptop or the HP laptop, the
second laptop will be referred to as the second laptop or the Dell laptop.
5.2 Programs
In this section the programs that will be created for testing will
be described. Both of the programs created to test the database
communication will be web clients listening on port 8080 that receives
a request from a third party. To enable this there are some things that
Spring boot auto-configures, these can also be changed if needed. For
example the Spring MVC program needs a Servlet container and the
Spring Webflux needs and async and non-blocking server.
The program will use the JDBC MySQL driver and use the java.sql.Connection
to communicate with the database. The default embedded Servlet con-
tainer Tomcat will be used.
19
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
inserted into the database. The thing that will be counted is the number
of column values.
For selection values the fetch size will be set and data will be fetched by
executing a java.sql.Statement and adding the return result to a ArrayList
and returning the ArrayList to the Request sender.
The program will use the community-driven R2DBC driver for MySQL,
use the default async and non-blocking server Netty.
The program will interact with the database using a feature from the
Spring Framework called repositories, a class called org.springframework
.data.r2dbc.core.DatabaseClient and a class called io.r2dbc.spi.Batch.
A client program will be created as one of the Request senders since when
it comes to the response from the reactive program the response might
need to be handled in a reactive way. This will be done by creating
another Spring boot with just the Spring Reactive Web dependency then
configuring a CommandLineRunner Bean to make a GET request to the
reactive program and then handling the response as a Flux or Mono.
5.3 Measurements
Where the test will be run may wary depending on what is measured
if time, CPU usage and memory consumption are measured the test
will be run on the Dell laptop unless stated otherwise.
20
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
The CPU usage and memory usage measurements will be taken with a
program called VisualVM is a troubleshooting tool with good features.
It used to be a part of Oracle JDK 6-8 as Java VisualVM but from JDK 9
it was discontinued and is now a separate program. [23]
Figure 5.2 shows the layout of VisualVM, to the left the currently
running java processes can be seen in a list and if one is double-
clicked the monitoring view for that process pop up in the rest of
the window. The currently shown tab is the Monitor where you can
monitor an application in real-time, in addition to this there are tabs for
Overview, Threads, Sampler and Profiler and these displays information
corresponding to their name. In addition to monitoring resources it is
possible to see how long a process has been running for.
21
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
22
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
6. Results
In this chapter the features of the programs are explained, the result
from the performance tests is presented and the result of the study of
the possibility to handle BLOBs in a reactive program is presented.
6.1 Programs
In this section the result of the implementation is presented, the thesis
resulted in three different Spring programs. One JDBC program using
servlet stack, one R2DBC program using reactive stack and one reactive
client that sends a request to the reactive program and receives and
handles the response.
23
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
When returning data from the database to the request sender it can be
done as a stream of data or chunks.
6.2 Tests
In this section performance tests are described and the result of the
tests run on the two Spring programs is presented. CPU usage is the
amount of CPU the process takes from the system, memory usage is
the amount of memory the process takes from the system and the
execution time is the time it takes from a program to send a request to
the web service, the web service communicate with the database and
then return the reply to the program that sent the request.
For the insertion tests the data is generated in the same way so it
and the class used in the tests is a custom created class called Book.
Figure 6.1 shows the Java code for the class where internal variables
are present, id is an id that is auto-generated by the database when a
book is added to it, name represents the name of a fake book and price
represents the price of a fake book.
24
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.2 show the layout of the table used in the tests taken from
MySQL workbench. Where id is an auto-generated id assigned by
the database when a value is inserted. Name is a 255 characters
long VARCHAR where the name of the fictional book. Price is a 15
characters long NUMERIC where there can be two after the decimal
point.
Figure 6.2: Screenshot of the columns in the table used for the test.
The INSERT tests are run on an empty table in the database and
the database table is removed and recreated with the SQL commands
shown in figure 6.3.
25
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
The SELECT tests are run on a table with 1 000 000 rows with id 1 to 1
000 000.
26
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
threads.
The SELECT test was run with 1 000 000 values in the table of the
database run a couple of times and always ended up taking around
five seconds. Figure 6.6 show a screenshot of Postman that shows the
type of request and to what address it is sent, the response from the
program and the time it took to get a response on the request.
27
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.7 show in more detail where the time of the request were
spent.
28
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
An almost identical test was run but with the difference that the
heap space was limited to 256 MB. This resulted in a crash of type
java.lang.OutOfMemoryError: Java heap space. In figure 6.9 it is visible
when the program ran out of heap.
29
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
INSERT
30
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
31
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
32
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
RAM usage, loaded classes and threads. which shows that the process
had been running for one hour and eight minutes when the test was
canceled.
Due to the very slow speed of not using reactive transactions the rest
of the tests on this program will only be run with reactive transactions
enabled.
Tests with the DatabaseClient class are executed one after another by
using commands like:
databaseClient.execute(”INSERT INTO books ( name, price) VALUES (”Test
Book - R2DBC”, 5)”)
And this would result in one statement being sent to the database at a
time and each statement handled individually and that would result in
similar results as the repository tests without reactive transactions. So
no 200 000 INSERT tests were done with the DatabaseClient.
The INSERT test with 200 000 values using Batch class failed with the
output in figure 6.15. Got a packet bigger than ’max_allowed_bytes’.
33
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.15: Screenshot of the error output when inserting 200 000
values.
34
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
SELECT
As stated after the first set of insert tests all tests will only be run with
the reactive transactions enabled.
Since the SELECT test consists of just a single select statement. And a
batch is a collection of several statements no select test was conducted
using the Batch class.
The SELECT test with 1 000 000 values using repository and not
streaming the reply back to the sender. Figure 6.18 is a screenshot of
Postman that shows the type of request and to what address it is sent,
the response from the program and the time it took to get a response
on the request.
35
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.19 shows more details on where the time the request took was
spent.
Figure 6.19: Screenshot of time details from Postman after the non-
streaming select.
36
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
instances of the type Book in the database with a repository. It shows the
process uptime, CPU usage, RAM usage, loaded classes and threads.
The SELECT test with 1 000 000 values using repository and streaming
the reply back to the sender. Figure 6.21 is a screenshot of Postman that
shows the type of request and to what address it is sent, the response
from the program and the time it took to get a response on the request.
37
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.22 shows a more details on where the time the request took
were spent.
38
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.22: Screenshot of time details from Postman after the streaming
select.
39
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
The SELECT test with 1 000 000 values using DatabaseClient and not
streaming the reply back to the sender. Figure 6.24 is a screenshot of
Postman that shows the type of request and to what address it is sent,
the response from the program and the time it took to get a response
on the request.
40
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.25 shows a more details on where the time the request took
were spent.
Figure 6.25: Screenshot of time details from Postman after the non-
streaming select.
41
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
for the program’s Java process when an SELECT with 1 000 000
instances of the type Book in the database with a DatabaseClient. It
shows the process uptime, CPU usage, RAM usage, loaded classes and
threads.
The SELECT test with 1 000 000 values using DatabaseClient and
streaming the reply back to the sender. Figure 6.27 is a screenshot of
Postman that shows the type of request and to what address it is sent,
the response from the program and the time it took to get a response
on the request.
42
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.28 shows a more details on where the time the request took
were spent.
43
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.28: Screenshot of time details from Postman after the streaming
select.
44
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
A set of tests was run with heap space limited to 256 MB. These
tests could be completed for all select versions of the R2DBC program.
Figure 6.30 is a screenshot of VisualVM after a completed non-streaming
select using a repository.
45
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Figure 6.31 shows the layout of the table where id is an auto generated
number and the column test is of the type LONGBLOB.
46
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
Tests of trying to use Spring repositories for the table failed. Attempts to
get the BLOBs as a Flux of a type like byte[] resulted in the entire BLOB
being loaded into memory before it could be handled. And attempts to
get them as a Flux of Flux of a class failed. The available heap memory
was lowered to check if it could handle the BLOB without loading the
entire thing into memory. But the program crashed due to it running
out of memory.
47
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
7. Conclusions
Firstly I implemented programs for performance testing in accordance
with what is stated in section 5.2 and what is stated in section 6.3 which
resulted in two programs, one that uses JDBC and servlet stack and one
that uses R2DBC and reactive stack, the features of these programs are
described in section 6.1. The reason for the choices of communication
in the JDBC program is that they were the first ways I encountered
when looking for ways of communicating with a database.
Secondly, I solved the goal Test the following capabilities of the programs
when handling large amounts of data: and the subgoals: CPU consumption
of the programs., Memory usage of the programs. and Measure the execution
time. I did so by inserting and selecting values from the database.
Due to the fact that one of the main points of reactive programming
is that the program should never ask or send more then the program
can handle. Both the inserts with the DatabaseClient and the Batch
class were considered failures since they would require me to manage
the batch size on my own or sending one statement at a time. Those
were mostly included in the thesis to illustrate that there are other
ways of communicating with a database with R2DBC other then Spring
repositories. But the repositories are the main focus of the select and
insert tests of this thesis. So for the insert tests the only result discussed
further is the repository result from the R2DBC and the JDBC programs
result. From the select tests the repository and DatabaseClient result
from the R2DBC program and the result from the JDBC program is
discussed.
The results from the R2DBC without the reactive transactions are not
mentioned since they were so much slower than all the rest, only
inserting around 90 000 in one hour and eight minutes.
48
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
The insert tests show that both the JDBC and the R2DBC programs
repository tests used about the same amount om memory from a bit over
50 MB up to around 250 MB. But the CPU consumption is noticeably
higher on the R2DBC program, Still not high but since it reached a
maximum of 10% in the test with reactive transactions. The execution
time is significantly shorter for the R2DBC program.
The select tests show that the JDBC program was faster then the R2DBC
program but that the JDBC program runs the risk of crashing if it has
too little memory, which the R2DBC does not.
Here I would like to point out that the fetch size of JDBC program is
like the batch size in the insert tests and tweaking of this would speed
it up. But a to large fetch size or batch size runs the risk of crashing
the database or the program communicating with the database. R2DBC
also gives you this by default in theory and it would seem like it does
it in reality as well since when it worked with less memory it handled
it well. It only asks for the amount of data it can handle.
49
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
R2DBC since it was the only driver implementation at the time of this
thesis that claimed to have Reactive LOB types but what that means is
not explained further. From this I drew the conclusion that it is not
possible to handle large BLOBs in a reactive program that uses R2DBC
to communicate with a SQL database.
Fourthly I solved the goal Evaluate and present the result from the sec-
ond, third goal and potential other observations made during the tests and draw
conclusions.
50
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
currently with a reactive program using R2DBC. The fact that I during
the process encountered a steep learning curve when trying to learn
and use reactive Java means that this is probably the case for most
Java developers since reactive code differs quite a bit from ”regular”
code and if it were to be used extensive rewrites of current code would
probably be needed to make it reactive.
One direction to take future work is to evaluate and try to map what
other code changes are needed to switch from servlet to reactive stack.
This would be very dependant on the software but some general points
and estimations could be produced if the study is large enough.
Another thing that can be seen as future work is to redo the comparison
when the drivers have been developed further. For example when a
driver has implemented the entire version 1.0 R2DBC specification.
51
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
transfer protocols it does not add any new things from this perspective.
It is the same as all the other database drivers and as previously stated
does not create any new ethical considerations, but makes it so that
if there are any special ethical considerations needed when working
with reactive programming and asynchronous database communication
needs to be taken in to account when using Java.
52
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
References
[1] TIOBE, “Tiobe index for february 2020.” https://www.tiobe.com/
tiobe-index/. Accessed: Feb 2020.
[12] Y. Bai, JDBC API and JDBC Drivers, pp. 89–111. 2011.
53
An Evaluation of Spring WebFlux - With focus on built in SQL features
Karl Dahlin 2020-06-17
[13] Ben Hale, Mark Paluch, Greg Turnquist, Jay Bryant, “R2dbc
- reactive relational database connectivity.” https://r2dbc.io/
spec/0.8.1.RELEASE/spec/html/. Version 0.8.1.RELEASE, 2020-
02-04.
54