composed-benchmark.c 4.31 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 21 22 23
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <abt.h>
#include <margo.h>

#include "composed-client-lib.h"

static hg_id_t my_rpc_shutdown_id;
static void* buffer;
static hg_size_t buffer_sz = 8*1024*1024;

int main(int argc, char **argv) 
{
    int i;
    int ret;
    margo_instance_id mid;
24
    hg_return_t hret;
25 26
    hg_addr_t delegator_svr_addr = HG_ADDR_NULL;
    hg_addr_t data_xfer_svr_addr = HG_ADDR_NULL;
Philip Carns's avatar
Philip Carns committed
27 28
    hg_handle_t handle;
    char proto[12] = {0};
Philip Carns's avatar
Philip Carns committed
29 30
    int iterations;
    double start, end, t1, t2, avg, min=0, max=0;
Philip Carns's avatar
Philip Carns committed
31
  
Philip Carns's avatar
Philip Carns committed
32
    if(argc != 4)
Philip Carns's avatar
Philip Carns committed
33
    {
Philip Carns's avatar
Philip Carns committed
34
        fprintf(stderr, "Usage: ./client <delegator_svr_addr> <data_xfer_svr_addr> <iterations>\n");
Philip Carns's avatar
Philip Carns committed
35 36
        return(-1);
    }
Philip Carns's avatar
Philip Carns committed
37 38 39

    ret = sscanf(argv[3], "%d", &iterations);
    assert(ret == 1);
Philip Carns's avatar
Philip Carns committed
40 41 42 43 44 45
       
    /* initialize Mercury using the transport portion of the destination
     * address (i.e., the part before the first : character if present)
     */
    for(i=0; i<11 && argv[1][i] != '\0' && argv[1][i] != ':'; i++)
        proto[i] = argv[1][i];
46

47 48 49
    /* TODO: this is a hack for now; I don't really want this to operate in server mode,
     * but it seems like it needs to for now for sub-service to be able to get back to it
     */
50
    /* actually start margo */
Philip Carns's avatar
Philip Carns committed
51
    /***************************************/
52 53
    mid = margo_init(proto, MARGO_SERVER_MODE, 0, -1);
    if(mid == MARGO_INSTANCE_NULL)
Philip Carns's avatar
Philip Carns committed
54
    {
55
        fprintf(stderr, "Error: margo_init()\n");
Philip Carns's avatar
Philip Carns committed
56 57 58 59
        return(-1);
    }

    /* register core RPC */
60 61
    my_rpc_shutdown_id = MARGO_REGISTER(mid, "my_shutdown_rpc",
        void, void, NULL);
Philip Carns's avatar
Philip Carns committed
62 63
    /* register service APIs */
    data_xfer_register_client(mid);
Philip Carns's avatar
Philip Carns committed
64
    composed_register_client(mid);
Philip Carns's avatar
Philip Carns committed
65

66
    /* find addrs for servers */
67 68 69 70
    hret = margo_addr_lookup(mid, argv[2], &data_xfer_svr_addr);
    assert(hret == HG_SUCCESS);
    hret = margo_addr_lookup(mid, argv[1], &delegator_svr_addr);
    assert(hret == HG_SUCCESS);
Philip Carns's avatar
Philip Carns committed
71 72 73 74

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

Philip Carns's avatar
Philip Carns committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    /* TODO: this is where benchmark timing would go, probably with iterations */
    /***************************************************************************/

    sleep(3);
    printf("# DBG: starting data_xfer_read() benchmark.\n");
    start = ABT_get_wtime();
    for(i=0; i<iterations; i++)
    {
        t1 = ABT_get_wtime();
        data_xfer_read(mid, data_xfer_svr_addr, buffer, buffer_sz);
        t2 = ABT_get_wtime();
        if(min == 0 || t2-t1<min)
            min = t2-t1;
        if(max == 0 || t2-t1>max)
            max = t2-t1;
    }
    end = ABT_get_wtime();
    avg = (end-start)/((double)iterations);
    printf("# DBG:    ... DONE.\n");
    printf("# <op> <min> <avg> <max>\n");
    printf("direct\t%f\t%f\t%f\n", min, avg, max);
Philip Carns's avatar
Philip Carns committed
96
    
97 98
    sleep(3);

Philip Carns's avatar
Philip Carns committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    printf("# DBG: starting composed_read() benchmark.\n");
    start = ABT_get_wtime();
    for(i=0; i<iterations; i++)
    {
        t1 = ABT_get_wtime();
        composed_read(mid, delegator_svr_addr, buffer, buffer_sz, argv[2]);
        t2 = ABT_get_wtime();
        if(min == 0 || t2-t1<min)
            min = t2-t1;
        if(max == 0 || t2-t1>max)
            max = t2-t1;
    }
    end = ABT_get_wtime();
    avg = (end-start)/((double)iterations);
    printf("# DBG:    ... DONE.\n");
    printf("# <op> <min> <avg> <max>\n");
    printf("composed\t%f\t%f\t%f\n", min, avg, max);
    printf("# DBG:    ... DONE.\n");
    
    /***************************************************************************/
Philip Carns's avatar
Philip Carns committed
119

120
    /* send rpc(s) to shut down server(s) */
121 122
    sleep(3);
    printf("Shutting down delegator server.\n");
123 124
    hret = margo_create(mid, delegator_svr_addr, my_rpc_shutdown_id, &handle);
    assert(hret == HG_SUCCESS);
125
    hret = margo_forward(handle, NULL);
126
    assert(hret == HG_SUCCESS);
127
    margo_destroy(handle);
128 129
    if(strcmp(argv[1], argv[2]))
    {
130 131
        sleep(3);
        printf("Shutting down data_xfer server.\n");
132 133
        hret = margo_create(mid, data_xfer_svr_addr, my_rpc_shutdown_id, &handle);
        assert(hret == HG_SUCCESS);
134
        hret = margo_forward(handle, NULL);
135
        assert(hret == HG_SUCCESS);
136
        margo_destroy(handle);
137
    }
Philip Carns's avatar
Philip Carns committed
138

139 140
    margo_addr_free(mid, delegator_svr_addr);
    margo_addr_free(mid, data_xfer_svr_addr);
Philip Carns's avatar
Philip Carns committed
141 142 143 144 145 146 147

    /* shut down everything */
    margo_finalize(mid);
    free(buffer);

    return(0);
}