Re: Please help me tune NetBSD for bulk.fefe.de/scalability/

Niels Provos <[email protected]>
Newsgroups gmane.os.netbsd.devel.performance
Message-ID <[email protected]>
Here is the benchmark that I used way back to measure performance of
file descriptor allocation.  Hope it helps.

Niels.

#include <stdio.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/resource.h>

#define NFILES	60000
#define TRIALS	10000L
 
int files[NFILES];

#define ssec ru_stime.tv_sec
#define usec ru_utime.tv_sec
#define susec ru_stime.tv_usec
#define uusec ru_utime.tv_usec

void
massage (int fd)
{
  u_long i;
  struct rusage t1, t2;

  getrusage(RUSAGE_SELF, &t1);

  for (i = 0; i < TRIALS; i++) {
    close (files[0]);
    close (files[fd]);
    files[0] = open("/etc/passwd", O_RDONLY, 0);
    if (files[0] == -1) {
      perror("massage: open(0)");
      exit (0);
    }
    files[fd] = open("/etc/passwd", O_RDONLY, 0);
    if (files[fd] == -1) {
      perror("massage: open");
      exit (0);
    }
  }
    
  getrusage(RUSAGE_SELF, &t2);

  printf ("%d %lf\n", fd, (double)(t2.ssec + t2.usec - t1.ssec - t1.usec) + 
	  (double)(t2.susec + t2.uusec - t1.susec - t1.uusec)/1000000);

}

int
main (void)
{
  int i;
	
  for (i = 0; i < NFILES; i++) {
    files[i] = open("/etc/passwd", O_RDONLY, 0);
	printf ("%d: %d\n", i, files[i]);
    if (files[i] == -1) {
      perror("open");
      exit (0);
    }
  }

  for (i = 1; i < NFILES; i += 2000)
    massage (i);

  return 1;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.