Browse Source

OfficeFloor raw sql client (#6854)

* Removing Rapidoid as seems dead project (no commit last year)

* Downloading from SourceForge

* Bump maven-compiler-plugin in /frameworks/Java/officefloor/src

Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.8.0 to 3.8.1.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.8.0...maven-compiler-plugin-3.8.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump maven-shade-plugin in /frameworks/Java/officefloor/src

Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.1...maven-shade-plugin-3.2.2)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Fixing Raw OfficeFloor

* Specifying Spring plugin version

* Bump to OfficeFloor 3.21.0

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.2.4.RELEASE to 2.2.5.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.2.4.RELEASE...v2.2.5.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.2.5.RELEASE to 2.2.6.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.2.5.RELEASE...v2.2.6.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.21.0 to 3.22.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump maven-shade-plugin in /frameworks/Java/officefloor/src

Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.2...maven-shade-plugin-3.2.3)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.22.0 to 3.23.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.23.0 to 3.24.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.2.6.RELEASE to 2.2.7.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.2.6.RELEASE...v2.2.7.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.2.7.RELEASE to 2.3.0.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.2.7.RELEASE...v2.3.0.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.24.0 to 3.25.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump maven-shade-plugin in /frameworks/Java/officefloor/src

Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.3 to 3.2.4.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.3...maven-shade-plugin-3.2.4)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.3.0.RELEASE to 2.3.1.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.3.0.RELEASE...v2.3.1.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.3.1.RELEASE to 2.3.2.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.3.1.RELEASE...v2.3.2.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.25.0 to 3.26.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/compare/release-3.25.0...release-3.26.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.3.2.RELEASE to 2.3.3.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.3.2.RELEASE...v2.3.3.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.26.0 to 3.27.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.3.3.RELEASE to 2.3.4.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.3.3.RELEASE...v2.3.4.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.27.0 to 3.28.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Fixing to run with v3.28.0

* Including Undertow

* Using slim docker images

* Fixing to add all supported tests

* Increasing connection pool size

* Write up the 503 errors and why

* Fix grammer

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.3.4.RELEASE to 2.3.5.RELEASE.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.3.4.RELEASE...v2.3.5.RELEASE)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Improving chances of full processing

Increasing max thread counts to have thread per client.  Also, shading
jars correctly.

Plus adding in DB test for raw

* Fixing raw test to have database

* Ensure random numbers to avoid cached entities

* Ensuring spring random numbers to avoid entity caching

* Adding queries for raw

* officefloor-raw queries passing

* office-raw supporting all requests

* Fixed update test to ensure updates occur before responding

* Adding officefloor-async

This will demonstrate OfficeFloor running as a single thread
asynchronous server

* Upgrading to OfficeFloor 2.38.1

* Tidy up read me

* Appropriate back pressure queue

* Handle rate limiting

* Providing appropriate throttling

* Lowering threading to handle through put

* officefloor-raw passing tests

* Passing tests

* OfficeFloor 3.28.2

* Fixing rate limiting

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.28.2 to 3.29.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Fixing for bump to 3.30.0

* Increasing max direct memory

* Increasing threshold to enable verifications to pass for officefloor-raw

* Start script to take available memory into consideration

* Max direct memory aware of available memory

Also, cleaning writer threads of buffers to avoid leaks.

* Avoiding OOM by managing disable/enable reading

* DB and Fortune passing

* Ensuring free command is available

* Removing TODOs

* Increasing reactor buffer for multiple queries

* Fixing for 3.30.1

* Passing benchmark tests

* Avoiding OOM on reactor buffer sizes

* Passing validate tests

* Using defaults from 3.30.1

* Bump to 512 threads and connections

* Reverting dockerfiles to provide appropriate parameters

* openjdk:slim for apt-get available

* Providing thread affinity to raw

* Fixing rate limit throttling

* Multiplexing queries over connections per socket

* Fixing for large queries in validate

* Fixing versions of maven and java

* Providing thread affinity of DB connection thread

* Fixing for Netty event loop thread

* Tidying up compiler warnings

* Single db pool to avoid additional threads

* Use default LoopResources

* Tidying up code for warnings

* Further tidy up of code

* Revert to latest pull request

* Using parallel GC for better throughput

* Fix up for thread local buffering improvements

* OfficeFloor fortune raw

Focus of officefloor-raw is raw performance of the OfficeFloor HTTP
server.  Using raw fortune to remove mustache overheads.

* Tidy up loop

* Server name (as per discussions)

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.3.5.RELEASE to 2.4.2.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.3.5.RELEASE...v2.4.2)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.30.2 to 3.31.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.31.0 to 3.32.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.4.2 to 2.4.3.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.4.2...v2.4.3)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.4.3 to 2.4.5.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.4.3...v2.4.5)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Upgrade to GitHub-native Dependabot

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.32.0 to 3.35.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits/release-3.35.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Bump to OfficeFloor 3.35.0

* Allow bump of all versions

* Vertx server

Also, renaming officefloor-raw to officefloor-r2dbc to make way for
officefloor-sqlclient

* Rename to R2dbc (from raw)

* Bump net.officefloor:bom in /frameworks/Java/officefloor/src

Bumps [net.officefloor:bom](https://github.com/officefloor/OfficeFloor) from 3.35.0 to 3.36.0.
- [Release notes](https://github.com/officefloor/OfficeFloor/releases)
- [Commits](https://github.com/officefloor/OfficeFloor/commits)

Signed-off-by: dependabot[bot] <[email protected]>

* Fixing meta-data

* Can not propagate Dependabot to TechEmpower

* Abstract WoOF from database driver

This will allow introducing Vertx SQL Client

* Fixing db port

* Providing Vertx SQL Client implementation

* Using OfficeFloorVertx for vertx

Allows for tests to reset

* Fixing link in read me

* Reducing repetition in readme

* Swapped OfficeFloor async to use Vertx SQL Client

* Bump spring-boot-maven-plugin in /frameworks/Java/officefloor/src

Bumps [spring-boot-maven-plugin](https://github.com/spring-projects/spring-boot) from 2.4.5 to 2.5.0.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v2.4.5...v2.5.0)

Signed-off-by: dependabot[bot] <[email protected]>

* Increasing SQL Client pool size to 512

Also, fixing update to sort to avoid deadlocks

* Removing unnecessary logging

* Removing dependabot configuration

* Improving performance of Vertx

This is by caching queries and using native communication.

Also, adding further performance updates to update test by sorting
updates

* Fixing OfficeFloor-vertx name

* Reducing load on DB callback threads

* Database worker threads relative to number of socket threads

* Further improvements to performance (by less contention)

* Avoid lock on write stream

* Using Guava

* Removing commented out line

* Providing Cache implementation

* Re-enabling thread affinity

* Making R2DBC more resilient

* Adding cached query configuration entries

* Caching runs off World table

* Only require World able

* Should be all I/O for SQLClient

* Reducing event loops for SQL connections

* Providing thread affinity on sql callbacks

* Removing unnecessary if

* Bump OfficeFloor to 3.38.0

* Improving latency for request/response over database connections

* Disable Nagle

* Providing tuned connection pooling

* Reduce number of connections

* Comparing Postgres rule of thumb

Trying out https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing

connections = ((core_count * 2) + effective_spindle_count)

* Merge branch 'master' of
[email protected]:TechEmpower/FrameworkBenchmarks.git

* Fixing classpath for Postgresql

* Providing lower layer driver without synchronise of Vertx promises

* Including raw SQL client

* Raw SQL client passing verify

* Fixing display name

* Optimising update

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Daniel 3 years ago
parent
commit
471d82aa0c

+ 22 - 0
frameworks/Java/officefloor/benchmark_config.json

@@ -71,6 +71,28 @@
 				"display_name": "OfficeFloor-sqlclient",
 				"notes": ""
 			},
+			"rawsqlclient": {
+				"json_url": "/json",
+				"plaintext_url": "/plaintext",
+				"db_url": "/db",
+				"query_url": "/queries?queries=",
+				"fortune_url": "/fortunes",
+				"update_url": "/update?queries=",
+				"port": 8080,
+				"approach": "Realistic",
+				"classification": "Platform",
+				"database": "Postgres",
+				"framework": "OfficeFloor",
+				"language": "Java",
+				"flavor": "None",
+				"orm": "raw",
+				"platform": "OfficeFloor",
+				"webserver": "WoOF",
+				"os": "Linux",
+				"database_os": "Linux",
+				"display_name": "OfficeFloor-rawsqlclient",
+				"notes": ""
+			},
 			"async": {
 				"json_url": "/json",
 				"plaintext_url": "/plaintext",

+ 17 - 0
frameworks/Java/officefloor/config.toml

@@ -108,6 +108,23 @@ platform = "OfficeFloor"
 webserver = "WoOF"
 versus = "None"
 
+[rawsqlclient]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+urls.db = "/db"
+urls.query = "/queries?queries="
+urls.update = "/update?queries="
+urls.fortune = "/fortunes"
+approach = "Realistic"
+classification = "Platform"
+database = "Postgres"
+database_os = "Linux"
+os = "Linux"
+orm = "raw"
+platform = "OfficeFloor"
+webserver = "WoOF"
+versus = "None"
+
 [undertow]
 urls.plaintext = "/plaintext"
 urls.json = "/json"

+ 16 - 0
frameworks/Java/officefloor/officefloor-rawsqlclient.dockerfile

@@ -0,0 +1,16 @@
+FROM maven:3.6.3 as maven
+WORKDIR /officefloor
+COPY src src
+WORKDIR /officefloor/src
+RUN mvn -B -N clean install
+WORKDIR /officefloor/src/woof_benchmark_woof
+RUN mvn -B clean install
+WORKDIR /officefloor/src/woof_benchmark_rawsqlclient
+RUN mvn -B clean package
+
+FROM openjdk:15-slim
+RUN apt-get update && apt-get install -y libjna-java
+WORKDIR /officefloor
+COPY --from=maven /officefloor/src/woof_benchmark_rawsqlclient/target/woof_benchmark_rawsqlclient-1.0.0.jar server.jar
+EXPOSE 8080
+CMD ["java", "-Xms2g", "-Xmx2g", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-Dvertx.disableMetrics=true", "-Dvertx.threadChecks=false", "-Dvertx.disableContextTimings=true", "-Dvertx.disableTCCL=true", "-jar", "server.jar"]

+ 9 - 0
frameworks/Java/officefloor/src/pom.xml

@@ -20,6 +20,7 @@
 		<module>woof_benchmark_async</module>
 		<module>woof_benchmark_r2dbc</module>
 		<module>woof_benchmark_sqlclient</module>
+		<module>woof_benchmark_rawsqlclient</module>
 		<module>woof_benchmark_netty</module>
 		<module>woof_benchmark_undertow</module>
 		<module>woof_benchmark_vertx</module>
@@ -71,6 +72,14 @@
 				<artifactId>guava</artifactId>
 				<version>29.0-jre</version>
 			</dependency>
+
+			<!-- Necessary for PostGresql -->
+			<dependency>
+				<groupId>com.ongres.scram</groupId>
+				<artifactId>client</artifactId>
+				<version>2.1</version>
+			</dependency>
+
 		</dependencies>
 	</dependencyManagement>
 	<build>

+ 8 - 1
frameworks/Java/officefloor/src/woof_benchmark_async/pom.xml

@@ -30,6 +30,13 @@
 			<artifactId>lombok</artifactId>
 			<scope>provided</scope>
 		</dependency>
+
+		<!-- Necessary for PostGresql -->
+		<dependency>
+			<groupId>com.ongres.scram</groupId>
+			<artifactId>client</artifactId>
+		</dependency>
+
 	</dependencies>
 	<build>
 		<plugins>
@@ -55,4 +62,4 @@
 			</plugin>
 		</plugins>
 	</build>
-</project>
+</project>

+ 56 - 0
frameworks/Java/officefloor/src/woof_benchmark_rawsqlclient/pom.xml

@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>net.officefloor.benchmarks</groupId>
+		<artifactId>benchmarks</artifactId>
+		<version>1.0.0</version>
+	</parent>
+	<artifactId>woof_benchmark_rawsqlclient</artifactId>
+	<dependencies>
+		<dependency>
+			<groupId>net.officefloor.benchmarks</groupId>
+			<artifactId>woof_benchmark_woof</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>net.officefloor.vertx</groupId>
+			<artifactId>officevertx</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>io.vertx</groupId>
+			<artifactId>vertx-pg-client</artifactId>
+		</dependency>
+
+		<!-- Necessary for PostGresql -->
+		<dependency>
+			<groupId>com.ongres.scram</groupId>
+			<artifactId>client</artifactId>
+		</dependency>
+
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-shade-plugin</artifactId>
+				<executions>
+					<execution>
+						<phase>package</phase>
+						<goals>
+							<goal>shade</goal>
+						</goals>
+						<configuration>
+							<transformers>
+								<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+									<mainClass>net.officefloor.benchmark.RawSqlClientOfficeFloorMain</mainClass>
+								</transformer>
+								<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
+							</transformers>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

+ 301 - 0
frameworks/Java/officefloor/src/woof_benchmark_rawsqlclient/src/main/java/net/officefloor/benchmark/RawSqlClientOfficeFloorMain.java

@@ -0,0 +1,301 @@
+package net.officefloor.benchmark;
+
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+
+import io.vertx.core.Future;
+import io.vertx.core.Promise;
+import io.vertx.core.Vertx;
+import io.vertx.core.VertxOptions;
+import io.vertx.core.impl.VertxBuilder;
+import io.vertx.core.impl.VertxThread;
+import io.vertx.core.spi.VertxThreadFactory;
+import io.vertx.pgclient.PgConnectOptions;
+import io.vertx.pgclient.PgConnection;
+import io.vertx.pgclient.impl.PgConnectionImpl;
+import io.vertx.sqlclient.PropertyKind;
+import io.vertx.sqlclient.Row;
+import io.vertx.sqlclient.Tuple;
+import io.vertx.sqlclient.impl.QueryResultHandler;
+import io.vertx.sqlclient.impl.RowDesc;
+import io.vertx.sqlclient.impl.command.CommandScheduler;
+import io.vertx.sqlclient.impl.command.ExtendedQueryCommand;
+import net.officefloor.server.RequestHandler;
+import net.officefloor.server.http.parse.HttpRequestParser;
+import net.officefloor.vertx.OfficeFloorVertx;
+import net.openhft.affinity.Affinity;
+
+/**
+ * R2DBC server.
+ *
+ * @author Daniel Sagenschneider
+ */
+public class RawSqlClientOfficeFloorMain implements DatabaseOperations {
+
+	/**
+	 * Run application.
+	 */
+	public static void main(String[] args) throws Throwable {
+		RawWoof.run(args, (socketCount, server, port, database, username,
+				password) -> new RawSqlClientOfficeFloorMain(socketCount, server, port, database, username, password));
+	}
+
+	/**
+	 * Query executor.
+	 */
+	private static class QueryExecutor implements Promise<Boolean> {
+
+		private final CommandScheduler scheduler;
+
+		private final String[] optimisedUpdates = new String[500];
+
+		private QueryExecutor(CommandScheduler scheduler) {
+			this.scheduler = scheduler;
+		}
+
+		public void execute(String sql, Tuple values, BiConsumer<List<Row>, Throwable> handler) {
+
+			// Create the query
+			ExtendedQueryCommand<List<Row>> query = ExtendedQueryCommand.createQuery(sql, null, values, true,
+					Collectors.toList(), new QueryResultHandler<List<Row>>() {
+
+						@Override
+						public <V> void addProperty(PropertyKind<V> property, V value) {
+							// Not required
+						}
+
+						@Override
+						public void handleResult(int updatedCount, int size, RowDesc desc, List<Row> result,
+								Throwable failure) {
+							handler.accept(result, failure);
+						}
+					});
+
+			// Execute query
+			this.scheduler.schedule(query, this);
+		}
+
+		public String getOptimisedUpdate(World[] worlds) {
+			int count = worlds.length;
+			String updateSql = this.optimisedUpdates[count - 1];
+			if (updateSql == null) {
+
+				// Build the SQL
+				StringBuilder sql = new StringBuilder();
+				sql.append("UPDATE WORLD SET RANDOMNUMBER = CASE ID");
+				for (int i = 0; i < count; i++) {
+					int offset = (i * 2) + 1;
+					sql.append(" WHEN $" + offset + " THEN $" + (offset + 1));
+				}
+				sql.append(" ELSE RANDOMNUMBER");
+				sql.append(" END WHERE ID IN ($1");
+				for (int i = 1; i < count; i++) {
+					int offset = (i * 2) + 1;
+					sql.append(",$" + offset);
+				}
+				sql.append(")");
+				updateSql = sql.toString();
+
+				// Cache
+				this.optimisedUpdates[count - 1] = updateSql;
+			}
+			return updateSql;
+		}
+
+		/*
+		 * =============== Promise ==================
+		 */
+
+		@Override
+		public boolean tryComplete(Boolean result) {
+			return true;
+		}
+
+		@Override
+		public boolean tryFail(Throwable cause) {
+			return true;
+		}
+
+		@Override
+		public Future<Boolean> future() {
+			return null;
+		}
+	}
+
+	/**
+	 * {@link ThreadLocal} {@link QueryExecutor} instances.
+	 */
+	private final ThreadLocal<QueryExecutor> threadLocalQueryExecutor;
+
+	/**
+	 * Instantiate.
+	 *
+	 * @param socketCount Number of server {@link Socket} instances.
+	 * @param server      Name of database server.
+	 * @param port        Port of database.
+	 * @param database    Name of database within server.
+	 * @param username    Username.
+	 * @param password    Password.
+	 */
+	public RawSqlClientOfficeFloorMain(int socketCount, String server, int port, String database, String username,
+			String password) {
+
+		// Should be all I/O processing for SQL responses
+		System.setProperty("vertx.nettyIORatio", "100");
+
+		// Create connection
+		PgConnectOptions connectOptions = new PgConnectOptions().setHost(server).setPort(port).setDatabase(database)
+				.setUser(username).setPassword(password).setCachePreparedStatements(true).setTcpNoDelay(true)
+				.setTcpQuickAck(true);
+
+		// Provide connection
+		this.threadLocalQueryExecutor = new ThreadLocal<QueryExecutor>() {
+			@Override
+			protected QueryExecutor initialValue() {
+				try {
+					// Obtain thread affinity
+					BitSet affinity = Affinity.getAffinity();
+					System.out.println(Thread.currentThread().getName() + " has affinity " + affinity);
+
+					// Setup Vertx for connection
+					VertxOptions options = new VertxOptions().setPreferNativeTransport(true).setEventLoopPoolSize(1)
+							.setWorkerPoolSize(1).setInternalBlockingPoolSize(1);
+					VertxBuilder builder = new VertxBuilder(options).threadFactory(new VertxThreadFactory() {
+						@Override
+						public VertxThread newVertxThread(Runnable target, String name, boolean worker,
+								long maxExecTime, TimeUnit maxExecTimeUnit) {
+							return VertxThreadFactory.INSTANCE.newVertxThread(() -> {
+								Affinity.setAffinity(affinity);
+								target.run();
+							}, name, worker, maxExecTime, maxExecTimeUnit);
+						}
+					});
+					Vertx vertx = builder.init().vertx();
+
+					// Obtain the connection
+					PgConnection connection = OfficeFloorVertx.block(PgConnection.connect(vertx, connectOptions));
+					PgConnectionImpl connectionImpl = (PgConnectionImpl) connection;
+
+					// Return the query executor
+					return new QueryExecutor(connectionImpl);
+				} catch (Exception ex) {
+					throw new IllegalStateException("Failed to setup connection", ex);
+				}
+			}
+		};
+	}
+
+	/*
+	 * ===================== DatabaseOperations ======================
+	 */
+
+	@Override
+	public void threadSetup(RequestHandler<HttpRequestParser> requestHandler) {
+		// Nothing thread specific to set up
+	}
+
+	@Override
+	public void db(DbSendResponse sender) {
+		threadLocalQueryExecutor.get().execute("SELECT ID, RANDOMNUMBER FROM WORLD WHERE ID=$1",
+				Tuple.of(ThreadLocalRandom.current().nextInt(1, 10001)), (result, failure) -> {
+					if (failure != null) {
+						sender.sendError(failure);
+						return;
+					}
+					Row row = result.get(0);
+					sender.sendDb(new World(row.getInteger(0), row.getInteger(1)));
+				});
+	}
+
+	@Override
+	public void queries(int queryCount, QueriesSendResponse sender) {
+		QueryExecutor executor = threadLocalQueryExecutor.get();
+		World[] worlds = new World[queryCount];
+		AtomicInteger index = new AtomicInteger();
+		BiConsumer<List<Row>, Throwable> handler = (result, failure) -> {
+			if (failure != null) {
+				sender.sendError(failure);
+				return;
+			}
+			int lastIndex = -1;
+			for (Row row : result) {
+				lastIndex = index.getAndIncrement();
+				worlds[lastIndex] = new World(row.getInteger(0), row.getInteger(1));
+			}
+			if ((lastIndex + 1) >= queryCount) {
+				sender.sendQueries(worlds);
+			}
+		};
+		for (int i = 0; i < queryCount; i++) {
+			executor.execute("SELECT ID, RANDOMNUMBER FROM WORLD WHERE ID=$1",
+					Tuple.of(ThreadLocalRandom.current().nextInt(1, 10001)), handler);
+		}
+	}
+
+	@Override
+	public void fortunes(FortunesSendResponse sender) {
+		threadLocalQueryExecutor.get().execute("SELECT ID, MESSAGE FROM FORTUNE", Tuple.tuple(), (result, failure) -> {
+			if (failure != null) {
+				sender.sendError(failure);
+				return;
+			}
+			List<Fortune> fortunes = new ArrayList<>(16);
+			for (Row row : result) {
+				fortunes.add(new Fortune(row.getInteger(0), row.getString(1)));
+			}
+			sender.sendFortunes(fortunes);
+		});
+	}
+
+	@Override
+	public void update(int queryCount, UpdateSendResponse sender) {
+		QueryExecutor executor = threadLocalQueryExecutor.get();
+		World[] worlds = new World[queryCount];
+		BiConsumer<List<Row>, Throwable> sendHandler = (result, failure) -> {
+			if (failure != null) {
+				sender.sendError(failure);
+				return;
+			}
+			sender.sendUpdate(worlds);
+		};
+		AtomicInteger index = new AtomicInteger();
+		String optimisedUpate = executor.getOptimisedUpdate(worlds);
+		BiConsumer<List<Row>, Throwable> selectHandler = (result, failure) -> {
+			if (failure != null) {
+				sender.sendError(failure);
+				return;
+			}
+			int lastIndex = -1;
+			for (Row row : result) {
+				lastIndex = index.getAndIncrement();
+				worlds[lastIndex] = new World(row.getInteger(0), ThreadLocalRandom.current().nextInt(1, 10001));
+			}
+			if ((lastIndex + 1) >= queryCount) {
+				List<Integer> params = new ArrayList<>(queryCount * 2);
+				for (int i = 0; i < worlds.length; i++) {
+					World world = worlds[i];
+					params.add(world.id);
+					params.add(world.randomNumber);
+				}
+				executor.execute(optimisedUpate, Tuple.wrap(params), sendHandler);
+			}
+		};
+		for (int i = 0; i < queryCount; i++) {
+			executor.execute("SELECT ID, RANDOMNUMBER FROM WORLD WHERE ID=$1",
+					Tuple.of(ThreadLocalRandom.current().nextInt(1, 10001)), selectHandler);
+		}
+	}
+
+	@Override
+	public void cached(int updateCount, CachedSendResponse sender) {
+		throw new UnsupportedOperationException("/cached-worlds test not supported");
+	}
+
+}

+ 7 - 0
frameworks/Java/officefloor/src/woof_benchmark_sqlclient/pom.xml

@@ -21,6 +21,13 @@
 			<groupId>io.vertx</groupId>
 			<artifactId>vertx-pg-client</artifactId>
 		</dependency>
+
+		<!-- Necessary for PostGresql -->
+		<dependency>
+			<groupId>com.ongres.scram</groupId>
+			<artifactId>client</artifactId>
+		</dependency>
+
 	</dependencies>
 	<build>
 		<plugins>