[xSocket-develop] Memory problems while using xSocket as a server
Status: Inactive
Brought to you by:
grro
|
From: Kasper G. <kaw...@gm...> - 2010-04-28 14:28:01
|
Hi, im experiencing a possible memoryleak when using xSocket.
I am running with the xSocket(core) with the following version:
Implementation-Version=2.8.12
Implementation-Date=2010-04-19 09:26 MESZ
The amount of memory and live objects is just rising and rising even
with no connections at all. The NetBeans profiler only shows that it
is a HashMap iterator that is using more and more memory.
Try to use the following code (with a profiler that you like, i am
using NetBeans):
import org.xsocket.connection.*;
public class NextServer
{
protected static IServer srv = null;
public static void main(String[] args)
{
try
{
// http://xsocket.sourceforge.net/core/tutorial/V2/TutorialCore.htm
srv = new Server("127.0.0.1", 1338, new xGuestSocketDataHandler());
srv.run();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
protected static void shutdownServer()
{
try
{
srv.close();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
And my xGuestSocketDataHandler that i am using as a connection handler:
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.channels.ClosedChannelException;
import org.xsocket.*;
import org.xsocket.connection.*;
public class xGuestSocketDataHandler implements IDataHandler,
IConnectHandler, IDisconnectHandler
{
public boolean onData(INonBlockingConnection nbc) throws
IOException, BufferUnderflowException, ClosedChannelException,
MaxReadSizeExceededException
{
try
{
String data = nbc.readStringByDelimiter("\r\n");
if(data.trim().length() > 0)
{
System.out.println("Incoming data: " + data);
String[] message = data.split(";");
if(message.length == 2 && message[0].equalsIgnoreCase("auth"))
{
//IHandler newUserHandler = new
xUserSocketDataHandler(message[1],nbc);
//nbc.setHandler(newUserHandler);
}
else if(message[0].equalsIgnoreCase("SHUTDOWN"))
{
NextServer.shutdownServer();
}
else
{
nbc.write("Authentication failed!");
}
}
}
catch(Exception ex)
{
System.out.println("onData: " + ex.getMessage());
}
return true;
}
public boolean onConnect(INonBlockingConnection nbc) throws
IOException, BufferUnderflowException, MaxReadSizeExceededException
{
try
{
nbc.write("K-THXBYE");
System.out.println("onConnect");
}
catch(Exception ex)
{
System.out.println("onConnect: " + ex.getMessage());
}
return true;
}
public boolean onDisconnect(INonBlockingConnection nbc) throws IOException
{
try
{
System.out.println("onDisconnect");
}
catch(Exception ex)
{
System.out.println("onDisconnect: " + ex.getMessage());
}
return true;
}
}
This is when the program is launched:
http://imgur.com/zyDrh.png
And after a couple of minutes (7-8 minutesl):
http://imgur.com/jm1M3.png
When 26 threads connects and writes to the server:
http://imgur.com/tcWfA.png
When the threads disconnects again:
http://imgur.com/boUv0.png (The number of KeyIterators are still rising)
Running after 30-40 minutes:
http://imgur.com/CWPD8.png
I don't believe that i am doing anything wrong. Am I? Is it a bug?
Best regards
--
Kasper Grubbe
Computer Science AP
Phone: (+45) 42 42 42 74
Mail: kas...@gm...
Kettegårds Allè 70,1,6115
2650 Hvidovre
Denmark
|