[comp.unix.wizards] Yellow Pages getservby???? is a pig

dpk@BRL.ARPA (Doug Kingston) (11/18/86)

Dear Sun Microsystems:

	*&!^*^%!$&%% Yellow Pages.	(venting anger at YP)

	This is to inform you of a severe performance loser in
your systems running release 3.0.  Other systems may also be
effected.  The routine getservby???? does not do keyed lookups
in the yellow pages.  The program getservbyport is one I wrote
to demonstrated the problem in a controlled manner:

#include <netdb.h>

main(argc, argv)
char **argv;
{
	struct servent *sp;
	int i;

	setservent(1);
	for (i = 1; i < argc; i++) {
		if ((sp = getservbyport(htons(atoi(argv[i])), "tcp")) == 0)
			printf("%d:\t*\n", atoi(argv[i]));
		else
			printf("%d:\t%s\n", atoi(argv[i]),
				sp->s_name ? sp->s_name : "?");
	}
	exit(0);
}

The results are really depressing.  The following script
shows the problem in detail.  The second invocation
("xgetservbyport") is the same program but compiled with
a reworked getservent.c that acutally uses YP the way it
was intended.  This entailed changes to the /etc/yp/Makefile
as well.  The program "resource" is like "time" but more
informative.  Note the number of datagrams (messages)
that were necessary by the old version that was in fact
doing a while(sp = getservent()); loop.

Exhibit A:

Script started on Tue Nov 18 02:48:19 1986
brl-sem)
brl-sem) resource getservbyport 19 19 19 19 19 19 19 19 19 19
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
Time:  real 17.04,   user CPU 2.02,   sys CPU 4.06
Memory:  ixrss 2887,   idrss 4598,   isrss 0
Paging:  reclaims 0,   faults 0,   swaps 0
Block I/O:   9 in,   2 out
Messages:   623 sent,  623 received
Signals:  0
Context Switches:  631 voluntary,  1424 involuntary
brl-sem)
brl-sem)
brl-sem) resource getservbyport 19 19 19 19 19 19 19 19 19 19
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
19:	chargen
Time:  real 1.00,   user CPU 0.00,   sys CPU 0.04
Memory:  ixrss 160,   idrss 120,   isrss 0
Paging:  reclaims 0,   faults 0,   swaps 0
Block I/O:   11 in,   4 out
Messages:   13 sent,  13 received
Signals:  0
Context Switches:  24 voluntary,  64 involuntary
brl-sem) exit

I hope this is fixed in release 3.2.  I know this bug exists
in the current software of at least two (2) of your fellow
vendors who have licensed NFS from you.  You are welcome to
my fixes if you want them as are others.

I am also unhappy that if you care to use yellow pages
at all you MUST support /etc/services, /etc/protocols and
others.  You have NO choice.  In checking for the yellow
pages (in yelloup()) you implicitly assume if its up, it
will support these tables.  I know this is not fixed in 3.2.

I am hoping that my fixes reduces the CPU overhead of ypserv
to a resonable level or we are going to have to pitch YP
altogether.  Does anyone else have performance fixes for YP?

Still caring about performance,
	-Doug-


Internet:  <DPK @ BRL.ARPA>
Phone:  (301)-278-6678
Postal:
  Doug Kingston
  Computer Science and Mathematics Branch
  Systems Engineering and Concepts Analysis Division
  U.S. Army Ballistic Research Laboratory
  Attn: SLCBR-SECAD (Kingston)
  APG, MD  21005-5066