TEST: make rbreader/writer more like the other benchmarking apps

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2012-05-21 08:30:22 +10:00
parent 0458c5ccd2
commit 7bf88478ac
2 changed files with 63 additions and 66 deletions

View File

@ -28,9 +28,10 @@
#include <qb/qbutil.h>
#include <qb/qblog.h>
#define BUFFER_CHUNK_SIZE (50*50*10)
#define ONE_MEG 1048576
static qb_ringbuffer_t *rb = NULL;
static int keep_reading = QB_TRUE;
int8_t buffer[ONE_MEG];
static void sigterm_handler(int32_t num)
@ -42,18 +43,18 @@ static void sigterm_handler(int32_t num)
int32_t main(int32_t argc, char *argv[])
{
ssize_t num_read;
int8_t buffer[BUFFER_CHUNK_SIZE];
signal(SIGINT, sigterm_handler);
qb_log_init("rbreader", LOG_USER, LOG_EMERG);
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, "*", LOG_INFO);
QB_LOG_FILTER_FILE, "*", LOG_TRACE);
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
rb = qb_rb_open("tester", BUFFER_CHUNK_SIZE * 3,
QB_RB_FLAG_SHARED_PROCESS | QB_RB_FLAG_CREATE, 0);
rb = qb_rb_open("tester", ONE_MEG * 3,
QB_RB_FLAG_SHARED_PROCESS |
QB_RB_FLAG_CREATE, 0);
if (rb == NULL) {
qb_perror(LOG_ERR, "failed to create ringbuffer");
@ -61,8 +62,11 @@ int32_t main(int32_t argc, char *argv[])
}
while (keep_reading) {
num_read = qb_rb_chunk_read(rb, buffer,
BUFFER_CHUNK_SIZE, 5500);
if (num_read < 0) {
ONE_MEG, 0);
if (num_read == -ETIMEDOUT) {
usleep(100000);
} else if (num_read < 0) {
errno = -num_read;
qb_perror(LOG_ERR, "nothing to read");
}
}

View File

@ -35,11 +35,10 @@
#include <qb/qbutil.h>
#include <qb/qblog.h>
static int alarm_notice = 0;
static qb_ringbuffer_t *rb = NULL;
#define ITERATIONS 100000
#define BUFFER_CHUNK_SIZE (50*50*10)
static struct timeval tv1, tv2, tv_elapsed;
#define ONE_MEG 1048576
static char buffer[ONE_MEG * 3];
#define timersub(a, b, result) \
do { \
@ -51,6 +50,11 @@ do { \
} \
} while (0)
static void sigalrm_handler (int num)
{
alarm_notice = 1;
}
static void sigterm_handler(int32_t num)
{
qb_log(LOG_INFO, "writer: %s(%d)\n", __func__, num);
@ -58,53 +62,56 @@ static void sigterm_handler(int32_t num)
exit(0);
}
static void bm_start(void)
static void
_benchmark(int write_size)
{
gettimeofday(&tv1, NULL);
}
struct timeval tv1, tv2, tv_elapsed;
unsigned int res;
int write_count = 0;
static void bm_finish(const char *operation, int32_t size)
{
float ops_per_sec;
float mbs_per_sec;
alarm_notice = 0;
gettimeofday(&tv2, NULL);
timersub(&tv2, &tv1, &tv_elapsed);
alarm (10);
ops_per_sec =
((float)ITERATIONS) / (((float)tv_elapsed.tv_sec) +
(((float)tv_elapsed.tv_usec) / 1000000.0));
mbs_per_sec =
((((float)ITERATIONS) * size) /
(((float)tv_elapsed.tv_sec) +
(((float)tv_elapsed.tv_usec) / 1000000.0))) / (1024.0 * 1024.0);
qb_log(LOG_INFO, "write size %d OPs/sec %9.3f MB/sec %9.3f",
size, ops_per_sec, mbs_per_sec);
}
static void bmc_connect(void)
{
rb = qb_rb_open("tester", BUFFER_CHUNK_SIZE * 3,
QB_RB_FLAG_SHARED_PROCESS, 0);
if (rb == NULL) {
qb_perror(LOG_ERR, "failed to create ringbuffer");
exit(1);
gettimeofday (&tv1, NULL);
do {
res = qb_rb_chunk_write(rb, buffer, write_size);
if (res == write_size) {
write_count++;
}
} while (alarm_notice == 0 && (res == write_size || res == -EAGAIN));
if (res < 0) {
perror("qb_ipcc_sendv");
}
gettimeofday (&tv2, NULL);
timersub (&tv2, &tv1, &tv_elapsed);
printf ("%5d messages sent ", write_count);
printf ("%5d bytes per write ", write_size);
printf ("%7.3f Seconds runtime ",
(tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
printf ("%9.3f TP/s ",
((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
printf ("%7.3f MB/s.\n",
((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
}
static char buffer[1024 * 1024];
static void bmc_send_nozc(size_t size)
{
ssize_t res = 0;
repeat_send:
res = qb_rb_chunk_write(rb, buffer, size);
if (res < size) {
goto repeat_send;
static void
do_throughput_benchmark(void)
{
ssize_t size = 64;
int i;
signal (SIGALRM, sigalrm_handler);
for (i = 0; i < 10; i++) { /* number of repetitions - up to 50k */
_benchmark(size);
signal (SIGALRM, sigalrm_handler);
size *= 5;
if (size >= ONE_MEG) {
break;
}
}
}
@ -125,8 +132,6 @@ int32_t main(int32_t argc, char *argv[])
{
const char *options = "vh";
int32_t opt;
int32_t i, j;
int32_t size;
int32_t verbose = 0;
while ((opt = getopt(argc, argv, options)) != -1) {
@ -150,21 +155,9 @@ int32_t main(int32_t argc, char *argv[])
QB_LOG_FILTER_FILE, "*", LOG_INFO + verbose);
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
bmc_connect();
for (j = 1; j < 49; j++) {
bm_start();
size = 7 * (j + 1) * j;
if (size > BUFFER_CHUNK_SIZE) {
size = BUFFER_CHUNK_SIZE;
}
for (i = 0; i < ITERATIONS; i++) {
bmc_send_nozc(size);
}
bm_finish("ringbuffer", size);
}
rb = qb_rb_open("tester", ONE_MEG * 3,
QB_RB_FLAG_SHARED_PROCESS, 0);
do_throughput_benchmark();
qb_rb_close(rb);
return EXIT_SUCCESS;
}