Open rsvoboda opened 3 years ago
Could be related to #16355
@rsvoboda I figured out what is causing this strange behaviour on macOS systems when using Java CLI or starting Java apps in general.
The problem is that for some unknown reason, the following call on the JVM is taking seconds to execute:
java.net.InetAddress.getLocalHost()
It could be solved by adding the hostname that the application will return on your etc hosts file, pointing to 127.0.0.1 like:
$ sudo nano /etc/hosts
127.0.0.1 localhost [your macOS hostname]
::1 localhost [your macOS hostname]
To see your actual hostname, run: $ hostname
I don't know in what JDK versions this problem happens, but I tested on Java LTS versions (11 & 17).
After change hosts file, you can just run Quarkus Fast-Jar and the startup time will be very fast as it should be:
java -jar target/quarkus-app/quarkus-run.jar
In my case it's now just taking 0.553 seconds!!! Before I change the etc/hosts file, the startup was taking about 5 seconds.
If you're curious, you can run the Main class of inetTester.jar to see how much time the call takes to execute:
public static void main(String[] args) throws UnknownHostException {
System.out.printf("Calling the hostname resolution method...%n");
final Instant start = Instant.now();
final String hostName = InetAddress.getLocalHost().getHostName();
final long end = Duration.between(start, Instant.now()).toMillis();
System.out.printf("Method called, hostname %s, elapsed time: %d (ms)%n", hostName, end);
}
Hostname resolution trick is not helping in my case. In the description you can see that I have quick starts with other java programs. I will try to ping some people to see how quick time quarkus --help
is on their systems.
Ah, so I guess I found the trouble, I'm using quarkus app through jbang as described in https://quarkus.io/get-started/ and https://quarkus.io/guides/cli-tooling#installing-the-cli
When I directly invoke java -jar
I have much better times:
java -jar devtools/cli/target/quarkus-cli-999-SNAPSHOT-runner.jar 1.50s user 0.16s system 168% cpu 0.987 total
jbang run devtools/cli/target/quarkus-cli-999-SNAPSHOT-runner.jar 3.90s user 0.42s system 183% cpu 2.356 total
cc @maxandersen
Yes. Two runs of a jvm vs one will have this effect.
I don't see the same big difference though.
What java version are you using ?
Two runs of a jvm - yup, I realized that when looking into the details, was using GraalVM CE 21.3.0 Java11.
The main concern is that the JBang way of using quarkus
is promoted in https://quarkus.io/get-started/
It's also first option in https://quarkus.io/guides/cli-tooling#installing-the-cli
So this way users get a slower experience with CLI than if they use for example SDKMAN! based CLI installation.
correct its slightly slower but it is also way simpler and more reliable to install.
working on making jbang native which should help too and provide java based fallback so still reliable to install. But its not in the cards at the moment.
/cc @ebullient, @maxandersen
Quite slow on WSL2 with Ubuntu 20
time quarkus --help
...
real 0m2.948s
user 0m5.507s
sys 0m0.898s
version 3.5.0
How is it installed ?
@maxandersen JBang
Ok. Try use direct sdk or scoop or choco. That removes one jvm start from that.
Try measure that and see what diff that does for you.
Bit better with sdk, about half:
time quarkus --help
...
real 0m1.387s
user 0m2.978s
sys 0m0.760s
Quarkus CLI has slow(-ish) start, I'm missing the supersonic effect.
I'm using MBP 2019 with JDK 11 and the cli startup feels slow, 2 seconds to get help.
Did also comparison with CLI for Spring Boot and Micronat to get help text and to get version. Micronaut cli is slower than Quarkus cli, but Spring Boot cli is much faster, around 0.6s versus 1.7s. I think Quarkus cli should get under 1 second.
Version:
Help: