close() slow on socketpairs?

From: Dan Kegel (dank@alumni.caltech.edu)
Date: Tue Oct 17 2000 - 00:09:03 EST


I wrote a little benchmark to call either pipe() or socketpair()
8000 times, then close() on all the fds produced by pipe or socketpair.
On both 2.2.14 and 2.2.16, pipe and socketpair are nice and speedy.
close() is fine for pipes, but at 8000 socketpairs, each call to close()
takes 14 *milliseconds* at 100% cpu usage. What's up with that?

- Dan

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
main()
{
        int i;
        int fds[16000];
        int n = 8000;
        time_t start = time(0);
        for (i=0; i<n; i+= 2)
                if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds + i))
                        exit(1);
        printf("Opening %d socketpairs took %d seconds\n", n, time(0) - start);
        start = time(0);
        for (i=0; i<n; i+= 2)
                if (close(fds[i]) || close(fds[i+1]))
                        exit(1);
        printf("Closing %d pipes took %d seconds\n", n, time(0) - start);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Oct 23 2000 - 21:00:10 EST