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

fp.bugs 3390 multithread performance is very not good

XMLWordPrintable

    • sparc
    • solaris_2.5

      What comes from using a single kernel thread for all java threads...
      >From: Scott Comer <###@###.###>

      i used the attached code to open a connection to the tcp echo service
      (localhost, port 7) and write 5 bytes of data, and then read back 5
      bytes (and compare it), and then close the connection.

      i wrote the code to try two different approaches: the first creates a
      process to do the above and then waits for it to complete. it does this
      50 times. the second approach creates 50 processes to do the above, and
      doesn't wait for them to complete. either way, when 50 connections have
      been created, written, read, and closed, the program exits (because
      there are no more non-daemon processes).

      the bug is that approach one (50 processes one at a time) takes 9 wall
      seconds, while the second approach takes 2 minutes and 26 seconds of
      wall time.

      per-connection, that's 180 milliseconds vs. 2.92 seconds.

      the code as encloseed executes approach two. to test approach one, find
      the following text: "//fc.join();" and remove the comment characters
      "//" from the front.

      to compile and execute:

      javac MainClient.java
      java MainClient

      seems a little high to me. actually, the 180 milliseconds seems high to
      me.

      scott out

      --------------37E2431FF5D
      Content-Type: text/plain; charset=us-ascii
      Content-Transfer-Encoding: 7bit
      Content-Disposition: inline; filename="MainClient.java"

      import java.net.*;
      import java.io.*;

      class MainClient
      {
      public static void main(String[] args)
      {
      System.out.println("MainClient starting up...");

      try
      {
      InetAddress myAddr = InetAddress.getByName("localhost");

      for (int i = 0; i < 50; i++)
      {
      FooClient fc = new FooClient(myAddr, 7);
      fc.start();
      //fc.join();
      }
      }
      catch (Exception e)
      {
      System.out.println("MainClient exception:");
      System.out.println(e);
      }

      System.out.println("MainClient done.");
      }
      }

      class FooClient extends Thread
      {
      InetAddress fc_address;
      int fc_port;

      public FooClient(InetAddress address, int port)
      {
      fc_address = address;
      fc_port = port;
      }

      public boolean expecting(InputStream input, int b)
      throws IOException
      {
      int a = input.read();

      if (a != b)
      {
      System.out.println(
      this + " got " + a + " but expected " + b + ".");
      return false;
      }

      return true;
      }

      public void run()
      {
      try
      {
      Socket fc_socket = new Socket(fc_address, fc_port);

      OutputStream output = fc_socket.getOutputStream();

      output.write('t');
      output.write('e');
      output.write('s');
      output.write('t');
      output.write('\\n');
      output.flush();

      InputStream input = fc_socket.getInputStream();

      boolean itWorked = expecting(input, 't') &&
      expecting(input, 'e') &&
      expecting(input, 's') &&
      expecting(input, 't') &&
      expecting(input, '\\n');

      fc_socket.close();

      System.out.println(this + " done.");
      }
      catch (Exception e)
      {
      System.out.println(this + " FooClient run exception:");
      System.out.println(e);
      }
      }
      }

      --------------37E2431FF5D--

            tlindholsunw Timothy Lindholm (Inactive)
            bhagen Benjamin Hagen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: