Rename NR_THREADS to CONNECTIONS and get the value form an environment
variable. Change the test script to test multiple connections.

An example run:

$ ./synch-parallel.sh
Connections: 1
Request size: 4096
thread 0: finished OK in 10.000000 seconds
TLS: disabled
bytes sent: 996638720 (95.0469 MiB/s)
bytes received: 995004416 (94.891 MiB/s)
I/O requests: 486241 (48624.1 IOPS)

Connections: 1
Request size: 262144
thread 0: finished OK in 10.000047 seconds
TLS: disabled
bytes sent: 9216720896 (878.975 MiB/s)
bytes received: 9266528256 (883.725 MiB/s)
I/O requests: 70508 (7050.8 IOPS)

Connections: 2
Request size: 4096
thread 0: finished OK in 10.000015 seconds
thread 1: finished OK in 10.000012 seconds
TLS: disabled
bytes sent: 1681920000 (160.4 MiB/s)
bytes received: 1680896000 (160.303 MiB/s)
I/O requests: 821000 (82100 IOPS)

Connections: 2
Request size: 262144
thread 0: finished OK in 10.000048 seconds
thread 1: finished OK in 10.000060 seconds
TLS: disabled
bytes sent: 12331515904 (1176.03 MiB/s)
bytes received: 12310282240 (1174 MiB/s)
I/O requests: 94001 (9400.1 IOPS)

Connections: 4
Request size: 4096
thread 3: finished OK in 10.000004 seconds
thread 0: finished OK in 10.000029 seconds
thread 2: finished OK in 10.000011 seconds
thread 1: finished OK in 10.000025 seconds
TLS: disabled
bytes sent: 2024407040 (193.062 MiB/s)
bytes received: 2024652800 (193.086 MiB/s)
I/O requests: 988540 (98854 IOPS)

Connections: 4
Request size: 262144
thread 2: finished OK in 10.000300 seconds
thread 1: finished OK in 10.000360 seconds
thread 0: finished OK in 10.000340 seconds
thread 3: finished OK in 10.000325 seconds
TLS: disabled
bytes sent: 12098994176 (1153.85 MiB/s)
bytes received: 12016680960 (1146 MiB/s)
I/O requests: 91994 (9199.4 IOPS)

Connections: 8
Request size: 4096
thread 0: finished OK in 10.000002 seconds
thread 1: finished OK in 10.000050 seconds
thread 5: finished OK in 10.000098 seconds
thread 3: finished OK in 10.000013 seconds
thread 6: finished OK in 10.000239 seconds
thread 4: finished OK in 10.000126 seconds
thread 2: finished OK in 10.000068 seconds
thread 7: finished OK in 10.000215 seconds
TLS: disabled
bytes sent: 2110287872 (201.253 MiB/s)
bytes received: 2105614336 (200.807 MiB/s)
I/O requests: 1029273 (102927 IOPS)

Connections: 8
Request size: 262144
thread 7: finished OK in 10.000441 seconds
thread 6: finished OK in 10.000351 seconds
thread 2: finished OK in 10.000572 seconds
thread 0: finished OK in 10.000676 seconds
thread 3: finished OK in 10.000772 seconds
thread 5: finished OK in 10.000839 seconds
thread 4: finished OK in 10.000968 seconds
thread 1: finished OK in 10.000861 seconds
TLS: disabled
bytes sent: 11867783168 (1131.8 MiB/s)
bytes received: 11875647488 (1132.55 MiB/s)
I/O requests: 90574 (9057.4 IOPS)

Signed-off-by: Nir Soffer <[email protected]>
---
 tests/synch-parallel.c  | 30 ++++++++++++++++++++----------
 tests/synch-parallel.sh | 19 ++++++++++++-------
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/tests/synch-parallel.c b/tests/synch-parallel.c
index d6ab1df..099a906 100644
--- a/tests/synch-parallel.c
+++ b/tests/synch-parallel.c
@@ -33,154 +33,164 @@
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
 #include <sys/time.h>
 
 #include <pthread.h>
 
 #include <libnbd.h>
 
 #include "byte-swapping.h"
 
 /* We keep a shadow of the RAM disk so we can check integrity of the data. */
 static char *ramdisk;
 
 /* This is also defined in synch-parallel.sh and checked here. */
 #define EXPORTSIZE (8*1024*1024)
 
 /* How long (seconds) that the test will run for. */
 #define RUN_TIME 10
 
-/* Number of threads. */
-#define NR_THREADS 8
+#define MAX_CONNECTIONS 8
 
 #define KiB 1024
 #define MiB (1024*KiB)
 
 #define MICROSECONDS 1000000
 
 /* Unix socket. */
 static const char *unixsocket;
 
 static long request_size;
+static long connections;
 
 struct thread_status {
-  size_t i;                     /* Thread index, 0 .. NR_THREADS-1 */
+  size_t i;                     /* Thread index, 0 .. connections-1 */
   uint64_t offset, length;      /* Area assigned to this thread. */
   int status;                   /* Return status. */
   unsigned requests;            /* Total number of requests made. */
   uint64_t bytes_sent, bytes_received; /* Bytes sent and received by thread. */
 };
 
 static void *start_thread (void *arg);
 
 static inline int64_t
 microtime (void)
 {
   struct timeval tv;
 
   gettimeofday(&tv, NULL);
   return tv.tv_sec * MICROSECONDS + tv.tv_usec;
 }
 
 static long
 getenv_long(const char *name, long defval)
 {
   const char *value;
   char *end;
   long res;
 
   value = getenv (name);
   if (value == NULL)
     return defval;
 
   res = strtol(value, &end, 10);
   if (*end != '\0' || end == value) {
     fprintf (stderr, "Invalid value for %s: '%s'\n", name, value);
     exit (EXIT_FAILURE);
   }
 
   return res;
 }
 
 int
 main (int argc, char *argv[])
 {
-  pthread_t threads[NR_THREADS];
-  struct thread_status status[NR_THREADS];
+  pthread_t threads[MAX_CONNECTIONS];
+  struct thread_status status[MAX_CONNECTIONS];
   size_t i;
   int err;
   unsigned requests, errors;
   uint64_t bytes_sent, bytes_received;
 
   if (argc != 2) {
     fprintf (stderr, "%s socket\n", argv[0]);
     exit (EXIT_FAILURE);
   }
   unixsocket = argv[1];
 
+  connections = getenv_long ("CONNECTIONS", 8);
+  if (connections < 1 ||
+      connections > MAX_CONNECTIONS ||
+      EXPORTSIZE % connections != 0) {
+    fprintf (stderr,
+             "Invalid CONNECTIONS environment variable: %ld\n",
+             connections);
+    exit (EXIT_FAILURE);
+  }
+
   request_size = getenv_long ("REQUEST_SIZE", 16*KiB);
   if (request_size < 4*KiB ||
       request_size > 512*KiB ||
-      (EXPORTSIZE / NR_THREADS) % request_size != 0) {
+      (EXPORTSIZE / connections) % request_size != 0) {
     fprintf (stderr,
              "Invalid REQUEST_SIZE environment variable: %ld\n",
              request_size);
     exit (EXIT_FAILURE);
   }
 
   srand ((microtime () / MICROSECONDS) + getpid ());
 
   /* Initialize the RAM disk with the initial data from
    * nbdkit-pattern-filter.
    */
   ramdisk = malloc (EXPORTSIZE);
   if (ramdisk == NULL) {
     perror ("calloc");
     exit (EXIT_FAILURE);
   }
   for (i = 0; i < EXPORTSIZE; i += 8) {
     uint64_t d = htobe64 (i);
     memcpy (&ramdisk[i], &d, sizeof d);
   }
 
   /* Start the worker threads. */
-  for (i = 0; i < NR_THREADS; ++i) {
+  for (i = 0; i < connections; ++i) {
     status[i].i = i;
-    status[i].offset = i * EXPORTSIZE / NR_THREADS;
-    status[i].length = EXPORTSIZE / NR_THREADS;
+    status[i].offset = i * EXPORTSIZE / connections;
+    status[i].length = EXPORTSIZE / connections;
     status[i].status = 0;
     status[i].requests = 0;
     status[i].bytes_sent = status[i].bytes_received = 0;
     err = pthread_create (&threads[i], NULL, start_thread, &status[i]);
     if (err != 0) {
       errno = err;
       perror ("pthread_create");
       exit (EXIT_FAILURE);
     }
   }
 
   /* Wait for the threads to exit. */
   errors = 0;
   requests = 0;
   bytes_sent = bytes_received = 0;
-  for (i = 0; i < NR_THREADS; ++i) {
+  for (i = 0; i < connections; ++i) {
     err = pthread_join (threads[i], NULL);
     if (err != 0) {
       errno = err;
       perror ("pthread_join");
       exit (EXIT_FAILURE);
     }
     if (status[i].status != 0) {
       fprintf (stderr, "thread %zu failed with status %d\n",
                i, status[i].status);
       errors++;
     }
     requests += status[i].requests;
     bytes_sent += status[i].bytes_sent;
     bytes_received += status[i].bytes_received;
   }
 
   free (ramdisk);
 
   /* Print some stats. */
   printf ("TLS: %s\n",
diff --git a/tests/synch-parallel.sh b/tests/synch-parallel.sh
index 0ca9060..ae35dd1 100755
--- a/tests/synch-parallel.sh
+++ b/tests/synch-parallel.sh
@@ -1,28 +1,33 @@
 #!/usr/bin/env bash
 # nbd client library in userspace
 # Copyright (C) 2019 Red Hat Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
 # version 2 of the License, or (at your option) any later version.
 #
 # This library 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
 # Lesser General Public License for more details.
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 # Test synchronous parallel high level API requests.
 
-for request_size in 4096 262144; do
-    echo "Request size: $request_size"
-    REQUEST_SIZE=$request_size nbdkit -U - \
-           --filter=cow \
-           pattern size=8M \
-           --run '$VG ./synch-parallel $unixsocket'
-    echo
+for connections in 1 2 4 8; do
+    for request_size in 4096 262144; do
+        echo "Connections: $connections"
+        echo "Request size: $request_size"
+        CONNECTIONS=$connections \
+        REQUEST_SIZE=$request_size \
+        nbdkit -U - \
+               --filter=cow \
+               pattern size=8M \
+               --run '$VG ./synch-parallel $unixsocket'
+        echo
+    done
 done
-- 
2.31.1

_______________________________________________
Libguestfs mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to