You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Maki Camara <Ma...@etu.enseeiht.fr> on 2013/04/16 15:39:53 UTC

Non blocking receive qpid proton

Hi,

I would like to know if there is any means to do an non-blocking 
receive,
I mean I would like to be able to avoid the loop{while(true) as shown 
in qpid proton examples} when listening,
I want my process awaken only when a new message is added in the 
incoming queue.

Thank you for your response

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


RE: Non blocking receive qpid proton

Posted by Maki Camara <Ma...@etu.enseeiht.fr>.
Ok,

Thank you Jason


On Tue, 16 Apr 2013 18:34:28 +0100, Jason Barto wrote:
> Apologies, I typed before thinking. To address you're concern you'll 
> still
> have the while (true) you're trying to avoid but the cpu consumption 
> you're
> trying to avoid will be pushed onto the messaging library and should 
> be
> pretty easy on cpu.
>
> Sincerely,
> Jason
> On Apr 16, 2013 6:21 PM, "Jason Barto" <ja...@gmail.com> 
> wrote:
>
>> In the spawned thread, rather than while(true) couldn't you register 
>> a
>> handler function or functions with the spawned thread, from the 
>> thread call
>> recv (), which blocks, and then pass the received message to the 
>> registered
>> handlers?
>>
>> Sincerely,
>> Jason
>> On Apr 16, 2013 6:13 PM, "Maki Camara" <Ma...@etu.enseeiht.fr>
>> wrote:
>>
>>> Connor,
>>>
>>> I have thought of delegating the recv to another thread, but what I 
>>> would
>>> like to have idealy is to
>>> avoid the loop(while(true)) to ensure minimal use of the cpu
>>>
>>> Thank you for your response,
>>>
>>> Maki
>>>
>>> On Tue, 16 Apr 2013 16:54:50 +0000, Connor Poske wrote:
>>>
>>>> Maki,
>>>>
>>>> An asynchronous event-listener interface would be a nice 
>>>> convenience,
>>>> but wouldn't simply blocking on recv() in another thread suite 
>>>> your
>>>> needs?
>>>>
>>>> Just spawn a thread from your main process to do receiving, while
>>>> main does whatever other work it needs to do.  This way your 
>>>> process
>>>> is not blocked.
>>>>
>>>>
>>>> ______________________________**__________
>>>> From: Maki Camara [Maki.Camara@etu.enseeiht.fr]
>>>> Sent: Tuesday, April 16, 2013 9:37 AM
>>>> To: users@qpid.apache.org
>>>> Cc: dpierce@redhat.com
>>>> Subject: Re: Non blocking receive qpid proton
>>>>
>>>> Yes that's exactly what I'm looking for. Is there any mean to do 
>>>> that?
>>>>
>>>> Thank you
>>>>
>>>> On Tue, 16 Apr 2013 11:27:20 -0400, Darryl L. Pierce wrote:
>>>>
>>>>> On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
>>>>>
>>>>>> THank you rafael,
>>>>>>
>>>>>> Sorry, I do not have a good english, I am using messenger, 
>>>>>> setting
>>>>>> the time out to zero can be useful...
>>>>>> I want my process be notified of the arrival of a new message in 
>>>>>> the
>>>>>> incoming queue(like a events...)
>>>>>> As long as this event doesn't occur, I can do another thing.... 
>>>>>> and
>>>>>> when it occur, I will call messenger.recv(0)...
>>>>>>
>>>>>> Is this more clear
>>>>>>
>>>>>
>>>>> You want something more along the lines of registering a listener
>>>>> type
>>>>> that's called when a new message arrives, is that it?
>>>>>
>>>>
>>>>
>>>> ------------------------------**------------------------------**
>>>> ---------
>>>> To unsubscribe, e-mail: 
>>>> users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>>>> For additional commands, e-mail: users-help@qpid.apache.org
>>>>
>>>>
>>>> ------------------------------**------------------------------**
>>>> ---------
>>>> To unsubscribe, e-mail: 
>>>> users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>>>> For additional commands, e-mail: users-help@qpid.apache.org
>>>>
>>>
>>>
>>> 
>>> ------------------------------**------------------------------**---------
>>> To unsubscribe, e-mail: 
>>> users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>>> For additional commands, e-mail: users-help@qpid.apache.org
>>>
>>>


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


RE: Non blocking receive qpid proton

Posted by Jason Barto <ja...@gmail.com>.
Apologies, I typed before thinking. To address you're concern you'll still
have the while (true) you're trying to avoid but the cpu consumption you're
trying to avoid will be pushed onto the messaging library and should be
pretty easy on cpu.

Sincerely,
Jason
On Apr 16, 2013 6:21 PM, "Jason Barto" <ja...@gmail.com> wrote:

> In the spawned thread, rather than while(true) couldn't you register a
> handler function or functions with the spawned thread, from the thread call
> recv (), which blocks, and then pass the received message to the registered
> handlers?
>
> Sincerely,
> Jason
> On Apr 16, 2013 6:13 PM, "Maki Camara" <Ma...@etu.enseeiht.fr>
> wrote:
>
>> Connor,
>>
>> I have thought of delegating the recv to another thread, but what I would
>> like to have idealy is to
>> avoid the loop(while(true)) to ensure minimal use of the cpu
>>
>> Thank you for your response,
>>
>> Maki
>>
>> On Tue, 16 Apr 2013 16:54:50 +0000, Connor Poske wrote:
>>
>>> Maki,
>>>
>>> An asynchronous event-listener interface would be a nice convenience,
>>> but wouldn't simply blocking on recv() in another thread suite your
>>> needs?
>>>
>>> Just spawn a thread from your main process to do receiving, while
>>> main does whatever other work it needs to do.  This way your process
>>> is not blocked.
>>>
>>>
>>> ______________________________**__________
>>> From: Maki Camara [Maki.Camara@etu.enseeiht.fr]
>>> Sent: Tuesday, April 16, 2013 9:37 AM
>>> To: users@qpid.apache.org
>>> Cc: dpierce@redhat.com
>>> Subject: Re: Non blocking receive qpid proton
>>>
>>> Yes that's exactly what I'm looking for. Is there any mean to do that?
>>>
>>> Thank you
>>>
>>> On Tue, 16 Apr 2013 11:27:20 -0400, Darryl L. Pierce wrote:
>>>
>>>> On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
>>>>
>>>>> THank you rafael,
>>>>>
>>>>> Sorry, I do not have a good english, I am using messenger, setting
>>>>> the time out to zero can be useful...
>>>>> I want my process be notified of the arrival of a new message in the
>>>>> incoming queue(like a events...)
>>>>> As long as this event doesn't occur, I can do another thing.... and
>>>>> when it occur, I will call messenger.recv(0)...
>>>>>
>>>>> Is this more clear
>>>>>
>>>>
>>>> You want something more along the lines of registering a listener
>>>> type
>>>> that's called when a new message arrives, is that it?
>>>>
>>>
>>>
>>> ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>>> For additional commands, e-mail: users-help@qpid.apache.org
>>>
>>>
>>> ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>>> For additional commands, e-mail: users-help@qpid.apache.org
>>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>

RE: Non blocking receive qpid proton

Posted by Jason Barto <ja...@gmail.com>.
In the spawned thread, rather than while(true) couldn't you register a
handler function or functions with the spawned thread, from the thread call
recv (), which blocks, and then pass the received message to the registered
handlers?

Sincerely,
Jason
On Apr 16, 2013 6:13 PM, "Maki Camara" <Ma...@etu.enseeiht.fr> wrote:

> Connor,
>
> I have thought of delegating the recv to another thread, but what I would
> like to have idealy is to
> avoid the loop(while(true)) to ensure minimal use of the cpu
>
> Thank you for your response,
>
> Maki
>
> On Tue, 16 Apr 2013 16:54:50 +0000, Connor Poske wrote:
>
>> Maki,
>>
>> An asynchronous event-listener interface would be a nice convenience,
>> but wouldn't simply blocking on recv() in another thread suite your
>> needs?
>>
>> Just spawn a thread from your main process to do receiving, while
>> main does whatever other work it needs to do.  This way your process
>> is not blocked.
>>
>>
>> ______________________________**__________
>> From: Maki Camara [Maki.Camara@etu.enseeiht.fr]
>> Sent: Tuesday, April 16, 2013 9:37 AM
>> To: users@qpid.apache.org
>> Cc: dpierce@redhat.com
>> Subject: Re: Non blocking receive qpid proton
>>
>> Yes that's exactly what I'm looking for. Is there any mean to do that?
>>
>> Thank you
>>
>> On Tue, 16 Apr 2013 11:27:20 -0400, Darryl L. Pierce wrote:
>>
>>> On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
>>>
>>>> THank you rafael,
>>>>
>>>> Sorry, I do not have a good english, I am using messenger, setting
>>>> the time out to zero can be useful...
>>>> I want my process be notified of the arrival of a new message in the
>>>> incoming queue(like a events...)
>>>> As long as this event doesn't occur, I can do another thing.... and
>>>> when it occur, I will call messenger.recv(0)...
>>>>
>>>> Is this more clear
>>>>
>>>
>>> You want something more along the lines of registering a listener
>>> type
>>> that's called when a new message arrives, is that it?
>>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: Non blocking receive qpid proton

Posted by "Darryl L. Pierce" <dp...@redhat.com>.
On Tue, Apr 16, 2013 at 07:13:15PM +0200, Maki Camara wrote:
> Connor,
> 
> I have thought of delegating the recv to another thread, but what I
> would like to have idealy is to
> avoid the loop(while(true)) to ensure minimal use of the cpu

Sorry to not reply before, I was on holiday yesterday.

I don't think the blocking model will put much stress on the CPU. while
no messages are returned, the get/fetch methods will sit and do nothing
for the timeout period specified (or forever if no timeout is provided).
It won't simply loop repeatedly.

What language are you looking to use (you may have said and I'm just
forgetting or haven't seen the message yet)? In Ruby I've been playing
with the idea of registering blocks for Receiver.get, Receiver.fetch
and Session.next_receiver that would act as a multiplexer for incoming
messages and for receivers with pending local messages.

-- 
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/


RE: Non blocking receive qpid proton

Posted by Connor Poske <co...@onrampwireless.com>.
I'm not sure what you mean by minimal CPU use. You should never just spin inside a while loop like that. The recv() call blocks. This does not use CPU. 

while(threadCanRun)
{
    receiver.get( timeout ) ;  //This blocks until timeout expires
}
________________________________________
From: Maki Camara [Maki.Camara@etu.enseeiht.fr]
Sent: Tuesday, April 16, 2013 10:13 AM
To: users@qpid.apache.org
Cc: dpierce@redhat.com; Connor Poske
Subject: RE: Non blocking receive qpid proton

Connor,

I have thought of delegating the recv to another thread, but what I
would like to have idealy is to
avoid the loop(while(true)) to ensure minimal use of the cpu

Thank you for your response,

Maki

On Tue, 16 Apr 2013 16:54:50 +0000, Connor Poske wrote:
> Maki,
>
> An asynchronous event-listener interface would be a nice convenience,
> but wouldn't simply blocking on recv() in another thread suite your
> needs?
>
> Just spawn a thread from your main process to do receiving, while
> main does whatever other work it needs to do.  This way your process
> is not blocked.
>
>
> ________________________________________
> From: Maki Camara [Maki.Camara@etu.enseeiht.fr]
> Sent: Tuesday, April 16, 2013 9:37 AM
> To: users@qpid.apache.org
> Cc: dpierce@redhat.com
> Subject: Re: Non blocking receive qpid proton
>
> Yes that's exactly what I'm looking for. Is there any mean to do
> that?
>
> Thank you
>
> On Tue, 16 Apr 2013 11:27:20 -0400, Darryl L. Pierce wrote:
>> On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
>>> THank you rafael,
>>>
>>> Sorry, I do not have a good english, I am using messenger, setting
>>> the time out to zero can be useful...
>>> I want my process be notified of the arrival of a new message in
>>> the
>>> incoming queue(like a events...)
>>> As long as this event doesn't occur, I can do another thing.... and
>>> when it occur, I will call messenger.recv(0)...
>>>
>>> Is this more clear
>>
>> You want something more along the lines of registering a listener
>> type
>> that's called when a new message arrives, is that it?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org


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


RE: Non blocking receive qpid proton

Posted by Maki Camara <Ma...@etu.enseeiht.fr>.
Connor,

I have thought of delegating the recv to another thread, but what I 
would like to have idealy is to
avoid the loop(while(true)) to ensure minimal use of the cpu

Thank you for your response,

Maki

On Tue, 16 Apr 2013 16:54:50 +0000, Connor Poske wrote:
> Maki,
>
> An asynchronous event-listener interface would be a nice convenience,
> but wouldn't simply blocking on recv() in another thread suite your
> needs?
>
> Just spawn a thread from your main process to do receiving, while
> main does whatever other work it needs to do.  This way your process
> is not blocked.
>
>
> ________________________________________
> From: Maki Camara [Maki.Camara@etu.enseeiht.fr]
> Sent: Tuesday, April 16, 2013 9:37 AM
> To: users@qpid.apache.org
> Cc: dpierce@redhat.com
> Subject: Re: Non blocking receive qpid proton
>
> Yes that's exactly what I'm looking for. Is there any mean to do 
> that?
>
> Thank you
>
> On Tue, 16 Apr 2013 11:27:20 -0400, Darryl L. Pierce wrote:
>> On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
>>> THank you rafael,
>>>
>>> Sorry, I do not have a good english, I am using messenger, setting
>>> the time out to zero can be useful...
>>> I want my process be notified of the arrival of a new message in 
>>> the
>>> incoming queue(like a events...)
>>> As long as this event doesn't occur, I can do another thing.... and
>>> when it occur, I will call messenger.recv(0)...
>>>
>>> Is this more clear
>>
>> You want something more along the lines of registering a listener
>> type
>> that's called when a new message arrives, is that it?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org


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


RE: Non blocking receive qpid proton

Posted by Connor Poske <co...@onrampwireless.com>.
Maki,

An asynchronous event-listener interface would be a nice convenience, but wouldn't simply blocking on recv() in another thread suite your needs? 

Just spawn a thread from your main process to do receiving, while main does whatever other work it needs to do.  This way your process is not blocked. 

 
________________________________________
From: Maki Camara [Maki.Camara@etu.enseeiht.fr]
Sent: Tuesday, April 16, 2013 9:37 AM
To: users@qpid.apache.org
Cc: dpierce@redhat.com
Subject: Re: Non blocking receive qpid proton

Yes that's exactly what I'm looking for. Is there any mean to do that?

Thank you

On Tue, 16 Apr 2013 11:27:20 -0400, Darryl L. Pierce wrote:
> On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
>> THank you rafael,
>>
>> Sorry, I do not have a good english, I am using messenger, setting
>> the time out to zero can be useful...
>> I want my process be notified of the arrival of a new message in the
>> incoming queue(like a events...)
>> As long as this event doesn't occur, I can do another thing.... and
>> when it occur, I will call messenger.recv(0)...
>>
>> Is this more clear
>
> You want something more along the lines of registering a listener
> type
> that's called when a new message arrives, is that it?


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


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


Re: Non blocking receive qpid proton

Posted by Maki Camara <Ma...@etu.enseeiht.fr>.
Yes that's exactly what I'm looking for. Is there any mean to do that?

Thank you

On Tue, 16 Apr 2013 11:27:20 -0400, Darryl L. Pierce wrote:
> On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
>> THank you rafael,
>>
>> Sorry, I do not have a good english, I am using messenger, setting
>> the time out to zero can be useful...
>> I want my process be notified of the arrival of a new message in the
>> incoming queue(like a events...)
>> As long as this event doesn't occur, I can do another thing.... and
>> when it occur, I will call messenger.recv(0)...
>>
>> Is this more clear
>
> You want something more along the lines of registering a listener 
> type
> that's called when a new message arrives, is that it?


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


Re: Non blocking receive qpid proton

Posted by "Darryl L. Pierce" <dp...@redhat.com>.
On Tue, Apr 16, 2013 at 04:54:15PM +0200, Maki Camara wrote:
> THank you rafael,
> 
> Sorry, I do not have a good english, I am using messenger, setting
> the time out to zero can be useful...
> I want my process be notified of the arrival of a new message in the
> incoming queue(like a events...)
> As long as this event doesn't occur, I can do another thing.... and
> when it occur, I will call messenger.recv(0)...
> 
> Is this more clear

You want something more along the lines of registering a listener type
that's called when a new message arrives, is that it?

-- 
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/


Re: Non blocking receive qpid proton

Posted by Maki Camara <Ma...@etu.enseeiht.fr>.
THank you rafael,

Sorry, I do not have a good english, I am using messenger, setting the 
time out to zero can be useful...
I want my process be notified of the arrival of a new message in the 
incoming queue(like a events...)
As long as this event doesn't occur, I can do another thing.... and 
when it occur, I will call messenger.recv(0)...

Is this more clear

Maki

On Tue, 16 Apr 2013 10:03:35 -0400, Rafael Schloming wrote:
> I'm a little confused by your question. Awakening only when a new 
> message
> is added to the incoming queue sounds more like a blocking than a
> non-blocking receive.
>
> That said, you can certainly poll rather than block if you wish. 
> Assuming
> you're using messenger, you can set the timeout of the messenger to 
> zero.
> This will cause receive to return immediately rather than block 
> waiting for
> incoming messages. You can then check to see if any messages were 
> actually
> received by checking the size of the incoming queue.
>
> Hope this helps. If you describe a bit more about what you're trying 
> to do
> then I might be able to give you a better answer.
>
> --Rafael
>
>
> On Tue, Apr 16, 2013 at 9:39 AM, Maki Camara
> <Ma...@etu.enseeiht.fr>wrote:
>
>> Hi,
>>
>> I would like to know if there is any means to do an non-blocking 
>> receive,
>> I mean I would like to be able to avoid the loop{while(true) as 
>> shown in
>> qpid proton examples} when listening,
>> I want my process awaken only when a new message is added in the 
>> incoming
>> queue.
>>
>> Thank you for your response
>>
>> 
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: 
>> users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>


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


Re: Non blocking receive qpid proton

Posted by Rafael Schloming <rh...@alum.mit.edu>.
I'm a little confused by your question. Awakening only when a new message
is added to the incoming queue sounds more like a blocking than a
non-blocking receive.

That said, you can certainly poll rather than block if you wish. Assuming
you're using messenger, you can set the timeout of the messenger to zero.
This will cause receive to return immediately rather than block waiting for
incoming messages. You can then check to see if any messages were actually
received by checking the size of the incoming queue.

Hope this helps. If you describe a bit more about what you're trying to do
then I might be able to give you a better answer.

--Rafael


On Tue, Apr 16, 2013 at 9:39 AM, Maki Camara <Ma...@etu.enseeiht.fr>wrote:

> Hi,
>
> I would like to know if there is any means to do an non-blocking receive,
> I mean I would like to be able to avoid the loop{while(true) as shown in
> qpid proton examples} when listening,
> I want my process awaken only when a new message is added in the incoming
> queue.
>
> Thank you for your response
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.**org<us...@qpid.apache.org>
> For additional commands, e-mail: users-help@qpid.apache.org
>
>