Date: Mon, 21 May 2007 17:09:38 +1000 From: Edwin Groothuis <edwin@mavetju.org> To: freebsd-net@freebsd.org Subject: faster /etc/services Message-ID: <20070521070938.GA48283@k7.mavetju>
next in thread | raw e-mail | index | archive | help
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/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070521070938.GA48283>