From owner-freebsd-arch Tue Jan 14 3:47:58 2003 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D8DF037B405 for ; Tue, 14 Jan 2003 03:47:56 -0800 (PST) Received: from soulshock.mail.pas.earthlink.net (soulshock.mail.pas.earthlink.net [207.217.120.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id BDE3A43F43 for ; Tue, 14 Jan 2003 03:47:55 -0800 (PST) (envelope-from tlambert2@mindspring.com) Received: from stork (stork.mail.pas.earthlink.net [207.217.120.188]) by soulshock.mail.pas.earthlink.net (8.11.6+Sun/8.11.6) with ESMTP id h0EBiWH18470 for ; Tue, 14 Jan 2003 03:44:32 -0800 (PST) Received: from pool0016.cvx40-bradley.dialup.earthlink.net ([216.244.42.16] helo=mindspring.com) by stork with asmtp (SSLv3:RC4-MD5:128) (Exim 3.33 #1) id 18YPUR-0006Ry-00; Tue, 14 Jan 2003 03:44:20 -0800 Message-ID: <3E23F7B9.3FA2B37@mindspring.com> Date: Tue, 14 Jan 2003 03:42:49 -0800 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Igor Sysoev Cc: arch@FreeBSD.ORG Subject: Re: getsysfd() patch #1 (Re: Virtual memory question) References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-ELNK-Trace: b1a02af9316fbb217a47c185c03b154d40683398e744b8a449560a48fbfb5e8aeb154a94ba214e6f667c3043c0873f7e350badd9bab72f9c350badd9bab72f9c Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Igor Sysoev wrote: > I do not want to say that kernel-based timers are useless or too expensive. > > I only want to say that if application need to set and delete timers > too often then it's much better to set and delete them in user space > because most of them will never fired and calling kernel to set or cancel > them is expensive. I've personally implemented a lot -- scores -- of call-conversion schedulers in my career, including timer support. The points that Matt makes about the kqueue/select style timeout as a building block are really very valid, if you need closed to fixed intervals as possible, at least within the non-RT scheduling constraints forced on you if you are using FreeBSD (the main reason I never joined John Dyson in his "rewrite the FreeBSD kernel" crusade was that he had no intention of dealing with RT issues, only SMP issues). > > for timers, they work better if they are cancelled before they > > ever fire, because cancellation is by reference, whereas firing > > is by traversal. > > In server that I'm deleloping I use delta value between timeouts > so firing is cheap as cancelation. Firing timers are on the head > of queue. This only works for fixed intervals timers, or variable interval timers with very high insertion costs -- effectively, you must implement in terms of absolute monotonically increasing tick count, and then traverse the outstanding list to perform an order insertion. The best case you can get is hashed vector insertion, where you must hit the hash and then traverse to the end of the list or the next hash bucket... effectively, a skiplist. This works OK for timers that are inserted, and left there, but it sucks for one-shots, it sucks for timers that are going to be deleted (you pay your cost up front), and it sucks for repeating timers (you have to pay the insertion cost each time). So basically, it doesn't answer two of the three types of timers that Matt desribed. Note that just going ahead and implementing this way sucks, too. Better to implement fixed interval event list heads that were inserted into a btree or a TST for the first event, and then tail-inserted for each timer request, so you can traverse from the head and get a 100% hit rate, minus 1, for an arbitrary number of timer events. Matt's suggested facilities have this same overhead problem, FWIW. > I did not argue against previous, current or future implementation > of timers in the kernel. I mean that if user-level application > need to set thousands timers (i.e. web server with thousands > connections) it's better to manage them in user space and set > only one the most early timer in the kernel via kqueue/select/poll. Batch them agross kqueue calls, and amortize the costs. Pushing down 100 timers with 1 call costs only 1/100th of a sytem call per timer. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message