On 4/20/07, Trustin Lee <[EMAIL PROTECTED]> wrote:
On 4/20/07, Richard Lowe <[EMAIL PROTECTED]> wrote:
> Hi Mike and everybody,
>
> I am now doing this, but it doesn't seem to make much difference in
> terms of the performance:
> io.write(ByteBuffer.wrap(b))
>
> I have run a profiler and it appears that around 48.4% of the time is
> spent in ByteBuffer.allocate.
>
> Could I store a small ByteBuffer in my session using setAttribute() and
> then reuse that for every write? It would only be tiny.
>
> I may be stabbing in the dark here, but wondering if that might help?
> Your thoughts greatly appreciated as ever.
You might need to decrease the default receive/send buffer size. For example:
SocketAcceptorConfig cfg = ...;
((SocketSessionConfig) cfg.getSessionConfig()).setReceiveBufferSize(512);
((SocketSessionConfig) cfg.getSessionConfig()).setSendBufferSize(512);
or
((SocketSessionConfig) acceptor.getDefaultSessionConfig()).setReceive....
or
((SocketSessionConfig) session.getConfig()).setReceive...
I found the default buffer size of some operating systems is too big
(e.g. 40k!). Decreasing them impacts performance quite a lot. (about
20%?)
Additionally, did you try to turn on 'tcp no delay' option? (this
doesn't affect CPU utilization but might improve throughput)
((SocketSessionConfig) cfg.getSessionConfig()).setTcpNoDelay(true);
and... It would be nice to see your IoHandler implementation code.
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6