[rabbitmq-discuss] Performance question - java
jerryk at vmware.com
Tue Jan 11 21:25:28 GMT 2011
> I'm evaluating AMQP for use with both Java and C++, and have a question related to the Java library - does it share/pool connections?
That depends what you mean. The Connection class that is exposed to the Java client wraps a TCP connection and runs a Java thread to handle AMQP related activity on the behalf of your client code and the broker on the other side of the connection.
> I am working on a distributed system, and currently we create an HTTP connection, send a message to a server (host/port) and then tear down the connection - there is a slight overhead to this, but likely not affecting our overall throughput, but ideally, we would like to have the connection open for the send, to avoid the cost of constructing the connection for every message.
> So, asking wrt Rabbit - if I send a bunch of messages, is there a connection creation cost for each one?
Nope. You create a connection, and then from the connection you create one or more channels. Channels in Rabbit and AMQP effectively let you multiplex the expensive TCP connection. You can have one or more channels associated with a given connection, and they can publish, receive, ack, etc. independently of one another as long as some basic thread safety practices are observed. You can keep a connection and its channels open in your client for long sessions if you like, potentially handling many messages over its lifetime.
There's a summary of the relationships of these entities, and some Java sample code here:
The samples are usually straightforward to adapt to the client libraries for other languages.
> Any help here is appreciated - I'm spending some time looking at performance, as throughput for us is extremely important.
The documentation on the Rabbit website, and the new Rabbit tutorials...
might be of interest to you. Also, if you're already looking at the Java client, it comes with many samples you can experiment with and use as inspiration. Its unit tests can also be instructive to look at.
More information about the rabbitmq-discuss