* [RFC] try* interfaces in posix_mq 0.8.0pre
@ 2011-02-27 11:26 Eric Wong
2011-02-27 14:44 ` Iñaki Baz Castillo
0 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2011-02-27 11:26 UTC (permalink / raw)
To: ruby.posix.mq
I just pushed this out to RubyGems.org (and ruby_posix_mq.git).
Let us know what you think, thanks!
posix_mq 0.8.0pre - kinder, gentler and less exceptional
This adds trysend, tryreceive, and tryshift interfaces to avoid
exceptions on common EAGAIN errors for non-blocking users. EAGAIN
during non-blocking messages is common when there are multiple
readers/writer threads/processes working on the same queue.
trysend is like send, except it returns true for success and false for
EAGAIN. send (still) returns nil, which I now consider a mistake but
won't change until post-1.0...
tryreceive and tryshift are like receive and shift respectively,
but they return nil for EAGAIN and the same return values
for their non-shift variants.
None of these methods call mq_setattr() beforehand to set the
non-blocking flag, it assumes the user set it once before they were ever
called and never changes it. Checking/setting the non-blocking flag
every time is needless overhead and still subject to race conditions if
multiple processes/queues keep flipping flag on the same queue
descriptor.
These interfaces are not yet final, feedback is appreciated
at ruby.posix.mq@librelist.org.
--
Eric Wong
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] try* interfaces in posix_mq 0.8.0pre
2011-02-27 11:26 [RFC] try* interfaces in posix_mq 0.8.0pre Eric Wong
@ 2011-02-27 14:44 ` Iñaki Baz Castillo
2011-02-27 15:01 ` Iñaki Baz Castillo
0 siblings, 1 reply; 7+ messages in thread
From: Iñaki Baz Castillo @ 2011-02-27 14:44 UTC (permalink / raw)
To: ruby.posix.mq
2011/2/27 Eric Wong <normalperson@yhbt.net>:
> I just pushed this out to RubyGems.org (and ruby_posix_mq.git).
> Let us know what you think, thanks!
>
> posix_mq 0.8.0pre - kinder, gentler and less exceptional
>
> This adds trysend, tryreceive, and tryshift interfaces to avoid
> exceptions on common EAGAIN errors for non-blocking users. EAGAIN
> during non-blocking messages is common when there are multiple
> readers/writer threads/processes working on the same queue.
>
> trysend is like send, except it returns true for success and false for
> EAGAIN. send (still) returns nil, which I now consider a mistake but
> won't change until post-1.0...
>
> tryreceive and tryshift are like receive and shift respectively,
> but they return nil for EAGAIN and the same return values
> for their non-shift variants.
>
> None of these methods call mq_setattr() beforehand to set the
> non-blocking flag, it assumes the user set it once before they were ever
> called and never changes it. Checking/setting the non-blocking flag
> every time is needless overhead and still subject to race conditions if
> multiple processes/queues keep flipping flag on the same queue
> descriptor.
>
> These interfaces are not yet final, feedback is appreciated
> at ruby.posix.mq@librelist.org.
Hi Eric, nice addition. In my benchmarks raising/rescuing exception is
really expensive. When a Ruby server gets congested and starts
raising/rescuing exceptions things become even worse. So I strongly
agree with your new features (similar to Gio in Unicorn, right?) :)
I will test it ASAP and comment here.
--
Iñaki Baz Castillo
<ibc@aliax.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] try* interfaces in posix_mq 0.8.0pre
2011-02-27 14:44 ` Iñaki Baz Castillo
@ 2011-02-27 15:01 ` Iñaki Baz Castillo
2011-02-27 16:15 ` Iñaki Baz Castillo
2011-02-27 22:27 ` Eric Wong
0 siblings, 2 replies; 7+ messages in thread
From: Iñaki Baz Castillo @ 2011-02-27 15:01 UTC (permalink / raw)
To: ruby.posix.mq
2011/2/27 Iñaki Baz Castillo <ibc@aliax.net>:
> I will test it ASAP and comment here.
Hi Eric, I've cloned your repo and want to test it by building and
installing the gem but have found various issues:
- File .manifest doesn't exist (touch .manifest does the work).
- gemspec doesn't include lib/posix_mq.rb so such file is not
installed and the gem cannot be loaded.
--
Iñaki Baz Castillo
<ibc@aliax.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] try* interfaces in posix_mq 0.8.0pre
2011-02-27 15:01 ` Iñaki Baz Castillo
@ 2011-02-27 16:15 ` Iñaki Baz Castillo
[not found] ` <20110227222400.GB31726@dcvr.yhbt.net>
2011-02-27 22:27 ` Eric Wong
1 sibling, 1 reply; 7+ messages in thread
From: Iñaki Baz Castillo @ 2011-02-27 16:15 UTC (permalink / raw)
To: ruby.posix.mq
2011/2/27 Iñaki Baz Castillo <ibc@aliax.net>:
>> I will test it ASAP and comment here.
>
> Hi Eric, I've cloned your repo and want to test it by building and
> installing the gem but have found various issues:
>
> - File .manifest doesn't exist (touch .manifest does the work).
> - gemspec doesn't include lib/posix_mq.rb so such file is not
> installed and the gem cannot be loaded.
Apart from these temporal issues I've tested tryreceive and trysend
and they work well (as expected).
--
Iñaki Baz Castillo
<ibc@aliax.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] try* interfaces in posix_mq 0.8.0pre
2011-02-27 15:01 ` Iñaki Baz Castillo
2011-02-27 16:15 ` Iñaki Baz Castillo
@ 2011-02-27 22:27 ` Eric Wong
1 sibling, 0 replies; 7+ messages in thread
From: Eric Wong @ 2011-02-27 22:27 UTC (permalink / raw)
To: ruby.posix.mq
Iñaki Baz Castillo <ibc@aliax.net> wrote:
> 2011/2/27 Iñaki Baz Castillo <ibc@aliax.net>:
> > I will test it ASAP and comment here.
>
> Hi Eric, I've cloned your repo and want to test it by building and
> installing the gem but have found various issues:
The gem is installable via "gem install --pre posix_mq" from
RubyGemms.org
> - File .manifest doesn't exist (touch .manifest does the work).
> - gemspec doesn't include lib/posix_mq.rb so such file is not
> installed and the gem cannot be loaded.
I use "make gem" to generate teh manifest and gem in one go.
--
Eric Wong
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC] try* interfaces in posix_mq 0.8.0pre
[not found] ` <AANLkTins0SjXeC6XBczdWakMo1e5pQSd9mo9EkjQ+E2e@mail.gmail.com>
@ 2011-02-27 23:23 ` Iñaki Baz Castillo
2011-02-27 23:51 ` Eric Wong
0 siblings, 1 reply; 7+ messages in thread
From: Iñaki Baz Castillo @ 2011-02-27 23:23 UTC (permalink / raw)
To: ruby.posix.mq
2011/2/27 Eric Wong <normalperson@yhbt.net>:
> Thanks! Any comments/suggestions on the interface?
It looks just correct IMHO. Just one question: how about << method?
Currently it behaves as POSIX_MQ#send method (raises in non-blocking
mode id it cannot write) but it returns the POSIX_MQ instance itself
when success. I suggest that it could return true on success (as you
suggest for send method).
However it could also possible that << would behave as trysend
(returning true/false), but it would break backward compatiiblity.
> Thinking about it more, I really want to make POSIX_MQ#send return
> "true" on success now (and just raise on errors) for consistency with
> POSIX_MQ#trysend.
Sure.
> I doubt anyone actually checks the return value of POSIX_MQ#send...
> Maybe I'll change it and call the next release 1.0.0.
I don't check it as for now it doesn't make sense (nil says nothing,
and I already rescue the possible exceptions).
Regards.
--
Iñaki Baz Castillo
<ibc@aliax.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] try* interfaces in posix_mq 0.8.0pre
2011-02-27 23:23 ` Iñaki Baz Castillo
@ 2011-02-27 23:51 ` Eric Wong
0 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2011-02-27 23:51 UTC (permalink / raw)
To: ruby.posix.mq
Iñaki Baz Castillo <ibc@aliax.net> wrote:
> 2011/2/27 Eric Wong <normalperson@yhbt.net>:
> > Thanks! Any comments/suggestions on the interface?
>
> It looks just correct IMHO. Just one question: how about << method?
> Currently it behaves as POSIX_MQ#send method (raises in non-blocking
> mode id it cannot write) but it returns the POSIX_MQ instance itself
> when success. I suggest that it could return true on success (as you
> suggest for send method).
> However it could also possible that << would behave as trysend
> (returning true/false), but it would break backward compatiiblity.
I actually considered doing something with POSIX_MQ#<<, but then I
realized people would expect to use it like an Array or Queue and
chain messages to it:
mq << "FOO" << "bar"
They'd still get an exception if it returned anything other than the
mq object since the << fails on symbols/nil/false.
I considered an interface like this that would work like try/catch:
mq.try do
mq << "FOO" << "bar"
end
But there's no telling at which point ("FOO" or "bar") the pushing
failed, either. So I think << is really only good for people doing
blocking mq_send() (which I mainly use myself).
Thanks for the feedback!
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-02-27 23:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-27 11:26 [RFC] try* interfaces in posix_mq 0.8.0pre Eric Wong
2011-02-27 14:44 ` Iñaki Baz Castillo
2011-02-27 15:01 ` Iñaki Baz Castillo
2011-02-27 16:15 ` Iñaki Baz Castillo
[not found] ` <20110227222400.GB31726@dcvr.yhbt.net>
[not found] ` <AANLkTins0SjXeC6XBczdWakMo1e5pQSd9mo9EkjQ+E2e@mail.gmail.com>
2011-02-27 23:23 ` Iñaki Baz Castillo
2011-02-27 23:51 ` Eric Wong
2011-02-27 22:27 ` Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/ruby_posix_mq.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).