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

Solaris socket performance is lower than windows

XMLWordPrintable

    • sparc
    • solaris_2.6



      Our AJC member CTC(ITOCHU TECHNO-SCIENCE Corporation) reports
      us a strange phenomenon which happens on Java socket under Solaris and Windows.
      We guess it may be a bug.

      [Background ]
      CTC is planing to develop a 3-tier system using Java socket.
      The structure is as following:
      Clients <-----> Server <-----> Oracle/Sybase

      Before they start the developing, they test a small program to
      measure performances of Java socket under both OS Solaris and Windows.

      They design two patterns which call pattern A (1 client access/ 1 socket create ) and
      pattern B (keep socket) and test them between Solaris and the Windows.

      pattern A: Socket is created once ServerSocket accepts the client's request, and the server
                 will close the socket for every request.

      pattern B: Socket is created when the first request is accepted, and the server will keep
                 the socket until the whole requests end.

      [Phenomenon]
      The following is the results under different environments and patterns A, B.

      The strange phenomenon is "Test One", because the response time of pattern B
      is longer than pattern A.

      #The problem is that the results show Sparc/Solaris is not suitable as a Server site
       for 3-tier structure in this case.

      The test Java sources are attached at the last. Here is the test steps:
      [Step1] Compile the Server.java and Client.java,
      [Step2] java Server &
      [Step3] java Client aaa ----> if you test pattern A
              java Client ----> if you test oattern B
      [Step4] Just view the response time.
              [Step3] will display the time.

      Since I test it one my machine called "speed" as the server site, you should change it to
      your test machine name at the source Client.java.

      (1) Case One
      [Environment]
      Server: Solaris 8, "Solaris_JDK_1.2.1_04c"
      Client: Windows 95, java full version "1.3.0-c"

      [Results]
                  pattern A (1 client access/ 1 socket create ) pattern B case (keep socket)
      test 1 16260 (msec) 101010 (msec)
      test 2 15650 100900
      test 3 14780 100950

      --------------------------------------------------------------------------
      (2) Case Two
      [Environment]
      Server: Solaris 8, Solaris_JDK_1.2.1_04c
      Client: Solaris 8, Solaris_JDK_1.2.1_04c

      [Results]
                  pattern A (1 client access/ 1 socket create ) pattern B case (keep socket)
      test 1 5064 2038
      test 2 4866 2044
      test 3 4898 2065
         
      ---------------------------------------------------------------------------
      (3) Case Three
      [Environment]
      Server: Windows 95, java full version "1.3.0-c"
      Client: Solaris 8, "Solaris_JDK_1.2.1_04c"

      [Results]
                  pattern A (1 client access/ 1 socket create ) pattern B case (keep socket)
      test 1 11396 6216
      test 2 11415 5807
      test 3 11901 5857
      ---------------------------------------------------------------------------


      //Client.java start--------------------------------------------------------------------------------

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

      public class Client {

        private String server = "speed"; // ---> You should change it to your server name.
        private int port = 4567;
        private int timeout = 0;

        // Socket
        private Socket socket;
        private BufferedReader is;
        private BufferedWriter os;

        public Client() {
          try {
            socket = new Socket(server, port);
            os = new BufferedWriter(
      new OutputStreamWriter(socket.getOutputStream()));
            is = new BufferedReader(
      new InputStreamReader(socket.getInputStream()));
            if (timeout > 0)
      socket.setSoTimeout(timeout * 1000);
          } catch (UnknownHostException e) {
            e.printStackTrace();
          } catch (UnknownServiceException e) {
            e.printStackTrace();
          } catch (SocketException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
      // System.out.println("Local Port " + socket.getLocalPort());
        }

        private void close() {
      // System.out.println("Client close()");
          try {
            os.write("close()\n", 0, 8);
            os.flush();
            is.close();
            os.close();
            socket.close();
            is = null;
            os = null;
            socket = null;
          } catch (IOException e) {}
        }

        /*
         * Send command string to server, and receive the data from server.
         * @param sbuff Buffer contain the send data
         * @param rbuff Buffer contain the received data
         * @return status.
         */
        public void send() {
          // Send request to server and receive the return data.
          try {
            String s = "Send request to server.";
            for (int i = 0; i < 100; ++i)
      os.write(s, 0, s.length());
            os.write("\n", 0, 1);
            os.flush();
            String r = is.readLine();
      // System.out.println(r);
          } catch (InterruptedIOException e) {
            System.out.println(e);
          } catch (IOException e) {
            System.out.println(e);
          }
        }

        public static void main(String [] args) {
          int count = 1000;
          Date s1 = new Date();
          if (args.length <= 0) {
            System.out.println("pattern B case (keep socket): count = " + count);
            Client client = new Client();
            for (int i = 0; i < count; ++i) {
      client.send();
            }
            client.close();
          } else {
            System.out.println("pattern A (1 client access/ 1 socket create ): count = " + count);
            for (int i = 0; i < count; ++i) {
      Client client = new Client();
      client.send();
      client.close();
            }
          }
          Date s2 = new Date();
          System.out.println("Time " + String.valueOf(s2.getTime()-s1.getTime()));
        }
      }
      // Client.java end------------------------------------------------------------------------------


      // Server.java start------------------------------------------------------------------------------
      import java.util.Date;
      import java.io.IOException;
      import java.net.*;
      import java.io.*;

      public class Server extends Thread {
        private int id;
        private Socket socket;
        private BufferedReader is;
        private BufferedWriter os;

        public Server(Socket sock, int no) throws IOException {
      // System.out.println("Open server " + no);
          id = no;
          socket = sock;
          is = new BufferedReader(
            new InputStreamReader(socket.getInputStream()));
          os = new BufferedWriter(
      new OutputStreamWriter(socket.getOutputStream()));
      // System.out.println("rec=" + socket.getReceiveBufferSize() +
      // " Send=" + socket.getSendBufferSize());
        }

        /**
         * Run thread
         */
        public void run() {
      // Date t1 = new Date();
      // Date t2 = t1;
          int i = 0;
          for (;;) {
            try {
      ++i;
              Thread.yield();
      String r = is.readLine();
      // System.out.println("ID=" + id + " I=" + i + " Length=" + r.length());
      if ("close()".equals(r))
      break;
      String s = String.valueOf(id) + "\n";
      os.write(s, 0, s.length());
      os.flush();
      // Date t3 = new Date();
      // System.out.println("T=" + (t3.getTime()-t2.getTime()));
      // t2 = t3;
            } catch (IOException e) {
      e.printStackTrace();
            }
          }
          try {
            socket.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
      // t2 = new Date();
      // System.out.println("Time=" + (t2.getTime()-t1.getTime()));
       // System.out.println("Server closed " + id);
        } // run

        public static void main(String [] args) {
          try {
            int no = 0;
            int port = 4567;
            ServerSocket server = new ServerSocket(port);
            System.out.println(" Port: " + server.getLocalPort());

            while (true) {
      try {
                Thread.yield();
      Server ss = new Server(server.accept(), no);
      no++;
      ss.start();
      } catch (IOException e) {
      e.printStackTrace();
      }
            }
          } catch (IOException e) {
            e.printStackTrace();
          }
        }

      } // class Server
      // Server.java end------------------------------------------------------------------------------

            alanb Alan Bateman
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: