You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by mattcodes <ma...@mattfreeman.co.uk> on 2010/04/07 13:12:53 UTC

Relationship between Producer, Session and Connection.

In a (ASP.Net/c#) web-app I want to pump messages to an ActiveMQ queue
(nothing complicated - no native transactions etc..). Reading various FAQs
etc.. I figure I should create a pool of say 50 message producers, each with
their own session and own connection for the best performance. i.e. a 1 to 1
relation between producer --> session and session --> connection. Is this
the optimal setup? When would this be problematic?  Obviously Id have to
implement the pooling myself since there's no ActiveMQ pool lib for .Net? 

Alternatively I thought about pooling Session (with 1to1 with connection)
and then creating the producer on each request? The overhead of this is
about 9ms I tested, which isnt that far off pulling from a pool, 
-- 
View this message in context: http://old.nabble.com/Relationship-between-Producer%2C-Session-and-Connection.-tp28163471p28163471.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Relationship between Producer, Session and Connection.

Posted by Bruce Snyder <br...@gmail.com>.
On Wed, Apr 7, 2010 at 10:56 PM, mattcodes <ma...@mattfreeman.co.uk> wrote:
>
> The .Net library does not have a pooled connection factory. I will look at
> porting the Java one.
>
> ...Yikes, I think I'll drop that idea, the naming is already making it not
> suitable for hangover day. ConnectionPool represents a connection and
> associated pool, not a connection pool.

There is a CachingConnectionFactory in the Spring .NET APIs:

http://springframework.net/docs/1.3.0/api/net-2.0/html/topic17141.html

I believe that the implementation in Spring .NET is nearly the same as
the one in the Spring Java APIs. But I'm not a Windows/.NET type so
I've CC'd Mark Pollack who created and maintains Spring .NET.

> 1 to 1 for producer to session, and then shared connection(s). From what I
> read things will be multiplexed onto the connection, is there anything on
> the broker side to see the usage of a connection - how much its maxed out
> by? thus providing a indicator of when to bring in multiple connections

Various aspects of ActiveMQ can be monitored through JMX and jconsole
will provide resource utilization monitoring. The best thing to do is
test it in your environment (i.e., on your machines with your
destinations, with your anticipated load, etc.) and watch the broker
memory usage. The memory available to the broker can be adjusted via
the <systemUsage> element in the activemq.xml. More info about it is
available here:

http://activemq.apache.org/producer-flow-control.html#ProducerFlowControl-Systemusage

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder

Re: Relationship between Producer, Session and Connection.

Posted by mattcodes <ma...@mattfreeman.co.uk>.
The .Net library does not have a pooled connection factory. I will look at
porting the Java one.

...Yikes, I think I'll drop that idea, the naming is already making it not
suitable for hangover day. ConnectionPool represents a connection and
associated pool, not a connection pool.


1 to 1 for producer to session, and then shared connection(s). From what I
read things will be multiplexed onto the connection, is there anything on
the broker side to see the usage of a connection - how much its maxed out
by? thus providing a indicator of when to bring in multiple connections



bsnyder wrote:
> 
> On Wed, Apr 7, 2010 at 10:15 PM, mattcodes <ma...@mattfreeman.co.uk> wrote:
>>
>> When you say overhead are you talking about ongoing on startup, I was
>> thinking of initializing the pool on startup, so bring up minsize of
>> pools
>> say 30 producer(1:1)session(1:1)connection, so when requested its all
>> ready
>> to go, use it, and release it back to the pool for the next incoming web
>> request that has to send a message to the backend queue.
> 
> Not only is the overhead of creating each object large, but creating a
> connection and a session per producer is just simply unnecessary. It
> winds up being a waste of resources that burden the broker
> unnecessarily.
> 
>> If I go the route of having 1 connection, how many session would you have
>> per connection? I guess start with the connection as singelton, then a
>> pool
>> of sessions? Eventually scale it to connection per 20 sessions? Or
>> something
>> like that?
> 
> A single connection can support many sessions. As I said before, the
> best approach is use a pooling connection factory. That way all of
> this is handled for you and all you need to do is create and cache the
> producers.
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
> 
> ActiveMQ in Action: http://bit.ly/2je6cQ
> Blog: http://bruceblog.org/
> Twitter: http://twitter.com/brucesnyder
> 
> 

-- 
View this message in context: http://old.nabble.com/Relationship-between-Producer%2C-Session-and-Connection.-tp28163471p28174121.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Relationship between Producer, Session and Connection.

Posted by Bruce Snyder <br...@gmail.com>.
On Wed, Apr 7, 2010 at 10:15 PM, mattcodes <ma...@mattfreeman.co.uk> wrote:
>
> When you say overhead are you talking about ongoing on startup, I was
> thinking of initializing the pool on startup, so bring up minsize of pools
> say 30 producer(1:1)session(1:1)connection, so when requested its all ready
> to go, use it, and release it back to the pool for the next incoming web
> request that has to send a message to the backend queue.

Not only is the overhead of creating each object large, but creating a
connection and a session per producer is just simply unnecessary. It
winds up being a waste of resources that burden the broker
unnecessarily.

> If I go the route of having 1 connection, how many session would you have
> per connection? I guess start with the connection as singelton, then a pool
> of sessions? Eventually scale it to connection per 20 sessions? Or something
> like that?

A single connection can support many sessions. As I said before, the
best approach is use a pooling connection factory. That way all of
this is handled for you and all you need to do is create and cache the
producers.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder

Re: Relationship between Producer, Session and Connection.

Posted by mattcodes <ma...@mattfreeman.co.uk>.
When you say overhead are you talking about ongoing on startup, I was
thinking of initializing the pool on startup, so bring up minsize of pools
say 30 producer(1:1)session(1:1)connection, so when requested its all ready
to go, use it, and release it back to the pool for the next incoming web
request that has to send a message to the backend queue.

If I go the route of having 1 connection, how many session would you have
per connection? I guess start with the connection as singelton, then a pool
of sessions? Eventually scale it to connection per 20 sessions? Or something
like that?

There could be quite a few concurrent users that will push the demand on the
activemq parts up





bsnyder wrote:
> 
> On Wed, Apr 7, 2010 at 5:12 AM, mattcodes <ma...@mattfreeman.co.uk> wrote:
>>
>> In a (ASP.Net/c#) web-app I want to pump messages to an ActiveMQ queue
>> (nothing complicated - no native transactions etc..). Reading various
>> FAQs
>> etc.. I figure I should create a pool of say 50 message producers, each
>> with
>> their own session and own connection for the best performance. i.e. a 1
>> to 1
>> relation between producer --> session and session --> connection. Is this
>> the optimal setup? When would this be problematic?  Obviously Id have to
>> implement the pooling myself since there's no ActiveMQ pool lib for .Net?
>>
>> Alternatively I thought about pooling Session (with 1to1 with connection)
>> and then creating the producer on each request? The overhead of this is
>> about 9ms I tested, which isnt that far off pulling from a pool,
> 
> The problem with what you are proposing is that it won't scale very
> well. Creating connections, sessions and producers in a 1:1 ratio is
> inappropriate because the overhead of both is rather high. It's
> actually better to use one connection to create many sessions and only
> increasing the number of connections if it is deemed necessary. This
> is the model used by most JMS pooling connection factories and most
> messaging middleware works very well with this model.
> 
> Here is an example of what I recommend to folks for sending messages:
> 
> http://bsnyderblog.blogspot.com/2010/02/using-spring-jmstemplate-to-send-jms.html
> 
> This example uses the Spring Framework to send JMS messages. Let me
> know if you have any questions.
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
> 
> ActiveMQ in Action: http://bit.ly/2je6cQ
> Blog: http://bruceblog.org/
> Twitter: http://twitter.com/brucesnyder
> 
> 

-- 
View this message in context: http://old.nabble.com/Relationship-between-Producer%2C-Session-and-Connection.-tp28163471p28173978.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Relationship between Producer, Session and Connection.

Posted by Bruce Snyder <br...@gmail.com>.
On Wed, Apr 7, 2010 at 5:12 AM, mattcodes <ma...@mattfreeman.co.uk> wrote:
>
> In a (ASP.Net/c#) web-app I want to pump messages to an ActiveMQ queue
> (nothing complicated - no native transactions etc..). Reading various FAQs
> etc.. I figure I should create a pool of say 50 message producers, each with
> their own session and own connection for the best performance. i.e. a 1 to 1
> relation between producer --> session and session --> connection. Is this
> the optimal setup? When would this be problematic?  Obviously Id have to
> implement the pooling myself since there's no ActiveMQ pool lib for .Net?
>
> Alternatively I thought about pooling Session (with 1to1 with connection)
> and then creating the producer on each request? The overhead of this is
> about 9ms I tested, which isnt that far off pulling from a pool,

The problem with what you are proposing is that it won't scale very
well. Creating connections, sessions and producers in a 1:1 ratio is
inappropriate because the overhead of both is rather high. It's
actually better to use one connection to create many sessions and only
increasing the number of connections if it is deemed necessary. This
is the model used by most JMS pooling connection factories and most
messaging middleware works very well with this model.

Here is an example of what I recommend to folks for sending messages:

http://bsnyderblog.blogspot.com/2010/02/using-spring-jmstemplate-to-send-jms.html

This example uses the Spring Framework to send JMS messages. Let me
know if you have any questions.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder