memory creeps up

Christian Migowski chrismfwrd at gmail.com
Mon Jun 28 10:27:26 EDT 2010


Hi,

a quite general remark, sorry if it isn't useful for you:

Did you already get OutOfMemoryExceptions or not? Otherwise there may
be no problem, for performance reasons, the Java garbage collection
reclaims memory back only when it needs to (i.e. when there is no more
free memory left in the JVM).
If the JVM is taking too much memory, you can try to limit it via
command line option like -Xmx for the Sun JVM)

regards,
christian!

On Mon, Jun 28, 2010 at 4:02 PM, vasion <momchilrogelov at gmail.com> wrote:
>
> I have implemented a very small and simple socket server which takes xml
> messages and if the message is from the local server, it is sent to
> everybody else. It works, but memory crept up to 32% of 512MB with only one
> user connected. When i started it, it used up 16%. i close the channels on
> disconnect, so i have no idea what i am doing wrong.
>
> Handler
>
>
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import java.net.InetSocketAddress;
> import org.jboss.netty.channel.ChannelStateEvent;
> import org.jboss.netty.buffer.ChannelBuffer;
> import org.jboss.netty.channel.ChannelHandlerContext;
> import org.jboss.netty.channel.ChannelPipelineCoverage;
> import org.jboss.netty.channel.ExceptionEvent;
> import org.jboss.netty.channel.MessageEvent;
> import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
> import org.jboss.netty.channel.group.ChannelGroup;
> import org.jboss.netty.channel.group.DefaultChannelGroup;
> /**
>
> *handler for RadioPopuliServer
>
>  *
>  **/
>
> @ChannelPipelineCoverage("all")
>
> public class RadioPopuliHandler extends SimpleChannelUpstreamHandler {
>
>        private static final Logger logger =
> Logger.getLogger(RadioPopuliHandler.class.getName());
>        public ChannelGroup allchannels = new DefaultChannelGroup();
>        private InetSocketAddress address;
>        private String msg;
>        private ChannelBuffer chanbuf;
>
> @Override
>        public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
> throws Exception {
>                    allchannels.add(e.getChannel());
>                        }
>
>
> @Override
>    public void messageReceived(
>            ChannelHandlerContext ctx, MessageEvent e) {
>        // Send back the received message to the remote peer
>
>                //
>
>                address = (InetSocketAddress)(e.getRemoteAddress());
>                if(address.getAddress().isLoopbackAddress()){
>                    allchannels.write(e.getMessage());
>                }
>    }
>
>
>
> @Override
>    public void exceptionCaught(
>            ChannelHandlerContext ctx, ExceptionEvent e) {
>        // Close the connection when an exception is raised.
>        logger.log(
>                Level.WARNING,
>                "Unexpected exception from downstream.",
>                e.getCause());
>        e.getChannel().close();
>
>    }
>
> @Override
>    public void channelDisconnected(ChannelHandlerContext ctx,
> ChannelStateEvent e){
>        allchannels.remove(e.getChannel());
>    }
>
> }
>
> Server
>
> import java.net.InetSocketAddress;
> import java.util.concurrent.Executors;
>
> import org.jboss.netty.bootstrap.ServerBootstrap;
> import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
>
>
>
> public class RadioPopuliServer {
>      public static void main(String[] args) throws Exception {
>        // Configure the server.
>          ServerBootstrap bootstrap = new ServerBootstrap(
>                new NioServerSocketChannelFactory(
>                        Executors.newCachedThreadPool(),
>                        Executors.newCachedThreadPool()));
>  // Set up the default event pipeline.
>
>
>        RadioPopuliHandler handler = new RadioPopuliHandler();
>
>
>
>        bootstrap.getPipeline().addLast("handler", handler);
> // Bind and start to accept incoming connections.
>
>        bootstrap.bind(new InetSocketAddress(8080));
>    }
> }
>
>
>
>
>
> --
> View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/memory-creeps-up-tp5230889p5230889.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>



More information about the netty-users mailing list