/* run a test that simulates an approximate netbench client load */ bool torture_nbench(struct torture_context *torture) { bool correct = true; int torture_nprocs = torture_setting_int(torture, "nprocs", 4); struct smbcli_state *cli; const char *p; read_only = torture_setting_bool(torture, "readonly", false); nb_max_retries = torture_setting_int(torture, "nretries", 1); p = torture_setting_string(torture, "timelimit", NULL); if (p && *p) { timelimit = atoi(p); } warmup = timelimit / 20; loadfile = torture_setting_string(torture, "loadfile", NULL); if (!loadfile || !*loadfile) { loadfile = "client.txt"; } if (torture_nprocs > 1) { if (!torture_open_connection(&cli, torture, 0)) { return false; } if (!read_only && !torture_setup_dir(cli, "\\clients")) { return false; } } nbio_shmem(torture_nprocs, timelimit, warmup); printf("Running for %d seconds with load '%s' and warmup %d secs\n", timelimit, loadfile, warmup); /* we need to reset SIGCHLD here as the name resolution library may have changed it. We rely on correct signals from childs in the main torture code which reaps children. This is why smbtorture BENCH-NBENCH was sometimes failing */ signal(SIGCHLD, SIG_DFL); signal(SIGALRM, nb_alarm); alarm(1); torture_create_procs(torture, run_netbench, &correct); alarm(0); if (!read_only && torture_nprocs > 1) { smbcli_deltree(cli->tree, "\\clients"); } printf("\nThroughput %g MB/sec\n", nbio_result()); return correct; }
void nb_alarm(int sig) { int i; int lines=0; double t; int in_warmup = 0; int num_connected = 0; if (nbio_id != -1) return; for (i=0;i<nprocs;i++) { if (children[i].connected) { num_connected++; } if (children[i].bytes == 0) { in_warmup = 1; } lines += children[i].line; } t = timeval_elapsed(&tv_start); if (!in_warmup && warmup>0 && t > warmup) { tv_start = timeval_current(); warmup = 0; for (i=0;i<nprocs;i++) { children[i].warmup_bytes = children[i].bytes; } goto next; } if (t < warmup) { in_warmup = 1; } else if (!in_warmup && !in_cleanup && t > timelimit) { for (i=0;i<nprocs;i++) { children[i].done = 1; } tv_end = timeval_current(); in_cleanup = 1; } if (t < 1) { goto next; } if (!in_cleanup) { tv_end = timeval_current(); } if (in_warmup) { printf("%4d %8d %.2f MB/sec warmup %.0f sec \n", num_connected, lines/nprocs, nbio_result(), t); } else if (in_cleanup) { printf("%4d %8d %.2f MB/sec cleanup %.0f sec \n", num_connected, lines/nprocs, nbio_result(), t); } else { printf("%4d %8d %.2f MB/sec execute %.0f sec latency %.2f msec \n", num_connected, lines/nprocs, nbio_result(), t, nbio_latency() * 1.0e3); } fflush(stdout); next: signal(SIGALRM, nb_alarm); alarm(1); }