[rabbitmq-discuss] rabbitmq java client socket io performance (3 sendto syscalls per basicPublish)

Jason Toffaletti jason at cornsyrup.org
Thu May 24 08:46:24 BST 2012


I couldn't find a bug tracker, so I'm reporting this here.

I was stracing a java process that uses the 2.8.2 java amqp client and I 
noticed that every basicPublish is resulting in 3 sendto syscalls:

3026  00:06:51.269104 sendto(27, 
"\1\0\1\0\0\0\17\0<\0(\0\0\6hose04\0\0\316", 23, 0, NULL, 0 <unfinished ...>
3027  00:06:51.269127 <... futex resumed> ) = 0 <0.000030>
3026  00:06:51.269142 <... sendto resumed> ) = 23 <0.000019>
3025  00:06:51.269160 sendto(24, 
"\1\0\1\0\0\0\17\0<\0(\0\0\6hose03\0\0\316", 23, 0, NULL, 0 <unfinished ...>
3027  00:06:51.269189 futex(0x7f8e5c442b54, FUTEX_WAIT_PRIVATE, 10202495, 
NULL <unfinished ...>
3026  00:06:51.269211 sendto(27, "\2\0\1\0\0\0 
\0<\0\0\0\0\0\0\0\0\7\302\220\0\20application/json\1\316", 40, 0, NULL, 0 
<unfinished ...>
3025  00:06:51.269237 <... sendto resumed> ) = 23 <0.000058>
3026  00:06:51.269258 <... sendto resumed> ) = 40 <0.000024>
3025  00:06:51.269279 sendto(24, "\2\0\1\0\0\0 
\0<\0\0\0\0\0\0\0\0\10\206\220\0\20application/json\1\316", 40, 0, NULL, 0 
<unfinished ...>
3026  00:06:51.269314 sendto(27, "\3\0\1\0\0\7\302"..., 1994, 0, NULL, 0 
<unfinished ...>
3025  00:06:51.269444 <... sendto resumed> ) = 40 <0.000138>
3026  00:06:51.269463 <... sendto resumed> ) = 1994 <0.000025>

I believe these 3 sendto syscalls per basicPublish is a performance 
bottleneck and I went looking for a way to make it a single sendto call 
with all 3 frames included.

I'm fairly new to Java and AMQP, so bare with me.

The client is using BufferedOutputStream to wrap socket io in:

http://hg.rabbitmq.com/rabbitmq-java-client/file/b643c5c8ec23/src/com/rabbitmq/client/impl/SocketFrameHandler.java

BufferedOutputStream has a default buffer size of 512 bytes which suggests 
to me that flush() must be called in order to produce these small 23 and 40 
byte sendto calls.

AMQPCommand::transmit seems to be where the real action happens, and I see 
a connection.flush() at the end of that function:

http://hg.rabbitmq.com/rabbitmq-java-client/file/b643c5c8ec23/src/com/rabbitmq/client/impl/AMQCommand.java

However I'm still a bit confused because I think a basicPublish should only 
result in one transmit() and thus one flush() and one sendto(). This is 
where I'm stuck.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120524/50006d56/attachment.htm>


More information about the rabbitmq-discuss mailing list