Performance improvement for NAT in IPFIREWALL

Clement Laforet sheepkiller at
Wed Jul 2 15:42:50 PDT 2003


On Wed, 2 Jul 2003 18:39:42 -0500 (CDT)
Mike Silbersack <silby at> wrote:

> > Comments? Suggestions? Vision?
> If you have some time to throw at the problem, you might consider
> using gprof on natd in order to determine what exactly about natd is
> slow.  As is commonly mentioned, the kernel <-> userspace switch is
> probably one reason for natd's relative slowness, but I would bet that
> a decent speedup could be achieved just by optimizing natd.  Heck, it
> might be as simple as increasing the size of some hash tables or
> buffers.
> Tell us how it goes. :)

Few weeks ago, I've post a patch which impoves natd for INCOMING
connections (and breaks some options), I ran gprof to find where
natd and libalias lack of performance :
1. sendto(), recvfrom() [natd] an gettimeofday() [libalias] eat a lot of
2. [libalias] hash tables for incoming pakets is VERY poor since the
hash is based on alias address, it's mandatory for outgoing connections
I think, but for incoming redirect, it eats a lot of time (47%
according to gprof under heavy load), since the hash key is the same for
all incoming packets.
3. expire mecanisms is too slow, having small tables under heavy load
slows NAT'ing drastically. 
I had best performance with
#define LINK_TABLE_OUT_SIZE        4091
#define LINK_TABLE_IN_SIZE         8123
4. matching might be improved to.

Better with tables dedicated to redirects ("only" ~50% of CPU time, for
~55Mbp/s on a PIII 700, 90% of this CPU time was used by syscalls). 

My 2cts...

If somebody cares, I'm currently writing an in-kernel && in-ipfw NAT to
perform load balancing, if you have any suggestion, I'm all ears :)



More information about the freebsd-ipfw mailing list