YP services.byname

Douglas P. Kingston dpk at morgan.com
Thu Nov 16 05:10:10 AEST 1989


In fact, the handling of the "services" table by YP has never been correct
in sun distributed YP.  You are correct, services.byname should really be
services.byport, and services.byname should have been created and used.
Currently, if you do a yp lookup for "service/proto" (the most common
lookup when making connections) it has to do a linear search for the
entry.  THIS IS DUMB.  I reported the bug years ago when I was at BRL.  We
fixed it on our Goulds that were using Sun based code.  It made quite a
difference...

For your amusement here are two simple example programs that do yp service
lookups by port and name and the timing for each: The first is with no
args and gives and idea of the startup overhead.  The next two look up the
same 4 things by port and name.

The timings come from "resource", which is an enhanced version of the
"time" program.  It prints out the contents of the resource structure from
wait3().

Executive summary:

Lookups by port number are really fast and take 1 rpc for the portmapping
and then 1 rpc for each lookup, makeing it an Order(N) algorithm.  Lookups
by name require 1 rpc for the portmapping and then up to N rpc's to
linearly search the ypmap for the entry.  This make the algorithm
Order(n^2).

Note the number of messages sent in the following printouts.  I have
omitted the parts of the resource structure that are not relevant.

Use the programs below to amaze and disgust your friends and to embarrass
your vendor.  Lets get this fixed!

For a good laugh on a Sun, run trace on these two yp programs...

	-Doug-
	<dpk at morgan.com>

dpk) resource getservbyport 25/tcp 21/tcp 123/udp 520/udp
25:     smtp
21:     ftp
123:    ntp
520:    route
Time:    0.04 real,  0.00 user CPU,  0.01 sys CPU
Messages:      5 received,     5 sent
Context Switches:  35 voluntary,  7 involuntary
dpk) 
dpk) resource getservbyname smtp/tcp ftp/tcp ntp/udp route/udp
smtp:   25
ftp:    21
ntp:    123
route:  520
Time:    1.06 real,  0.01 user CPU,  0.04 sys CPU
Messages:    103 received,   103 sent
Context Switches:  230 voluntary,  185 involuntary
dpk) 

And now the real nasty, a service that does not exist:

dpk) resource getservbyname foo/tcp
foo:    *
Time:    1.04 real,  0.01 user CPU,  0.03 sys CPU
Messages:     81 received,    81 sent
Context Switches:  200 voluntary,  180 involuntary
dpk)
dpk) resource getservbyport 456/tcp
456:    *
Time:    0.03 real,  0.00 user CPU,  0.00 sys CPU
Messages:      2 received,     2 sent
Context Switches:  29 voluntary,  3 involuntary

Ed's Note: example programs placed in archives

FTP:	Hostname : titan.rice.edu (128.42.30.1)
	Directory: sun-source
	Filename : ypexamples.c

Archive Server Address: archive-server at rice.edu
Archive Server Command: get sun-source ypexamples.c



More information about the Comp.sys.sun mailing list