1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-12 03:39:39 +02:00

Updated Improve Performance of PGPainless CLI with Nailgun (markdown)

Paul Schaub 2023-04-27 20:03:33 +02:00
parent b1531d868c
commit 84e250dffb

@ -1,6 +1,6 @@
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:
To fix this issue, [nailgun](https://github.com/facebookarchive/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.
@ -12,13 +12,13 @@ This is because nailgun uses features from Java 8, which were removed in later r
Simply execute the nailgun-server.jar on the Java 8 JVM:
```shell
$JAVA8_HOME/bin/java -jar nailgun-server.jar
$ $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
$ ng ng-cp /path/to/pgpainless-cli-XYZ-all.jar
```
## Execute PGPainlessCLI calls
@ -27,11 +27,11 @@ 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 <alice@example.org>"
$ # WITHOUT nailgun
$ java -jar pgpainless-cli-XYZ-all.jar generate-key "Alice <alice@example.org>"
# WITH nailgun
ng org.pgpainless.cli.PGPainlessCLI generate-key "Alice <alice@example.org>"
$ # WITH nailgun
$ ng org.pgpainless.cli.PGPainlessCLI generate-key "Alice <alice@example.org>"
```
As you can see, you now need to provide the name of the main class.
@ -43,7 +43,7 @@ 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.
$ # 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
```