From owner-freebsd-net@FreeBSD.ORG Mon May 21 08:16:08 2007 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 28E6716A41F for ; Mon, 21 May 2007 08:16:08 +0000 (UTC) (envelope-from niki@totalterror.net) Received: from office.suresupport.com (office.suresupport.com [213.145.98.15]) by mx1.freebsd.org (Postfix) with SMTP id 62A6B13C480 for ; Mon, 21 May 2007 08:16:07 +0000 (UTC) (envelope-from niki@totalterror.net) Received: (qmail 94540 invoked by uid 1026); 21 May 2007 07:49:24 -0000 Received: from 213.145.98.106 by office.suresupport.com (envelope-from , uid 1004) with qmail-scanner-2.01 (clamdscan: 0.88.4/1784. Clear:RC:1(213.145.98.106):. Processed in 0.091897 secs); 21 May 2007 07:49:24 -0000 Received: from unknown (HELO ?213.145.98.106?) (213.145.98.106) by office.suresupport.com with SMTP; 21 May 2007 07:49:23 -0000 Message-ID: <46514134.3020903@totalterror.net> Date: Mon, 21 May 2007 09:50:28 +0300 From: Niki Denev User-Agent: Thunderbird 1.5.0.7 (X11/20061107) MIME-Version: 1.0 To: Edwin Groothuis References: <20070521070938.GA48283@k7.mavetju> In-Reply-To: <20070521070938.GA48283@k7.mavetju> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org Subject: Re: faster /etc/services X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 May 2007 08:16:08 -0000 Edwin Groothuis wrote: > Hello, > > After the last patch I submitted with regarding to /etc/services, > I was asked if I could see if I could do something about the speed > of it. Personally I don't worry too much about it, my programs only > access getservbyname() only once per program :-) > > I did some tests with it, and at this moment you got the speed for > telnet/tcp, which lives at the beginning of /etc/services: > > telnet/tcp > 1 times - 0.000369 seconds > 10 times - 0.000583 > 100 times - 0.006279 > 1000 times - 0.059566 > 10000 times - 0.590499 > 100000 times - 5.591417 > > And dbbrowse/tcp, which lives at the end of /etc/services > > dbbrowse/tcp > 1 times - 0.001748 seconds > 10 times - 0.011674 > 100 times - 0.117460 > 1000 times - 1.172199 > 10000 times - 11.966367 > 100000 times - 120 > > So... what can we do? > > - Instead of reading and parsing /etc/services every time, read it > only once and use a cached version for all further getservbyxxx() > calls. This has a startup-penalty (once per application) and a > memory penalty, but all next calls are faster, specially for > services at the end of /etc/services. > > - Instead of reading and parsing /etc/services every time, use a > hash or btree file a la the aliases database. A hash one (first > key, next key) could be a replacement to use with getservent(), > while a btree one could be be a replacement to use with getservbyname(). > This doesn't have the startup-penalty, but the sysadmin needs to > keep track of changes in /etc/services and needs to rebuild it. > > - Instead of reading and parsing /etc/services every time, open a > socket and ask a daemon for the information. Which daemon is a > good question, but it can automatically re-read the /etc/services > file if it got changed. > > Other things to worry(?) about are YP/NIS. From what I've seen in > getservent() is that is happily intertwined with the /etc/services > code. > > Anybody with comments or suggestions from earlier threads like this? > > Edwin > I think there is cached(8) daemon in -current that does exactly this, and more. Dunno if it will get in -stable. --niki