Subject: Re: PCB hashing - performance improvement?
To: Dan S. Decasper <>
From: Francis Dupont <>
List: tech-net
Date: 01/15/1997 20:20:05
 In your previous mail you wrote:
   I've just saw that PCB demultiplexing for incoming IP packets is done now
   using hashing in the first place (e.g. in tcp_input call to
   in_pcbhashlookup) before the simple linear list traversal (in_pcblookup). 
   The in_pcbhashlookup calls the INPCBHASH macro which looks like this:
   #define	INPCBHASH(table, faddr, fport, laddr, lport) \
   	&(table)->inpt_hashtbl[(ntohl((faddr)->s_addr) + ntohs((fport)) +
   ntohs((lport))) & (table->inpt_hash)]
   What raised my attention are the 'ntoh' calls. These are implemented as
   function calls (assembler thought) on little-endian machines which are
   quite expensive on PENTIUMs as far as I know. 
=> it is cleary not very clever to use ntoh* functions because
they are not needed. Good point!

   I'm wondering whether somebody (most likely to person who implemented the
   hashing) did some testing with real world data on little-endian machines?
   If so, I would be very interested in the results. Does the hashing really
   provide a performance improvement?
=> it is very important if you have many connections and don't forget :
 - TCP keeps the closed connections for 2 MSL (for late packets)
 - UDP packets don't build streams then the one slot cache of BSD 4.4
 is not efficient. In fact an important part (in time) of UDP input
 processing is PCB lookup.
 - worst case with list lookup is failure.
If you need a proof you can try on a Web server, usually they have
many small connections (HTTP 1.0 opens and closes a TCP connection
per documents, it can be solved with HTTP 1.1 or T/TCP).