Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In RabbitMQ should I create a connection pool on Connections, Channels, or both?

Tags:

rabbitmq

Using a java client for RabbitMQ, I have created a connection pooling mechanism that has a set of rabbitmq connections established and available. Once a client leases a connection the client creates a channel. If I have to send perform tasks and send 100 messages, for each of those messages the client will lease a connection and create a channel with the API such as:

rqConnection = MyPoolManager.leaseConnection();
rqChannel = rqConnection.createChannel();

Can I have a channel pre-established within my pool as one channel per connection, or a channel can always be created prior to send a message ? My concern is that creating channels over channels might consume resources. I can have the channel co-exist with a Class that contains both the connection and the channel so it is always pre-created ahead of its usage need. If the channel creation poses no resource consumption or leakage implications, then I can proceed with my current approach.

like image 580
gextra Avatar asked Mar 28 '13 11:03

gextra


1 Answers

Based on additional research and observation from other groups, here are some facts about channels:

  • it appears that there are no documents specifying how to calculate the ration of number of channels per connection, neither for the benefits of running multiple connections vs multiple channels per connection
  • running a large number connections appears to be more resource consuming than running a large number of channels. Also, connections are limited to a certain number of file descriptors, whereas Channels are not.
  • some individual tests revealed the performance benchmarking of pooling connections versus pooling channels is similar

So the best approach appears to be in favor of having one connection and pool on multiple channels, where each channel would be provided by a different thread ( to prevent concurrency issues ).

like image 86
gextra Avatar answered Sep 30 '22 17:09

gextra