Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8057802

Bad performance in InetAddress.getByName() caused by NumberFormatException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7u65
    • core-libs
    • generic
    • generic

      FULL PRODUCT VERSION :
      ava version "1.7.0_65"
      OpenJDK Runtime Environment (IcedTea 2.5.1) (7u65-2.5.1-5~deb7u1)
      OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      InetAddress.getByName() invokes the internal method IPAddressUtil.textToNumericFormatV4(), which uses exceptions as a control structure. Several places in this method attempt to parse strings to integers, but these strings may or may not be numbers actually, so when they are not numbers, a NumberFormatException will be thrown and it will be caught by a catch{} clause that returns null.

      This is a performance nug, because this exception is being thrown too frequently in my app (a real-time bidder that handles 20,000 requests/second; every single of these requests requires at least one of these InetAddress.getByName() calls, there's only a small number of addresses but this happens in a third-party embedded library that I cannot optimize e.g. with a simple cache. Processing of each request is relatively fast so this exception is wasting ~5% of all CPU consumed by my application (after discounting the epoll network layer).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute test code below.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Address resolved but without burning CPU :)
      ACTUAL -
      Address is correctly resolved, but wasting enough CPU to appear near the top of my performance profile.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.net.InetAddress;
      import java.net.UnknownHostException;

      public class InetAddressTester {
        public static void main(String[] args) throws UnknownHostException {
          System.out.println(InetAddress.getByName("::ffff:10.86.252.234"));
        }
      }

      ---------- END SOURCE ----------

            michaelm Michael McMahon
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: