Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 May 2007 09:50:28 +0300
From:      Niki Denev <niki@totalterror.net>
To:        Edwin Groothuis <edwin@mavetju.org>
Cc:        freebsd-net@freebsd.org
Subject:   Re: faster /etc/services
Message-ID:  <46514134.3020903@totalterror.net>
In-Reply-To: <20070521070938.GA48283@k7.mavetju>
References:  <20070521070938.GA48283@k7.mavetju>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46514134.3020903>