[dbench @ cvs-1:mbp-20010730222405-m2ccq4k1m91qrrcl]
authormbp <mbp@blu>
Mon, 30 Jul 2001 22:24:05 +0000 (22:24 +0000)
committermbp <mbp@blu>
Mon, 30 Jul 2001 22:24:05 +0000 (22:24 +0000)
Add the -c option (to set the location of client.txt) and -s to do
synchronous IO, simulating NFS or SMB with strict locking.

INSTALL [new file with mode: 0644]
README
child.c
dbench.c
fileio.c
io.c
proto.h
util.c

diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..2c22208
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,11 @@
+Quick guide to installing/running dbench & co:
+
+1) Run 'make' in the source directory
+
+2) cd into the directory in which you wish to run the benchmark
+
+3) either copy client.txt into that directory, or specify it's path
+with -c
+
+4) run the appropriate benchmark program
+
diff --git a/README b/README
index 4ef7acb77820998e9def6cb15225109abee13416..16b4cb345536b501e58185adeee32b55228180c7 100644 (file)
--- a/README
+++ b/README
@@ -30,6 +30,9 @@ that a netbench client does in a typical netbench run. They parse
 client.txt and use it to produce the same load without having to buy a
 huge lab. They can simulate any number of simultaneous clients.
 
+client.txt must either be in the working directory, or specified on
+the command line with the -c option.
+
 dbench
 ------
 
diff --git a/child.c b/child.c
index 25d56e9b5465e11db5d12000651b11ba35e08e1f..16e9ab06e2a2f9571d73b40724757efb736d3ff9 100644 (file)
--- a/child.c
+++ b/child.c
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+/* This file links against either fileio.c to do operations against a
+   local filesystem (making dbench), or sockio.c to issue SMB-like
+   command packets over a socket (making tbench).
+
+   So, the pattern of operations and the control structure is the same
+   for both benchmarks, but the operations performed are different.
+*/
+
 #include "dbench.h"
 
 int line_count=0;
 
+char *client_filename = "client.txt";
+
+
 static int sigsegv(int sig)
 {
        char line[200];
@@ -31,6 +42,21 @@ static int sigsegv(int sig)
        exit(1);
 }
 
+
+FILE * open_client_dump(void)
+{
+       FILE            *f;
+
+       if ((f = fopen(client_filename, "rt")) != NULL)
+               return f;
+
+       fprintf(stderr,
+               "dbench: error opening %s: %s", client_filename,
+               strerror(errno));
+
+       return NULL;
+}
+
 void child_run(int client)
 {
        int i;
@@ -44,7 +70,7 @@ void child_run(int client)
 
        sprintf(cname,"CLIENT%d", client);
 
-       f = fopen("client.txt", "r");
+       f = open_client_dump();
 
        if (!f) {
                perror("client.txt");
index 0abbe669cd47e898de79c375b3676357f48afbc7..f63759ddb49e8e137f33b32ea8482ae129ffbf3c 100644 (file)
--- a/dbench.c
+++ b/dbench.c
@@ -1,6 +1,8 @@
 /* 
-   dbench version 1
-   Copyright (C) Andrew Tridgell 1999
+   dbench version 1.01
+   
+   Copyright (C) by Andrew Tridgell <tridge@samba.org> 1999, 2001
+   Copyright (C) 2001 by Martin Pool <mbp@samba.org>
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+/* TODO: We could try allowing for different flavours of synchronous
+   operation: data sync and so on.  Linux apparently doesn't make any
+   distinction, however, and for practical purposes it probably
+   doesn't matter.  On NFSv4 it might be interesting, since the client
+   can choose what kind it wants for each OPEN operation. */
+
 #include "dbench.h"
 
+int sync_ops = 0;
+
 static void sigcont(void)
 {
 }
 
-/* this creates the specified number of child processes and runs fn() in all of them */
+/* this creates the specified number of child processes and runs fn()
+   in all of them */
 static double create_procs(int nprocs, void (*fn)(int ))
 {
        int i, status;
@@ -36,6 +47,13 @@ static double create_procs(int nprocs, void (*fn)(int ))
 
        synccount = 0;
 
+       if (nprocs < 1) {
+               fprintf(stderr,
+                       "create %d procs?  you must be kidding.\n",
+                       nprocs);
+               return 1;
+       }
+
        child_status = (volatile int *)shm_setup(sizeof(int)*nprocs);
        if (!child_status) {
                printf("Failed to setup shared memory\n");
@@ -83,24 +101,65 @@ static double create_procs(int nprocs, void (*fn)(int ))
 }
 
 
+static void show_usage(void)
+{
+       printf("usage: dbench [OPTIONS] nprocs\n"
+              "options:\n"
+              "  -c CLIENT.TXT    set location of client.txt\n"
+              "  -s               synchronous mode (like NFS2)\n");
+       exit(1);
+}
+
 
 
- int main(int argc, char *argv[])
+int process_opts(int argc, char **argv,
+                int *nprocs)
 {
+       int c;
+       extern char *client_filename;
+       extern int sync_ops;
        extern char *server;
-       int nprocs;
-       double t;
 
-       if (argc < 2) {
-               printf("usage: dbench nprocs\n");
-               exit(1);
-       }
+       while ((c = getopt(argc, argv, "c:s")) != -1) 
+               switch (c) {
+               case 'c':
+                       client_filename = optarg;
+                       break;
+               case 's':
+                       sync_ops = 1;
+                       break;
+               case '?':
+                       if (isprint (optopt))
+                               fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+                       else
+                               fprintf (stderr,
+                                        "Unknown option character `\\x%x'.\n",
+                                        optopt);
+                       return 0;
+               default:
+                       abort ();
+               }
+       
+       if (!argv[optind])
+               return 0;
+       
+       *nprocs = atoi(argv[optind++]);
 
-       nprocs = atoi(argv[1]);
+       if (argv[optind])
+               server = argv[optind++];
 
-       if (argc > 2) {
-               server = argv[2];
-       }
+       return 1;
+}
+
+
+
+ int main(int argc, char *argv[])
+{
+       int nprocs;
+       double t;
+
+       if (!process_opts(argc, argv, &nprocs))
+               show_usage();
 
        t = create_procs(nprocs, child_run);
 
@@ -109,7 +168,8 @@ static double create_procs(int nprocs, void (*fn)(int ))
            sniff that was used to produce client.txt. That run used 2
            clients and ran for 660 seconds to produce a result of
            4MBit/sec. */
-       printf("Throughput %g MB/sec (NB=%g MB/sec  %g MBit/sec)\n", 
-              132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t);
+       printf("Throughput %g MB/sec (NB=%g MB/sec  %g MBit/sec)%s\n", 
+              132*nprocs/t, 0.5*0.5*nprocs*660/t, 2*nprocs*660/t,
+              sync_ops ? " (sync mode)" : "");
        return 0;
 }
index f6ad0426327c296b9e5d4530af533ba6f9979c6a..bc9a0ad6b7f9e679f77d9fe6caac8545d4af8bb4 100644 (file)
--- a/fileio.c
+++ b/fileio.c
@@ -25,6 +25,7 @@ static char buf[70000];
 extern int line_count;
 
 char *server = NULL;
+extern int sync_ops;
 
 static struct {
        int fd;
@@ -67,6 +68,9 @@ void nb_open(char *fname, int handle, int size)
 
        if (size == 0) flags |= O_TRUNC;
 
+       if (sync_ops)
+               flags |= O_SYNC;
+       
        fd = open(fname, flags, 0600);
        if (fd == -1) {
                printf("(%d) open %s failed for handle %d (%s)\n", 
diff --git a/io.c b/io.c
index e244b825a73452f6ca76c63fc263c5314c52c6ec..c76e684185b938b6d2f23904a1618017d17fc1aa 100644 (file)
--- a/io.c
+++ b/io.c
@@ -1,3 +1,26 @@
+/* 
+   dbench version 1.01
+   
+   Copyright (C) by Andrew Tridgell <tridge@samba.org> 1999, 2001
+   Copyright (C) 2001 by Martin Pool <mbp@samba.org>
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/* Wrappers for system calls that catch errors. */
+
 #include "dbench.h"
 
 #define MAX_FILES 1000
diff --git a/proto.h b/proto.h
index 4500718e4c4443b875d4bb181a5d0fd6b82bbae4..eaba8c4595d96a0bb34c059996c41df5cd5ceca6 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -1,6 +1,8 @@
 /* This file is automatically generated with "make proto". DO NOT EDIT */
 
 void child_run(int client);
+int process_opts(int argc, char **argv,
+                int *nprocs);
 void nb_setup(int client);
 void nb_unlink(char *fname);
 void expand_file(int fd, int size);
@@ -13,6 +15,17 @@ void nb_rmdir(char *fname);
 void nb_rename(char *old, char *new);
 void nb_stat(char *fname, int size);
 void nb_create(char *fname, int size);
+void do_unlink(char *fname);
+void expand_file(int fd, int size);
+void do_open(char *fname, int handle, int size);
+void do_write(int handle, int size, int offset);
+void do_read(int handle, int size, int offset);
+void do_close(int handle);
+void do_mkdir(char *fname);
+void do_rmdir(char *fname);
+void do_rename(char *old, char *new);
+void do_stat(char *fname, int size);
+void do_create(char *fname, int size);
 void nb_setup(int client);
 void nb_unlink(char *fname);
 void nb_open(char *fname, int handle, int size);
@@ -29,6 +42,7 @@ int open_socket_out(char *host, int port);
 void set_socket_options(int fd, char *options);
 int read_sock(int s, char *buf, int size);
 int write_sock(int s, char *buf, int size);
+int main(int argc, char *argv[]);
 void start_timer(void);
 double end_timer(void);
 void *shm_setup(int size);
diff --git a/util.c b/util.c
index 7819483b41dc19941f36d43dd44cedb0e64ba215..1b35649feed0cc939cb55ef88d5117a1d43e0133 100644 (file)
--- a/util.c
+++ b/util.c
@@ -51,7 +51,9 @@ void *shm_setup(int size)
 
        shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
        if (shmid == -1) {
-               printf("can't get shared memory\n");
+               printf("can't get private shared memory of %d bytes: %s\n",
+                      size, 
+                      strerror(errno));
                exit(1);
        }
        ret = (void *)shmat(shmid, 0, 0);