From owner-freebsd-hackers@FreeBSD.ORG Sun Apr 11 22:58:49 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6C38016A4CE for ; Sun, 11 Apr 2004 22:58:49 -0700 (PDT) Received: from smtp.netli.com (ip2-pal-focal.netli.com [66.243.52.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1950F43D31 for ; Sun, 11 Apr 2004 22:58:49 -0700 (PDT) (envelope-from vlm@netli.com) Received: (qmail 9034 invoked by uid 84); 12 Apr 2004 05:58:46 -0000 Received: from vlm@netli.com by l3-1 with qmail-scanner-0.96 (uvscan: v4.1.40/v4121. . Clean. Processed in 0.179402 secs); 12 Apr 2004 05:58:46 -0000 Received: from unknown (HELO netli.com) (172.17.1.12) by mx01-pal-lan.netli.lan with SMTP; 12 Apr 2004 05:58:46 -0000 Message-ID: <407A3076.8030005@netli.com> Date: Sun, 11 Apr 2004 23:00:22 -0700 From: Lev Walkin Organization: Netli, Inc. User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.6) Gecko/20040307 X-Accept-Language: ru, en-us, en MIME-Version: 1.0 To: dudu@diaspar.rdsnet.ro References: <20040412011216.P7661@qvnfcne.eqfarg.eb> In-Reply-To: <20040412011216.P7661@qvnfcne.eqfarg.eb> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org Subject: Re: SYSV message queues X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Apr 2004 05:58:49 -0000 Vlad GALU wrote: > Hello. I have the following scenario: one process that creates a > message queue and goes through it in a loop, together with another process > that inserts various messages into the queue. What I wish is for the > 'listening' process to be able to fully process the queue at a fixed > amount of time. In short, I'd like msgrcv() to iterate throught the queue > and visit every element in a single run. That set of operations being done > periodically. > Do you find this possible ? I'm quite puzzled here. I first tried > inserting a sleep() call in my queue processing loop but then I noticed > that it had a bad effect. It's true that I haven't read the man page very > carefully the first time. I'll blame it on the hurry. > > However, while writing this message, an idea occured to me. What > if I write the processing loop as follows: > > -- cut here -- > int i; > while (1) { > i = 0; > msgctl(queueid, IPC_STAT, &queuestat); > while (i <= queuestat.msg_qnum) { > msgrcv(queueid, &message, sizeof(message), 0, 0); > process_message(message); > i++; > } > sleep(5); > } > -- and here -- > > Does this look pheasible ? I'm expecting an injection of about > 100k messages per second or even more. There'll be quite a lot of > unprocessed ones at the end of each run, I suppose. I'll measure the average time spent for > one run and decide on the sleep interval. Did you try to grok what the msgrcv() call is supposed to return? Specifically, read about -1/EAGAIN and IPC_NOWAIT. Then remove sleep(). > However, does anyone have a better design ? Yes. Use sockets. Obsolescent Unix IPC Methods http://www.catb.org/~esr/writings/taoup/html/ch07s03.html#id2923376 -- Lev Walkin vlm@netli.com