You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Toralf Lund <to...@pgs.com> on 2014/10/30 14:30:46 UTC

QPid 0.22 C++ client threading

Hi,

We have encountered a problem with an application using QPid 0.22/APQP 
0.10 with the C++ messaging API, which could be caused by creation of an 
excessive number of threads. This might not be related to QPid, and the 
issue may not even be threading in this application (the problem occurs 
once every blue moon, so it's a bit hard to test theories), but in order 
to get a clear picture of the situation, it would be good to know what 
threads QPid creates, and if there are any issues with threading. Some 
questions:

  * When exactly does QPid create a new thread?
  * Are there any known situations where one might end up with lots of
    runaway threads?
  * Do I have to do anything specific e.g. after a communication error
    in order to make sure old threads go away?

I have one connection object with one session which in turn has one 
sender and two receivers (for two different queues.) Whenever an 
exception occurs, I close down the connection using connection.close(), 
and reset everything else by assigning a default-constructed object, as in
session=qpid::messaging::Session();
sender=qpid::messaging::Sender();

etc.

I then (later) try to reopen using a construct like

if(!connection.isOpen())
   connection.open();

if(session.isNull())
   session=connection.createSession();
if(receiver.isNull())
   receiver=session.createReceiver(<address>);
if(receiver2.isNull())
   receiver2=session.createReceiver(<address>);
if(sender.isNull())
   sender=session.createSender(<address>);

This code is executed periodically, and is also what takes care of 
first-time creation after startup. This is done within a try ... catch 
block.



The actual problem I'm talking about is that a pthread_create() call 
used for something unrelated will sometimes fail with EAGAIN.

An information anyone might have about the threading behaviour of QPid 
would be helpful.

TIA,

- Toralf


This e-mail, including any attachments and response string, may contain proprietary information which is confidential and may be legally privileged. It is for the intended recipient only. If you are not the intended recipient or transmission error has misdirected this e-mail, please notify the author by return e-mail and delete this message and any attachment immediately. If you are not the intended recipient you must not use, disclose, distribute, forward, copy, print or rely on this e-mail in any way except as permitted by the author.

Re: QPid 0.22 C++ client threading

Posted by Toralf Lund <to...@pgs.com>.
On 31/10/14 16:13, Gordon Sim wrote:
> On 10/30/2014 01:30 PM, Toralf Lund wrote:
>> Hi,
>>
>> We have encountered a problem with an application using QPid 0.22/APQP
>> 0.10 with the C++ messaging API, which could be caused by creation of an
>> excessive number of threads. This might not be related to QPid, and the
>> issue may not even be threading in this application (the problem occurs
>> once every blue moon, so it's a bit hard to test theories), but in order
>> to get a clear picture of the situation, it would be good to know what
>> threads QPid creates, and if there are any issues with threading. Some
>> questions:
>>
>>   * When exactly does QPid create a new thread?
>
> There is a shared thread pool for all 0-10 connections, used for IO. 
> The maximum size is controlled by the max-iothreads option. This is by 
> default set to be the number of available cores (or 1 if that cannot 
> be determined), but can be overidden  e.g. by setting 
> QPID_MAX_IOTHREADS). The pool starts out empty and the size is 
> increased as connections are added, up to the configured limit. At 
> present there is nothing that will kill off threads once created however.
>
> In addition there is a single timer thread that is used for heartbeat 
> related time activities.
OK. Thanks.

>
>>   * Are there any known situations where one might end up with lots of
>>     runaway threads?
>
> Nothing known, no.
Good.

>
>>   * Do I have to do anything specific e.g. after a communication error
>>     in order to make sure old threads go away?
>
> No.
>
> [...]
>> The actual problem I'm talking about is that a pthread_create() call
>> used for something unrelated will sometimes fail with EAGAIN.
>
> Could you perhaps have a cron job that does a ptrace on the process in 
> question periodically, and stores it in a file somewhere, so that you 
> can see what threads were present if and when the problem occurs again?
Yes, that's probably a good idea.

So far I've focused on looking for memory leaks (which I'm assuming may 
also cause this kind of problem), but I haven't found anything.

Thanks.

- Toralf


>
>> An information anyone might have about the threading behaviour of QPid
>> would be helpful.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>


This e-mail, including any attachments and response string, may contain proprietary information which is confidential and may be legally privileged. It is for the intended recipient only. If you are not the intended recipient or transmission error has misdirected this e-mail, please notify the author by return e-mail and delete this message and any attachment immediately. If you are not the intended recipient you must not use, disclose, distribute, forward, copy, print or rely on this e-mail in any way except as permitted by the author.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: QPid 0.22 C++ client threading

Posted by Gordon Sim <gs...@redhat.com>.
On 10/30/2014 01:30 PM, Toralf Lund wrote:
> Hi,
>
> We have encountered a problem with an application using QPid 0.22/APQP
> 0.10 with the C++ messaging API, which could be caused by creation of an
> excessive number of threads. This might not be related to QPid, and the
> issue may not even be threading in this application (the problem occurs
> once every blue moon, so it's a bit hard to test theories), but in order
> to get a clear picture of the situation, it would be good to know what
> threads QPid creates, and if there are any issues with threading. Some
> questions:
>
>   * When exactly does QPid create a new thread?

There is a shared thread pool for all 0-10 connections, used for IO. The 
maximum size is controlled by the max-iothreads option. This is by 
default set to be the number of available cores (or 1 if that cannot be 
determined), but can be overidden  e.g. by setting QPID_MAX_IOTHREADS). 
The pool starts out empty and the size is increased as connections are 
added, up to the configured limit. At present there is nothing that will 
kill off threads once created however.

In addition there is a single timer thread that is used for heartbeat 
related time activities.

>   * Are there any known situations where one might end up with lots of
>     runaway threads?

Nothing known, no.

>   * Do I have to do anything specific e.g. after a communication error
>     in order to make sure old threads go away?

No.

[...]
> The actual problem I'm talking about is that a pthread_create() call
> used for something unrelated will sometimes fail with EAGAIN.

Could you perhaps have a cron job that does a ptrace on the process in 
question periodically, and stores it in a file somewhere, so that you 
can see what threads were present if and when the problem occurs again?

> An information anyone might have about the threading behaviour of QPid
> would be helpful.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org