[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - ByteBuffer.allocateDirect ridiculously
clebert.suconic@jboss.com
do-not-reply at jboss.com
Mon Mar 2 20:49:21 EST 2009
I just found out ByteBuffer.allocateDirect is ridiculously slow, that's why the Buffer reuse on Journal made a lot of difference on the performance for us.
| final int TIMES = 50;
|
| final long numberOfIteractions = 1000000;
|
|
| public void testJustAllocateBufferDirect() throws Exception
| {
|
| long start = System.currentTimeMillis();
|
| for (int c = 0; c < TIMES; c++)
| {
| for (long i = 0; i < numberOfIteractions; i++)
| {
| if (i == 10000)
| {
| start = System.currentTimeMillis();
| }
| MessagingBuffer bufferSend = ChannelBuffers.wrappedBuffer(ByteBuffer.allocateDirect(1024));
|
| bufferSend.writeBytes(new byte[1024]);
| }
|
| long spentTime = System.currentTimeMillis() - start;
|
| System.out.println("Time BuffersDirect = " + spentTime);
| }
|
| }
|
| public void testOurBuffers() throws Exception
| {
|
| long start = System.currentTimeMillis();
|
| for (int c = 0; c < TIMES; c++)
| {
| for (long i = 0; i < numberOfIteractions; i++)
| {
| if (i == 10000)
| {
| start = System.currentTimeMillis();
| }
| ChannelBuffer bufferSend = ChannelBuffers.wrappedBuffer(AsynchronousFileImpl.newNativeBuffer(1024));
|
| bufferSend.writeBytes(new byte[1024]);
|
| AsynchronousFileImpl.destroyBuffer(bufferSend.toByteBuffer());
| }
|
| long spentTime = System.currentTimeMillis() - start;
|
| System.out.println("Time JBM JNI Buffers = " + spentTime);
| }
|
|
On the Above test, ByteBuffer.allocateDirect needed 100 seconds to complete the 1 million buffers.
While our code, allocating ByteBuffers directly through JNI, needed 2 seconds to complete 1 million buffers.
That *is* ridiculous.
The new Buffers were slicing the direct ByteBuffer, what affected the capacity, breaking buffer reuse, what raised this issue to my eyes.
I have made a few changes on the Journal, where we will allocate buffers directly, and I could get very good numbers with some simple tests. (Even thought I was not targeting any optimizations.. just looking after this bug on ByteBuffer).
We can talk about this tomorrow on the meeting.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4214338#4214338
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4214338
More information about the jboss-dev-forums
mailing list