Results 1 to 3 of 3
  1. #1
    pagod is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default ServerSocket.accept() using 100%+ CPU

    Hi everyone,

    I'm facing a rather weird problem and I have absolutely no idea what could be causing it and how to solve it, so I'm hoping someone might be able to give me a great idea or even a solution :-)

    Well, as it says in the title, it's about the accept function of the java.net.ServerSocket class. This function (if I'm not mistaken) is supposed to be listening for network requests on a given port. While waiting, it shouldn't be using any resources.

    I've recently received a new Linux server and installed some java server applications that make use of this accept() function (e.g. Apache Xindice, and some of my own as well). These servers always behaved well while waiting for requests. On the new server, however, these programs seem to be fighting for CPU power. I've created the simplest test program with which this behavior may be reproduced:

    Java Code:
    public static void main( String[] args ) {
        java.net.ServerSocket listener = new java.net.ServerSocket( 65535 );
        while( true ) {
            System.out.println( "waiting..." );
            listener.accept();
            System.out.println( "got request" );
        }
    }
    If I run this program on the new server with the following command:
    Java Code:
    java Test
    Then comes the message "waiting...", and when I do send a single request I also get a single message "got request" and then it comes back to "waiting..." -- i.e. it doesn't look like the method is failing for whatever reason and looping like crazy. But in the 'top' utility I get the following entry:
    Java Code:
    PID	USER	PR	NI	VIRT	RES	SHR	S	%CPU	%MEM	TIME+	COMMAND
    19858	pagod	20	0	670m	49m	6860	S	104	1.3	0:09.76	java Test
    One might wonder about the 104%, that's just because the server has a quad-core CPU. If I happen to start several such server processes at the same time, they'll all use between 80 and 110% of the CPU.

    So what could be happening here? It's a brand new quad-core Xeon 2.66GHz computer with 4GB RAM and a SuSE:
    Linux version 2.6.27.45-0.1-default (geeko@buildhost) (gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) ) #1 SMP 2010-02-22 16:49:47 +0100

    I've had to install java myself cos it wasn't there when I got the computer, installed it with zypper and got a package called java-1_6_0-ibm. Calling 'java -version' displays the following:
    Java Code:
    Java(TM) SE Runtime Environment (build pxa6460sr7-20091215_02(SR7))
    IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux amd64-64 jvmxa6460sr7-20091214_49398 (JIT enabled, AOT enabled)
    J9VM - 20091214_049398
    JIT  - r9_20091123_13891
    GC   - 20091111_AA)
    JCL  - 20091202_01
    Does anyone have any idea what the problem could be? I'm starting to think it might be a bug in this implementation cos I really have no other clue... Should I start by completely reinstalling java??

    Thanks in advance for any help one might provide!

    Pagod

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    look here: Tomcat6 on Linux uses 100% CPU whenever ServerSocket is idle - Stack Overflow

    perhaps setting SoTimeout will help you too

  3. #3
    pagod is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default "simply" reinstall java...

    Thx for the reply and the link.

    I wanted to use jstack to take a look at the information it could give me, but it wasn't installed in my JRE and I couldn't find a package. So I decided to simply uninstall the whole JRE and instead install a real JDK... Simply doing that completely solved my problem -- now the same programs that worked quietly on other computers also run without a sound on this new server. So I'm now convinced it was either a bug in the JRE that's made available by SuSE or some kind of dark incompatibility between the JRE and my system. I guess I'll never know

    However, problem solved makes pagod happy :-)

Similar Threads

  1. serversocket listen connection
    By gisler in forum Networking
    Replies: 1
    Last Post: 12-17-2009, 02:57 AM
  2. Replies: 3
    Last Post: 12-10-2009, 03:49 PM
  3. Sending image file over serversocket to browser client
    By maheshsk in forum Web Frameworks
    Replies: 1
    Last Post: 12-10-2009, 02:39 PM
  4. Client Socket Fails to Connect to ServerSocket
    By Sir_Fz in forum Networking
    Replies: 4
    Last Post: 11-03-2009, 07:44 AM
  5. problem with ServerSocket on Linux
    By gabriel in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •