From: "Iñaki Baz Castillo" <ibc@aliax.net>
To: ruby.posix.mq@librelist.com
Subject: Re: Calculating the required value of "ulimit -q"
Date: Fri, 15 Jan 2010 22:27:35 +0100 [thread overview]
Message-ID: <201001152227.35691.ibc@aliax.net> (raw)
In-Reply-To: 20100115201551.GA10617@dcvr.yhbt.net
El Viernes, 15 de Enero de 2010, Eric Wong escribió:
> I don't think it makes much sense since it doesn't (and can't) take
> other queues created by the user into account. Even if mqueuefs is
> mounted under Linux, ownerships can change (and the Linux kernel tracks
> sizes for the user that created them, and this doesn't change if
> ownership changes).
>
> In my experience, trying to be "helpful" with error handling/recovery
> that may end up misleading is worse than just showing the error for the
> user to handle. I consider the best way is just to return the errno so
> the user can consult OS-specific documentation and investigate the issue.
> This is also a "startup" issue that should be quickly noticed/diagnosed
> when an application is launched.
>
> Since I realize POSIX message queues are new territory to a lot of folks
> (myself included), I've been meaning to get started on an FAQ RDoc that
> I can distribute with the gem/tarball and add to the website.
Hi Eric.
Perhaps I explained wrong what I mean. I already deal with all the possible
exceptions posix_mq raises (no enough memory, inavalid values due to user
permissions, reusage of existing mqueues so atributes cannot be changed and
so).
What I propose is really simple: a method to determine tha amount of bytes a
posix queue would require, and it just depends on 3 factors:
- maxmsg
- msgsize
- 32 or 64 bits OS
So the only I propose (read please my last mail in which I attach a working
code for posix_mq_ext.c) is a method to know how many bytes a queue would
require, so the API looks like this:
POSIX_MQ::size(msgsize, maxmsg)
example:
irb> POSIX_MQ::size(1024, 5000)
5160000
Why this could be useful? Imagine your program creates a mqueue with a
required size. Before trying to create the queue it could read the user
rlimits for mqueues and try to increase them. The following is a fragment of
my application:
MQUEUE_SIZE = POSIX_MQ::size(1024, 5000)
if ( current_rlimit = Process.getrlimit(12)[1] ) < MQUEUE_SIZE
log.info "incrementing rlimits for posix msgqueue (currently " +
"#{current_rlimit} bytes) to #{MQUEUE_SIZE} bytes"
begin
Process.setrlimit(12, MQUEUE_SIZE)
rescue Errno::EPERM
log.warn "the current user has no permissions to increase " +
"rlimits for posix msgqueue"
end
end
MQUEUE_ATTR = POSIX_MQ::Attr.new
MQUEUE_ATTR.maxmsg = 5000
MQUEUE_ATTR.msgsize = 1024
MQUEUE_ATTR.flags = 0
MQUEUE_ATTR.curmsgs = 0
begin
@mq = POSIX_MQ.new MQUEUE_NAME, IO::RDONLY | IO::CREAT | IO::EXCL,
00620, MQUEUE_ATTR
rescue Errno::ENOSYS => e
fatal "the kernel has no support for posix queue messages, enable it"
rescue Errno::EEXIST
log.warn "posix message queue already exits so cannot change its " +
"attributes"
begin
@mq = POSIX_MQ.new MQUEUE_NAME, IO::RDONLY
rescue Errno::EACCES => e
fatal "cannot open the existing posix message due to user permissions"
end
rescue Errno::EINVAL
log.warn "cannot set posix message queue attributes due to user " +
"permissions, using system default values"
@mq = POSIX_MQ.new MQUEUE_NAME, IO::RDONLY | IO::CREAT, 00620
rescue Errno::ENOMEM => e
fatal "cannot create posix message queue due to current user's rlimits"
end
It works very well :)
--
Iñaki Baz Castillo <ibc@aliax.net>
next prev parent reply other threads:[~2010-01-15 21:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-14 22:33 Calculating the required value of "ulimit -q" Iñaki Baz Castillo
2010-01-14 22:55 ` Eric Wong
2010-01-14 22:57 ` Iñaki Baz Castillo
2010-01-14 23:01 ` Iñaki Baz Castillo
2010-01-15 10:01 ` Iñaki Baz Castillo
2010-01-15 18:33 ` Iñaki Baz Castillo
2010-01-15 20:15 ` Eric Wong
2010-01-15 21:27 ` Iñaki Baz Castillo [this message]
2010-01-15 22:12 ` Eric Wong
2010-01-15 23:41 ` Iñaki Baz Castillo
2010-01-16 1:02 ` Eric Wong
2010-01-16 13:08 ` Iñaki Baz Castillo
2010-01-18 11:35 ` Eric Wong
2010-01-18 12:05 ` Iñaki Baz Castillo
2010-01-18 15:42 ` Iñaki Baz Castillo
2010-01-18 15:55 ` Iñaki Baz Castillo
2010-01-19 2:59 ` Eric Wong
2010-01-19 9:29 ` Iñaki Baz Castillo
2010-01-18 16:09 ` Iñaki Baz Castillo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/ruby_posix_mq/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201001152227.35691.ibc@aliax.net \
--to=ibc@aliax.net \
--cc=ruby.posix.mq@librelist.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).