Navigation


Changeset 572:b1b56d4682d0 in freeDiameter


Ignore:
Timestamp:
Oct 8, 2010, 3:30:36 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added benchmark mode in test_app

Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • doc/test_app.conf.sample

    r336 r572  
    3838# mode = both;
    3939
     40# The behavior can be changed by specifying additional "benchmark;" keyword.
     41# When this keyword appears, it changes the behavior as follow:
     42#  - server is silent on message reception, only the activity summary is displayed every 30 seconds
     43#  - client attempts to send as many messages as possible during 10 seconds and counts them.
     44# benchmark;
     45
    4046#######################
    4147# Client-specific configuration
  • extensions/test_app/CMakeLists.txt

    r313 r572  
    1616        ta_dict.c
    1717        ta_cli.c
     18        ta_bench.c
    1819        ta_serv.c
    1920)
  • extensions/test_app/ta_conf.l

    r128 r572  
    153153                        }
    154154
     155(?i:"Benchmark")        {
     156                                return BENCH;
     157                        }
     158
    155159                       
    156160        /* Valid single characters for yyparse */
  • extensions/test_app/ta_conf.y

    r127 r572  
    126126%token          USER_NAME
    127127%token          SIGNAL
     128%token          BENCH
    128129
    129130/* Tokens and types for routing table definition */
     
    150151                        | conffile usrname
    151152                        | conffile signal
     153                        | conffile bench
    152154                        ;
    153155
     
    178180mode:                   MODE '=' INTEGER ';'
    179181                        {
    180                                 ta_conf->mode = $3;
     182                                ta_conf->mode = $3 | (ta_conf->mode & ~3); /* overwrite the 2 lsb */
     183                        }
     184                        ;
     185
     186bench:                  BENCH ';'
     187                        {
     188                                ta_conf->mode |= MODE_BENCH;
    181189                        }
    182190                        ;
  • extensions/test_app/ta_serv.c

    r406 r572  
    6464       
    6565        /* Value of Origin-Host */
    66         fprintf(stderr, "ECHO Test-Request received from ");
    67         CHECK_FCT( fd_msg_search_avp ( *msg, ta_origin_host, &a) );
    68         if (a) {
    69                 struct avp_hdr * hdr;
    70                 CHECK_FCT( fd_msg_avp_hdr( a, &hdr ) );
    71                 fprintf(stderr, "'%.*s'", (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
    72         } else {
    73                 fprintf(stderr, "no_Origin-Host");
     66        if (! (ta_conf->mode & MODE_BENCH)) {
     67                fprintf(stderr, "ECHO Test-Request received from ");
     68                CHECK_FCT( fd_msg_search_avp ( *msg, ta_origin_host, &a) );
     69                if (a) {
     70                        struct avp_hdr * hdr;
     71                        CHECK_FCT( fd_msg_avp_hdr( a, &hdr ) );
     72                        fprintf(stderr, "'%.*s'", (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
     73                } else {
     74                        fprintf(stderr, "no_Origin-Host");
     75                }
     76                fprintf(stderr, ", replying...\n");
    7477        }
    75         fprintf(stderr, ", replying...\n");
    7678       
    7779        /* Create answer header */
  • extensions/test_app/test_app.c

    r258 r572  
    4343struct ta_conf * ta_conf = NULL;
    4444static struct ta_conf _conf;
     45static pthread_t ta_stats_th = (pthread_t)NULL;
    4546
    4647static int ta_conf_init(void)
     
    5960        ta_conf->signal     = TEST_APP_DEFAULT_SIGNAL;
    6061       
     62        /* Initialize the mutex */
     63        CHECK_POSIX( pthread_mutex_init(&ta_conf->stats_lock, NULL) );
     64       
    6165        return 0;
    6266}
     
    7175        fd_log_debug( " Command Id ......... : %u\n", ta_conf->cmd_id);
    7276        fd_log_debug( " AVP Id ............. : %u\n", ta_conf->avp_id);
    73         fd_log_debug( " Mode ............... : %s%s\n", ta_conf->mode & MODE_SERV ? "Serv" : "", ta_conf->mode & MODE_CLI ? "Cli" : "" );
     77        fd_log_debug( " Mode ............... : %s%s%s\n", ta_conf->mode & MODE_SERV ? "Serv" : "", ta_conf->mode & MODE_CLI ? "Cli" : "",  ta_conf->mode & MODE_BENCH ? " (Benchmark)" : "");
    7478        fd_log_debug( " Destination Realm .. : %s\n", ta_conf->dest_realm ?: "- none -");
    7579        fd_log_debug( " Destination Host ... : %s\n", ta_conf->dest_host ?: "- none -");
    7680        fd_log_debug( " Signal ............. : %i\n", ta_conf->signal);
    7781        fd_log_debug( "------- /app_test configuration dump ---------\n");
     82}
     83
     84/* Function to display statistics every 10 seconds */
     85static void * ta_stats(void * arg) {
     86
     87        struct timespec start, now;
     88        struct ta_stats copy;
     89       
     90        /* Get the start time */
     91        CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &start), );
     92       
     93        /* Now, loop until canceled */
     94        while (1) {
     95                /* Display statistics every 30 seconds */
     96                sleep(30);
     97               
     98                /* Now, get the current stats */
     99                CHECK_POSIX_DO( pthread_mutex_lock(&ta_conf->stats_lock), );
     100                memcpy(&copy, &ta_conf->stats, sizeof(struct ta_stats));
     101                CHECK_POSIX_DO( pthread_mutex_unlock(&ta_conf->stats_lock), );
     102               
     103                /* Get the current execution time */
     104                CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), );
     105               
     106                /* Now, display everything */
     107                fd_log_debug( "------- app_test statistics ---------\n");
     108                if (now.tv_nsec >= start.tv_nsec) {
     109                        fd_log_debug( " Executing for: %d.%06ld sec\n",
     110                                        (int)(now.tv_sec - start.tv_sec),
     111                                        (long)(now.tv_nsec - start.tv_nsec) / 1000);
     112                } else {
     113                        fd_log_debug( " Executing for: %d.%06ld sec\n",
     114                                        (int)(now.tv_sec - 1 - start.tv_sec),
     115                                        (long)(now.tv_nsec + 1000000000 - start.tv_nsec) / 1000);
     116                }
     117               
     118                if (ta_conf->mode & MODE_SERV) {
     119                        fd_log_debug( " Server: %llu messages echoed\n", copy.nb_echoed);
     120                }
     121                if (ta_conf->mode & MODE_CLI) {
     122                        fd_log_debug( " Client:\n");
     123                        fd_log_debug( "   %llu messages sent\n", copy.nb_sent);
     124                        fd_log_debug( "   %llu errors received\n", copy.nb_errs);
     125                        fd_log_debug( "   %llu answers received\n", copy.nb_recv);
     126                        fd_log_debug( "     fastest: %ld.%06ld sec.\n", copy.shortest / 1000000, copy.shortest % 1000000);
     127                        fd_log_debug( "     slowest: %ld.%06ld sec.\n", copy.longest / 1000000, copy.longest % 1000000);
     128                        fd_log_debug( "     Average: %ld.%06ld sec.\n", copy.avg / 1000000, copy.avg % 1000000);
     129                }
     130                fd_log_debug( "-------------------------------------\n");
     131        }
     132       
     133        return NULL; /* never called */
    78134}
    79135
     
    104160        /* Start the signal handler thread */
    105161        if (ta_conf->mode & MODE_CLI) {
    106                 CHECK_FCT( ta_cli_init() );
     162                if (ta_conf->mode & MODE_BENCH) {
     163                        CHECK_FCT( ta_bench_init() );
     164                } else {
     165                        CHECK_FCT( ta_cli_init() );
     166                }
    107167        }
    108168       
    109169        /* Advertise the support for the test application in the peer */
    110170        CHECK_FCT( fd_disp_app_support ( ta_appli, ta_vendor, 1, 0 ) );
     171       
     172        /* Start the statistics thread */
     173        CHECK_POSIX( pthread_create(&ta_stats_th, NULL, ta_stats, NULL) );
    111174       
    112175        return 0;
     
    120183        if (ta_conf->mode & MODE_SERV)
    121184                ta_serv_fini();
     185        CHECK_FCT_DO( fd_thr_term(&ta_stats_th), );
     186        CHECK_POSIX_DO( pthread_mutex_destroy(&ta_conf->stats_lock), );
    122187}
    123188
  • extensions/test_app/test_app.h

    r258 r572  
    5252#define MODE_SERV       0x1
    5353#define MODE_CLI        0x2
     54#define MODE_BENCH      0x4
    5455
    5556/* The module configuration */
     
    6465        char    *       user_name;      /* default NULL */
    6566        int             signal;         /* default TEST_APP_DEFAULT_SIGNAL */
     67        struct ta_stats {
     68                unsigned long long      nb_echoed; /* server */
     69                unsigned long long      nb_sent;   /* client */
     70                unsigned long long      nb_recv;   /* client */
     71                unsigned long long      nb_errs;   /* client */
     72                unsigned long           shortest;  /* fastest answer, in microseconds */
     73                unsigned long           longest;   /* slowest answer, in microseconds */
     74                unsigned long           avg;       /* average answer time, in microseconds */
     75        } stats;
     76        pthread_mutex_t         stats_lock;
    6677};
    6778extern struct ta_conf * ta_conf;
     
    7788int ta_cli_init(void);
    7889void ta_cli_fini(void);
     90
     91/* Benchmark flavour */
     92int ta_bench_init(void);
     93void ta_bench_fini(void);
    7994
    8095/* Initialize dictionary definitions */
Note: See TracChangeset for help on using the changeset viewer.