12 November 2018

[FIXED] Java MacOS Hostname

During the development of Caltic, there is a strange from internal logger of Vert.x (our toolkit to build Caltic Systems). There're some warning log indicate something happen abnormally. See below:
[INFO] Nov 08, 2018 5:24:50 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Watched paths: [/Users/myrepublic/devel/caltic/caltic-train/target/classes]
[INFO] Nov 08, 2018 5:24:50 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Starting the vert.x application in redeploy mode
[INFO] Starting vert.x application...
[INFO] 18b3e3d3-043d-4f63-b8aa-52d018554b6a-redeploy
[INFO] Nov 08, 2018 5:24:53 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 2858 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:54 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 3859 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:55 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4863 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:58 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 2520 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:59 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 3524 ms, time limit is 2000
[INFO] Nov 08, 2018 5:25:00 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 4524 ms, time limit is 2000
It was happen when I upgraded MacOS Sierra to MacOS Mojave and along with it also upgraded JDK 1.8_171 to 1.8_181. For several weeks, I think it's not cause serious problem since the logs doesn't appear when the apps deployed to Heroku.
Later when I read Vert.x Core Manual, I carried to actor model and one of them that using actor model is Akka. Yeah, one year ago when I did research on Play Framework, the web framework for Java and Scala, I also found Akka, but I didn't found Akka deeper, when read one by one topic in Play. But now I understand that Play is only one implementation module (Akka Http) from many modules that Akka have, like Akka Actors, Akka Streams, etc. Back to the topic, when I tried the Lagom Framework, the new brand from Lightbend for microservice purpose, I also notified that something happen when starting Http Server. In the warning logs from Lagom, there is an url recommendation to solve this issue, here. Then the investigation is started.
After cloned git repository from the url above and run it on my machine, I got:
~$ java -jar bin/inetTester.jar
Calling the hostname resolution method...
Method called, hostname Heru-MacBook-Pro.local, elapsed time: 5011 (ms)
~$
Wow it's take a time 5 sec to getting the hostname, too long. Based on the url from Lagom logs, the proposed solution is fixed file /etc/hosts. The file should be consists of:
127.0.0.1   localhost Heru-MacBook-Pro.local
::1         localhost Heru-MacBook-Pro.local
The format above is <ip><localhost><hostname>. The hostname is grabbed from inetTester logs above, in my case is Heru-MacBook-Pro.local. Actually I'm using VIM to edit this file, but if you don't familiar with them, you could using echo.
~$ sudo echo "127.0.0.1 localhost Heru-MacBook-Pro.local" > /etc/hosts && sudo echo "::1 localhost Heru-MacBook-Pro.local" >> /etc/hosts
When password is asked, type on the terminal then enter. After you running these command, you could verify with cat command.
~$ cat /etc/host
127.0.0.1   localhost Heru-MacBook-Pro.local
::1         localhost Heru-MacBook-Pro.local
~$
Ok the proposed solution has been run, now time to verify. We can move to inetTester app again, run it:
~$ java -jar bin/inetTester.jar 
Calling the hostname resolution method...
Method called, hostname Heru-MacBook-Pro.local, elapsed time: 8 (ms)
~$
Amazing, you see it? It's only take time 8 mili-sec, so faster than before (5 sec). Now let's try the caltic app.
Vert.x Application Log
No blocked thread anymore. Since the threshold of each event loop from vertx is 2000 ms, so if your code is taken more time to be processed than the threshold, the warning log should be appeared, otherwise. Case Closed!

0 comments: