From b1531d868c64913756a6563d13680c027b0d1270 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 27 Apr 2023 20:02:01 +0200 Subject: [PATCH] Created Improve Performance of PGPainless-CLI with Nailgun (markdown) --- ...formance-of-PGPainless-CLI-with-Nailgun.md | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Improve-Performance-of-PGPainless-CLI-with-Nailgun.md diff --git a/Improve-Performance-of-PGPainless-CLI-with-Nailgun.md b/Improve-Performance-of-PGPainless-CLI-with-Nailgun.md new file mode 100644 index 0000000..dc4fd16 --- /dev/null +++ b/Improve-Performance-of-PGPainless-CLI-with-Nailgun.md @@ -0,0 +1,49 @@ +When executing a short-lived CLI application written in Java, a huge portion of the runtime is wasted on booting the JVM. + +To fix this issue, [nailgun]() can be used: +Nailgun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead. +Programs run in the server (which is implemented in Java), and are triggered by the client (written in C), which handles all I/O. + +To use nailgun to increase the performance of `pgpainless-cli`, the first thing you need is a Java 8 installation. +This is because nailgun uses features from Java 8, which were removed in later releases. + +## Start the nailgun server + +Simply execute the nailgun-server.jar on the Java 8 JVM: + +```shell +$JAVA8_HOME/bin/java -jar nailgun-server.jar +``` + +Next, load the pgpainless-cli-XYZ-all.jar: + +```shell +ng ng-cp /path/to/pgpainless-cli-XYZ-all.jar +``` + +## Execute PGPainlessCLI calls + +The syntax for calling pgpainless-cli only changes a little bit. +Here is an example without and with using nailgun: + +```shell +# WITHOUT nailgun +java -jar pgpainless-cli-XYZ-all.jar generate-key "Alice " + +# WITH nailgun +ng org.pgpainless.cli.PGPainlessCLI generate-key "Alice " +``` + +As you can see, you now need to provide the name of the main class. + +## Results + +On my machine, comparing the performance shows a drastic improvement! + +```shell +$ time (repeat 100 {java -jar pgpainless-cli-1.5.1-all.jar generate-key > /dev/null;}) +( repeat 100; do; java -jar pgpainless-cli-1.5.1-all.jar generate-key > ; done 167,06s user 9,14s system 216% cpu 1:21,42 total +# vs. +$ time (repeat 100 {ng org.pgpainless.cli.PGPainlessCLI generate-key > /dev/null;}) +( repeat 100; do; ng org.pgpainless.cli.PGPainlessCLI generate-key > /dev/nul) 0,21s user 0,99s system 20% cpu 5,914 total +``` \ No newline at end of file