From owner-freebsd-net@FreeBSD.ORG Mon May 21 07:27:56 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 19A2116A46C for ; Mon, 21 May 2007 07:27:56 +0000 (UTC) (envelope-from edwin@mavetju.org) Received: from mail4out.barnet.com.au (mail4.barnet.com.au [202.83.178.125]) by mx1.freebsd.org (Postfix) with ESMTP id D137213C43E for ; Mon, 21 May 2007 07:27:55 +0000 (UTC) (envelope-from edwin@mavetju.org) Received: by mail4out.barnet.com.au (Postfix, from userid 1001) id 7BAA237D6CB; Mon, 21 May 2007 17:09:39 +1000 (EST) X-Viruscan-Id: <465145B300014DD7C548AB@BarNet> Received: from mail4auth.barnet.com.au (mail4.barnet.com.au [202.83.178.125]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mail4.barnet.com.au (Postfix) with ESMTP id 48C6D422109 for ; Mon, 21 May 2007 17:09:39 +1000 (EST) Received: from k7.mavetju (k7.mavetju.org [10.251.1.18]) by mail4auth.barnet.com.au (Postfix) with ESMTP id 05D0637D69D for ; Mon, 21 May 2007 17:09:39 +1000 (EST) Received: by k7.mavetju (Postfix, from userid 1001) id E02A4205; Mon, 21 May 2007 17:09:38 +1000 (EST) Date: Mon, 21 May 2007 17:09:38 +1000 From: Edwin Groothuis To: freebsd-net@freebsd.org Message-ID: <20070521070938.GA48283@k7.mavetju> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Subject: 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 07:27:56 -0000 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 -- Edwin Groothuis | Personal website: http://www.mavetju.org edwin@mavetju.org | Weblog: http://www.mavetju.org/weblog/