Hi all,

I have a server program based on mina which provides services to clients and
also acts as a client of other servers. I found that when there're lots of
client come and request a service and go (at a moment, there aren't so many
clients), the CPU load of my program is very high. I profiled my program
through java's agentlib hprof, like this:

$ java -agentlib:hprof=cpu=samples,depth=8 -cp $MyClassPath MyClass

I got the following results:

......................
TRACE 300291:
        sun.nio.ch.PollArrayWrapper.poll0(PollArrayWrapper.java:Unknown
line)
        sun.nio.ch.PollArrayWrapper.poll(PollArrayWrapper.java:100)
        sun.nio.ch.PollSelectorImpl.doSelect(PollSelectorImpl.java:56)
        sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
        sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
       
org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:500)
       
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
       
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
TRACE 300275:
        sun.nio.ch.PollArrayWrapper.poll0(PollArrayWrapper.java:Unknown
line)
        sun.nio.ch.PollArrayWrapper.poll(PollArrayWrapper.java:100)
        sun.nio.ch.PollSelectorImpl.doSelect(PollSelectorImpl.java:56)
        sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
        sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
        sun.nio.ch.SelectorImpl.select(SelectorImpl.java:84)
       
org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.run(SocketAcceptor.java:233)
       
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
TRACE 300468:
        sun.nio.ch.PollArrayWrapper.poll0(PollArrayWrapper.java:Unknown
line)
        sun.nio.ch.PollArrayWrapper.poll(PollArrayWrapper.java:100)
        sun.nio.ch.PollSelectorImpl.doSelect(PollSelectorImpl.java:56)
        sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
        sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
       
org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:389)
       
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
       
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
......................
CPU SAMPLES BEGIN (total = 463435) Thu Jul 26 07:20:34 2007
rank   self  accum   count trace method
   1 86.46% 86.46%  400702 300291 sun.nio.ch.PollArrayWrapper.poll0
   2  6.14% 92.60%   28460 300275 sun.nio.ch.PollArrayWrapper.poll0
   3  4.09% 96.70%   18975 300468 sun.nio.ch.PollArrayWrapper.poll0
......................

It seems that sun.nio.ch.PollArrayWrapper.poll0 takes a lot of CPU time. Is
it normal? If not, what the problem may be?

My main program is like this:

......................
        ByteBuffer.setUseDirectBuffers(false);
        ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
        
        Executor executor = Executors.newCachedThreadPool();
        
        SocketAcceptor acceptor = new
SocketAcceptor(Runtime.getRuntime().availableProcessors(), executor);
        
        SocketAcceptorConfig config = new SocketAcceptorConfig();
        config.setThreadModel(ThreadModel.MANUAL);
        config.setReuseAddress(true);
        config.getFilterChain().addLast("codec", new ProtocolCodecFilter(new
MyCodecFactory()));
        config.getFilterChain().addLast("threadpool", new
ExecutorFilter(executor));
        
        acceptor.bind(new InetSocketAddress(port), handler, config);
......................

Any suggestions will be appreciated! Thanks!




-- 
View this message in context: 
http://www.nabble.com/Why-high-CPU-load--tf4149135s16868.html#a11803475
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.

Reply via email to