Jvm Takes a Long Time to Resolve Ip-Address for Localhost

Jvm takes a long time to resolve ip-address for localhost

I had the same problem. Tomcat went from 15 seconds to 6 minutes to initialise spring context after the upgrade... disabling csrutils didn't solve the issue for me.

I solved the problem by adding my Mac hostname (i.e. Macbook.local, or whatever your Mac is called) on the /etc/hosts file mapped to the 127.0.0.1 address as well as the ::1 like this:

127.0.0.1   localhost mbpro.local
::1 localhost mbpro.local

If you're interested you can find some details on the issue and solution here:
https://thoeni.io/post/macos-sierra-java/

On the post I also link to a github project to help troubleshooting the issue and validating the solution.

The problem is related (I believe) on how the localhost name resolution works and how the java.net.InetAddr class is retrieving the addresses. I verified with few colleagues and apparently it doesn't happen to everyone who upgraded to Sierra, but I'm still investigating the roots of this change.

The solution anyway was the same that antid0te implemented and worked immediately.

InetAddress.getLocalHost() slow to run (30+ seconds)

The issue can be solved by adding the following to /etc/hosts (assuming output of hostname command is my-macbook:

127.0.0.1   my-macbook
::1 my-macbook

This returns the time to something more suitable (< 1 second)

JMeter - localhost - wait for local server startup completed

  1. Add setUp Thread Group to your Test Plan
  2. Add While Controller to the setUp Thread Group and use the following __groovy() function as the condition:

    ${__groovy(!vars.get('continue').equals('false'),)}
  3. Add HTTP Request sampler to your Test Plan and configure it like:

    Sample Image

    Sample Image

  4. Add JSR223 PostProcessor as a child of the HTTP Request sampler and put the following code into "Script" area:

    if (prev.isSuccessful()) {
    vars.put('continue', 'false')
    }

    Sample Image

  5. That's it, While Controller will loop the HTTP Request sampler until it will be successful which means that your application is up and running.

    Sample Image

How can I specify an IP address besides localhost?

There is a serve variant that takes a SocketAddress. It won't resolve the hostname for you (as it seems to be done with http4s) so you'd need to pass it a resolved address.

Http.server.serve(new java.net.InetSocketAddress("192.168.0.1", 8080), service)

Note that by default, when you simply pass ":8081", the server will listen on all interfaces (including localhost).



Related Topics



Leave a reply



Submit