“This article has participated in the call for good writing activities, click to view: the back end, the big front end double track submission, 20,000 yuan prize pool waiting for you to challenge!”

Previous performance tests were run on JVMS (see Quarkus Insert&Select database performance), how is Quarkus Native performing?

In fact, there is also a corresponding introduction on the official website, as shown in the screenshot below. As practitioners, we try on this machine whether it really smells good.

Install the GraalVM environment

Installing GraalVM on a Mac platform is relatively easy. On the command line, type the following command:

brew install --cask graalvm/tap/graalvm-ce-lts-java8
Copy the code

Wait until the installation is completeGraalVM installed in the native path

/ Library/Java/JavaVirtualMachines/graalvm - ce - LTS - java8-20.3.1 / Contents/HomeCopy the code

If you have multiple JVM applications of the same version installed on your machine, you can view them using the following command

# meng @ Mbp in /usr/local/Caskroom [10:24:25] $ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.0_292, x86_64:	"AdoptOpenJDK 8"/ Library/Java/JavaVirtualMachines/adoptopenjdk - 8. The JDK/Contents/Home 1.8.0 comes with _282 + 7, x86_64:"GraalVM CE 20.3.1"/ Library/Java/JavaVirtualMachines/graalvm - ce - LTS - java8-20.3.1 / Contents/Home /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/HomeCopy the code

We load the installed GraalVM into our command line

vim ~/.bash_profile
Copy the code

Add the configuration to the file ~/.bash_profile

exportGRAALVM_HOME = / Library/Java/JavaVirtualMachines/graalvm - ce - LTS - java8-20.3.1 / Contents/Homeexport PATH=$GRAALVM_HOME/bin:$PATH
Copy the code

After disabling the ~/. Bash_profile file editing, run the command to make the configuration take effect

source ~/.bash_profile
Copy the code

At this time, we can use the bin provided by GraalVM to install image-native

gu install native-image 
Copy the code

Package Native

​

If using Maven, type it under the project path

./mvnw package -Pnative
Copy the code

If it is Gradle, type it under the project path

./gradlew build -Dquarkus.package.type=native
Copy the code

Success will be notified when packaging is completeAnd in thetargetThe packaged folder will appear under thenativeThe package. nativeThe package size is about 66MB.Use terminal commands to start the service.

$. / target/quarkus1-1.0.0 - the SNAPSHOT - runner __ ____ ____ _____ _____ ____ _____ ______ - / __ / / / / / _ | / _ \ / / / _ / / / / __ / - / / _ _ - / / / / / __ | /, _ /, / / __ / / \ \ - \ _ \ _ \ ____ _ / | _ / _ / | _ / _ / _ - | | \ _____ / ___ / 2021-07-09 10:45:58, 352 INFO [org.hib.rea.pro.imp.ReactiveIntegrator] (main) HRX000001: Hibernate Reactive Preview The 10:45:58 2021-07-09, 361 INFO [org. MXX. Con. Lif. ApplicationLifecycle] (main), The application is  starting... 2021-07-09 10:45:58,363 INFO [IO. Quarkus] (main) Quarkus1 1.0 native (powered by Quarkus 1.13.4.final) startedin0.031 s. Listening on: http://0.0.0.0:8080 2021-07-09 10:45:58,363 INFO [io.quarkus] (main) Profile Prod Activated. 2021-07-09 10:45:58,363 INFO [io.quarkus] (main) Installed features: [cdi, hibernate-orm, hibernate-reactive, hibernate-reactive-panache, mutiny, reactive-mysql-client, reactive-pg-client, smallrye-context-propagation, smallrye-metrics, smallrye-openapi, vertx, vertx-web]Copy the code

It was a quick boot up, taking 0.031 seconds (31ms) and 2.251 seconds in JVM mode

Performance test comparison

This machine uses MacBook Pro (15-inch, 2017), 10.13 operating system. Some problems occurred with the latest Big Sur operating system before, so it was restored to High Sierra

Unit testing

The test interface is relatively simple, returning the string hello4, quarkus. Quarkus version 1.13.4.final.

	@Route(path = "/hello4", methods = HttpMethod.GET)
    Uni<String> hello4(RoutingContext context) {
        return Uni.createFrom().item("hello4, quarkus");
    }
Copy the code

The JVM model

CPU& memory metrics at startupPressure test results

$WRK c50 - d20s http://127.0.0.1:8080/hello4 -- latenc Running 20 stest50 connections @ http://127.0.0.1:8080/hello4 2 threads and Thread Stats Avg Stdev Max + / - Stdev Latency 1.97 ms 5.44 ms 109.63ms 94.93%REq /Sec 25.76k 7.32k 47.85k 64.25% Latency Distribution 50% 663.00us 75% 1.36ms 90% 3.02ms 99% 28.91ms 1025903 requestsin20.04 s, 97.84 MBread
Requests/sec:  51192.58
Transfer/sec:      4.88MB
Copy the code

CPU and memory specifications during pressure measurement

Native mode

Memory and CPU metrics at startupPressure test results

$WRK c50 - d20s http://127.0.0.1:8080/hello4 -- latency Running 20 stest50 connections @ http://127.0.0.1:8080/hello4 2 threads and Thread Stats Avg Stdev Max + / - Stdev Latency 0.91 ms 1.67 ms 43.22 ms 92.54% the Req/Sec 37.78 k, 12.34 k, 69.22 k 65.50% Latency Distribution 340.00 us 50% 99% 75% 90% 2.17 0.90 ms ms 7.68 ms 1509395 requestsin20.09 s, 143.95 MBread
Requests/sec:  75119.42
Transfer/sec:      7.16MB
Copy the code

CPU and memory specifications during pressure measurement

gossip

Using Native has advantages over the JVM model in resource utilization.

The JVM model Native mode note
The startup time 2.251 s 0.031 s The shorter the time, the better
QPS 51192.58 75119.42 The higher the QPS, the better
Mean response time 1.97 ms 0.91 ms The shorter the response time, the better
Response time variance 94.93% 92.54% The smaller the variance, the more stable it is
Response time 99% 28.91 ms 7.68 ms The shorter the response time, the better
Memory (memory at startup) 338M 13M Less memory footprint means less resources
Memory (memory during pressure measurement) 1162M 273M Less memory footprint means less resources

Based on the comparison of the above basic indicators, using Native mode to deploy will save more resources and provide better performance.