bb-latency-bench.c 4.61 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>

#include "abt.h"
#include "abt-snoozer.h"
#include "bake-bulk.h"

static void bench_routine(bake_target_id_t bti, int iterations, int size);
Philip Carns's avatar
Philip Carns committed
21
static void bench_routine_noop(bake_target_id_t bti, int iterations);
Philip Carns's avatar
Philip Carns committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

int main(int argc, char **argv) 
{
    int ret;
    bake_target_id_t bti;
    int min_size, max_size, iterations, cur_size;
 
    if(argc != 5)
    {
        fprintf(stderr, "Usage: bb-latency-bench <server addr> <iterations> <min_sz> <max_sz>\n");
        fprintf(stderr, "  Example: ./bb-latency-bench tcp://localhost:1234 1000 4 32\n");
        return(-1);
    }       

    ret = sscanf(argv[2], "%d", &iterations);
    assert(ret == 1);

    ret = sscanf(argv[3], "%d", &min_size);
    assert(ret == 1);

    ret = sscanf(argv[4], "%d", &max_size);
    assert(ret == 1);

    /* set up Argobots */
    ret = ABT_init(argc, argv);
    if(ret != 0)
    {
        fprintf(stderr, "Error: ABT_init()\n");
        return(-1);
    }
    ret = ABT_snoozer_xstream_self_set();
    if(ret != 0)
    {
        ABT_finalize();
        fprintf(stderr, "Error: ABT_snoozer_xstream_self_set()\n");
        return(-1);
    }

    ret = bake_probe_instance(argv[1], &bti);
    if(ret < 0)
    {
        ABT_finalize();
        fprintf(stderr, "Error: bake_probe_instance()\n");
        return(-1);
    }

    printf("# <op> <iterations> <size> <avg> <min> <max>\n");
Philip Carns's avatar
Philip Carns committed
69
    bench_routine_noop(bti, iterations);
Philip Carns's avatar
Philip Carns committed
70 71 72 73 74 75 76 77 78 79 80 81
    for(cur_size=min_size; cur_size <= max_size; cur_size *= 2)
        bench_routine(bti, iterations, cur_size);
    
    bake_release_instance(bti);

    ABT_finalize();

    return(0);
}

static double Wtime(void)
{
82 83 84
    struct timespec tp;
    clock_gettime(CLOCK_MONOTONIC, &tp);
    return((double)tp.tv_sec + (double)(tp.tv_nsec) / (double)1000000000.0);
Philip Carns's avatar
Philip Carns committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
}

static void bench_routine(bake_target_id_t bti, int iterations, int size)
{
    bake_bulk_region_id_t rid;
    int ret;
    double tm1, tm2, min = 0, max = 0, sum = 0;
    char *buffer;
    uint64_t region_offset = 0;
    int i;

    buffer = calloc(1, size);
    assert(buffer);

    /* create region */
    ret = bake_bulk_create(bti, size*iterations, &rid);
    assert(ret == 0);

    sleep(1);

    for(i=0; i<iterations; i++)
    {
        tm1 = Wtime();
        /* transfer data (writes) */
        ret = bake_bulk_write(
            bti,
            rid,
            region_offset,
            buffer,
            size);
        tm2 = Wtime();
        assert(ret == 0);
        region_offset += size;

        sum += tm2-tm1;
        if(min == 0 || min > (tm2-tm1))
            min = tm2-tm1;
        if(max == 0 || max < (tm2-tm1))
            max = tm2-tm1;
    }

    printf("write\t%d\t%d\t%.9f\t%.9f\t%.9f\n", iterations, size, sum/((double)iterations), min, max);

    region_offset = 0;
    sleep(1);

    for(i=0; i<iterations; i++)
    {
        tm1 = Wtime();
        /* transfer data (reads) */
        ret = bake_bulk_read(
            bti,
            rid,
            region_offset,
            buffer,
            size);
        tm2 = Wtime();
        assert(ret == 0);
        region_offset += size;

        sum += tm2-tm1;
        if(min == 0 || min > (tm2-tm1))
            min = tm2-tm1;
        if(max == 0 || max < (tm2-tm1))
            max = tm2-tm1;
    }

    printf("read\t%d\t%d\t%.9f\t%.9f\t%.9f\n", iterations, size, sum/((double)iterations), min, max);

    /* persist */
    ret = bake_bulk_persist(bti, rid);
    assert(ret == 0);

    free(buffer);

    return;
}
Philip Carns's avatar
Philip Carns committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

static void bench_routine_noop(bake_target_id_t bti, int iterations)
{
    int ret;
    double tm1, tm2, min = 0, max = 0, sum = 0;
    int i;

    sleep(1);

    tm1 = Wtime();
    for(i=0; i<iterations; i++)
    {
        /* noop */
        ret = bake_bulk_noop(bti);
        assert(ret == 0);
    }
    tm2 = Wtime();
    sum = tm2-tm1;
    min = -1;
    max = -1;

    printf("noop(continuous))\t%d\t%d\t%.9f\t%.9f\t%.9f\n", iterations, -1, sum/((double)iterations), min, max);


    min = 0;
    max = 0;
    sum = 0;
    sleep(1);

    for(i=0; i<iterations; i++)
    {
        tm1 = Wtime();
        /* noop */
        ret = bake_bulk_noop(bti);
        tm2 = Wtime();
        assert(ret == 0);

        sum += tm2-tm1;
        if(min == 0 || min > (tm2-tm1))
            min = tm2-tm1;
        if(max == 0 || max < (tm2-tm1))
            max = tm2-tm1;
    }

    printf("noop\t%d\t%d\t%.9f\t%.9f\t%.9f\n", iterations, -1, sum/((double)iterations), min, max);

    return;
}