5 Replies Latest reply: Jun 28, 2012 6:52 AM by EJP RSS

    Performance Issue in NetworkInterface.getNetworkInterface in windows JRE 7

    945046
      NetworkInterface.getNetworkInterface() call takes 10 times more time when run in Windows JRE 7. The same call runs much faster in JRE 6.

      Sample Program,
      I wrote a small program which just fetches the network interfaces using java.net.NetworkInterface.getNetworkInterfaces() as below,

      ------------------------------------ Program Start ------------------------------------
      import java.net.*;
      import java.util.*;

      public class PerfNetTest {

      public static void main(String args[]) throws Exception {
           long startTime = System.currentTimeMillis();     
           Enumeration niEnum = NetworkInterface.getNetworkInterfaces();          
           long endTime = System.currentTimeMillis();     
           System.out.println ( "Total Time Taken For One Call: " + (endTime-startTime));          
           
           startTime = System.currentTimeMillis();          
           for (int i = 0; i < 10; i++) {
                niEnum = NetworkInterface.getNetworkInterfaces();
           }
           endTime = System.currentTimeMillis();     
           System.out.println ( "Total Time Taken For Ten Call: " + (endTime-startTime));          
      }     
      }
      ------------------------------------ Program End ------------------------------------

      Compiled the above code in Java 6 and ran the above program in JRE 6 and JRE 7. JRE 7 takes approximately 10 times more time than JRE 6. This leads to a huge performance issue in our project.

      I ran it 5 times in each JRE versions and below are the test results,

      When run in JRE 6

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 18
      Total Time Taken For Ten Call: 81

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 17
      Total Time Taken For Ten Call: 80

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 19
      Total Time Taken For Ten Call: 80

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 18
      Total Time Taken For Ten Call: 79

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 18
      Total Time Taken For Ten Call: 80
      -------

      When run in JRE 7

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 98
      Total Time Taken For Ten Call: 891

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 100
      Total Time Taken For Ten Call: 869

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 98
      Total Time Taken For Ten Call: 859

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 99
      Total Time Taken For Ten Call: 871

      c:\test\net>java PerfNetTest
      Total Time Taken For One Call: 99
      Total Time Taken For Ten Call: 888

      --------
      Is there any other way to optimize the performance in JRE 7 internally, Can the above issue considered as a bug with Windows JRE 7? Can I go and submit a bug for this?
        • 1. Re: Performance Issue in NetworkInterface.getNetworkInterface in windows JRE 7
          EJP
          Why exactly do you care whether it takes 18ms or 98ms to call this method? How often are you going to call it? and how does the missing 80ms compare with the total execution time of your program, and the time it spends waiting on the network whose interfaces you are interrogating here?
          • 2. Re: Performance Issue in NetworkInterface.getNetworkInterface in windows JRE 7
            gimbal2
            <broken record mode>
            What if you force IPv4? Does that make a difference?

            -Djava.net.preferIPv4Stack=true
            </broken record mode>


            (of course EJP's post is more relevant)
            • 3. Re: Performance Issue in NetworkInterface.getNetworkInterface in windows JRE 7
              945046
              I have simplified the program to point out the exact issue. In the actual usage we need to know immediately or whenever there is an ip change, it might be because of the change in ip to same nic card or when connected to a network via any of the nic card (wifi enabled, etc).

              Overall it is particularly important to as we used to get the NetworkInterfaces for every features. As a result of this, 60 feature which gets executed roughly around .5 milliseconds in java6, now consumes almost 6-10 seconds in java 7.

              Also in our client server application, where client queries for NetworkInterfaces and further sends a requests to the server where we have to support at least 100 transaction per seconds(TPS for complete client-server throughput), with 100's of client systems querying for its own NetworkInterface is consuming time and certainly reduces the overall throughput.

              Currently I am more inclined to cache it and refresh in a separate thread internally, but certainly I wanted to avoid it because the throughput will be less for the first request and especially when it works perfectly fine with java6.

              Edited by: Niran on Jun 28, 2012 3:08 AM
              • 4. Re: Performance Issue in NetworkInterface.getNetworkInterface in windows JRE 7
                945046
                Thanks for your suggestion,

                Unfortunately we need to know both IPv4and IPv6 address.

                However, I have tried with different options for java.net.preferIPv4Stack, java.net.preferIPv6Addresses, networkaddress.cache.ttl, networkaddress.cache.negative.ttl unfortunately none of them improve the performance.
                • 5. Re: Performance Issue in NetworkInterface.getNetworkInterface in windows JRE 7
                  EJP
                  Thanks for the extra details but you still haven't told us why you need to know when your IP address changes. Listening at all interfaces is the usual solution to this problem: why doesn't it apply in your case?