Navigation


Changeset 1090:8be95f757b08 in freeDiameter


Ignore:
Timestamp:
May 6, 2013, 11:29:31 AM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Improved the testmesg_stress with more functions tested and configurable number of samples.
Example of output: ./testmesg_stress -p 1000000

fd_msg_parse_buffer: 1000000 buffers parsed in 2.097266s (476811.2msg/s)
fd_msg_parse_dict : 1000000 messages parsed in 4.320338s (231463.4msg/s)
fd_msg_parse_rules : 1000000 messages parsed in 3.217548s (310795.7msg/s)
new_answer(normal) : 1000000 messages created in 1.623253s (616046.8msg/s)
new_answer(error) : 1000000 messages created in 1.325757s (754286.2msg/s)
fd_msg_bufferize : 1000000 buffers created in 2.619448s (381759.8msg/s)
fd_msg_free : 1000000 messages freed in 1.820525s (549292.0msg/s)

Location:
tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/testmesg_stress.c

    r1088 r1090  
    3737
    3838/* The number of times each operation is repeated to measure the average operation time */
    39 #define NUMBER_OF_SAMPLES       100000
     39#define DEFAULT_NUMBER_OF_SAMPLES       100000
     40
     41static void display_result(int nr, struct timespec * start, struct timespec * end, char * fct, char * type, char *op)
     42{
     43        long double dur = (long double)end->tv_sec + (long double)end->tv_nsec/1000000000;
     44        dur -= (long double)start->tv_sec + (long double)start->tv_nsec/1000000000;
     45        long double thrp = (long double)nr / dur;
     46        printf("%-19s: %d %-8s %-7s in %.6LFs (%.1LFmsg/s)\n", fct, nr, type, op, dur, thrp);
     47}
     48
     49
    4050
    4151/* Main test routine */
     
    4555        struct avp * pi = NULL, *avp1, *avp2;
    4656        unsigned char * buf = NULL;
     57       
     58        test_parameter = DEFAULT_NUMBER_OF_SAMPLES;
    4759       
    4860        /* First, initialize the daemon modules */
     
    371383        /* Test the throughput of the different functions function */
    372384        {
    373                 void ** stress_array;
     385                struct stress_struct {
     386                        struct msg * m;
     387                        uint8_t * b;
     388                } * stress_array;
    374389                int i;
    375390                struct timespec start, end;
     
    385400               
    386401                /* Create the copies of the message buffer */
    387                 stress_array = calloc(NUMBER_OF_SAMPLES, sizeof(void *));
     402                stress_array = calloc(test_parameter, sizeof(struct stress_struct));
    388403                CHECK( stress_array ? 1 : 0, 1);
    389404               
    390                 for (i=0; i < NUMBER_OF_SAMPLES; i++) {
     405                for (i=0; i < test_parameter; i++) {
    391406                        CPYBUF();
    392                         stress_array[i] = buf_cpy;
    393                 }
     407                        stress_array[i].b = buf_cpy;
     408                }
     409               
     410        /* fd_msg_parse_buffer */
    394411               
    395412                CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) );
    396413               
    397414                /* Test the msg_parse_buffer function */
    398                 for (i=0; i < NUMBER_OF_SAMPLES; i++) {
    399                         CHECK( 0, fd_msg_parse_buffer( (uint8_t **)&stress_array[i], 344, &msg) );
    400                         stress_array[i] = msg;
    401                 }
    402                
    403                 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
    404                
    405                 {
    406                         long us = (end.tv_sec - start.tv_sec) * 1000000;
    407                         us += (end.tv_nsec - start.tv_nsec) / 1000;
    408                         long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us;
    409                         printf("fd_msg_bufferize  : %d buffers  parsed in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp);
    410                 }
    411                
    412                
     415                for (i=0; i < test_parameter; i++) {
     416                        CHECK( 0, fd_msg_parse_buffer( &stress_array[i].b, 344, &stress_array[i].m) );
     417                }
     418               
     419                CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
     420                display_result(test_parameter, &start, &end, "fd_msg_parse_buffer", "buffers", "parsed");
     421               
     422        /* fd_msg_parse_dict */
    413423               
    414424                CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) );
    415425               
    416426                /* Test the fd_msg_parse_dict function */
    417                 for (i=0; i < NUMBER_OF_SAMPLES; i++) {
    418                         CHECK( 0, fd_msg_parse_dict( stress_array[i], fd_g_config->cnf_dict, NULL ) );
    419                 }
    420                
    421                 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
    422                
    423                 {
    424                         long us = (end.tv_sec - start.tv_sec) * 1000000;
    425                         us += (end.tv_nsec - start.tv_nsec) / 1000;
    426                         long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us;
    427                         printf("fd_msg_parse_dict : %d messages parsed in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp);
    428                 }
    429                
    430                
     427                for (i=0; i < test_parameter; i++) {
     428                        CHECK( 0, fd_msg_parse_dict( stress_array[i].m, fd_g_config->cnf_dict, NULL ) );
     429                }
     430               
     431                CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
     432                display_result(test_parameter, &start, &end, "fd_msg_parse_dict", "messages", "parsed");
     433               
     434               
     435        /* fd_msg_parse_rules */
    431436               
    432437                CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) );
    433438               
    434439                /* Test the fd_msg_parse_rules function */
    435                 for (i=0; i < NUMBER_OF_SAMPLES; i++) {
    436                         CHECK( 0, fd_msg_parse_rules( stress_array[i], fd_g_config->cnf_dict, NULL ) );
    437                 }
    438                
    439                 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
    440                
    441                 {
    442                         long us = (end.tv_sec - start.tv_sec) * 1000000;
    443                         us += (end.tv_nsec - start.tv_nsec) / 1000;
    444                         long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us;
    445                         printf("fd_msg_parse_rules: %d messages parsed in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp);
    446                 }
    447                
    448                
     440                for (i=0; i < test_parameter; i++) {
     441                        CHECK( 0, fd_msg_parse_rules( stress_array[i].m, fd_g_config->cnf_dict, NULL ) );
     442                }
     443               
     444                CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
     445                display_result(test_parameter, &start, &end, "fd_msg_parse_rules", "messages", "parsed");
     446               
     447               
     448        /* fd_msg_new_answer_from_req (0) */
     449               
     450                CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) );
     451               
     452                /* Test the fd_msg_new_answer_from_req function */
     453                for (i=0; i < test_parameter; i++) {
     454                        CHECK( 0, fd_msg_new_answer_from_req( fd_g_config->cnf_dict, &stress_array[i].m, 0 ) );
     455                }
     456               
     457                CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
     458                display_result(test_parameter, &start, &end, "new_answer(normal)", "messages", "created");
     459               
     460                /* unlink answers and go back to request messages */
     461                for (i=0; i < test_parameter; i++) {
     462                        struct msg * ans = stress_array[i].m;
     463                        CHECK( 0, fd_msg_answ_getq( ans, &stress_array[i].m ) );
     464                        CHECK( 0, fd_msg_answ_detach( ans ) );
     465                        fd_msg_free( ans );
     466                }
     467               
     468               
     469        /* fd_msg_new_answer_from_req (MSGFL_ANSW_ERROR) */
     470               
     471                CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) );
     472               
     473                /* Test the fd_msg_new_answer_from_req function */
     474                for (i=0; i < test_parameter; i++) {
     475                        CHECK( 0, fd_msg_new_answer_from_req( fd_g_config->cnf_dict, &stress_array[i].m, MSGFL_ANSW_ERROR ) );
     476                }
     477               
     478                CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
     479                display_result(test_parameter, &start, &end, "new_answer(error)", "messages", "created");
     480               
     481                /* unlink answers and go back to request messages */
     482                for (i=0; i < test_parameter; i++) {
     483                        struct msg * ans = stress_array[i].m;
     484                        CHECK( 0, fd_msg_answ_getq( ans, &stress_array[i].m ) );
     485                        CHECK( 0, fd_msg_answ_detach( ans ) );
     486                        fd_msg_free( ans );
     487                }
     488               
     489               
     490        /* fd_msg_bufferize */
     491               
     492
     493                CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) );
     494               
     495                /* Test the fd_msg_bufferize function */
     496                for (i=0; i < test_parameter; i++) {
     497                        size_t len = 0;
     498                        CHECK( 0, fd_msg_bufferize( stress_array[i].m, &stress_array[i].b, &len ) );
     499                }
     500               
     501                CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
     502                display_result(test_parameter, &start, &end, "fd_msg_bufferize", "buffers", "created");
     503               
     504               
     505        /* fd_msg_free */
    449506               
    450507                CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) );
    451508               
    452509                /* Free those messages */
    453                 for (i=0; i < NUMBER_OF_SAMPLES; i++) {
    454                         fd_msg_free( stress_array[i]);
    455                         stress_array[i] = NULL;
    456                 }
    457                
    458                 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
    459                
    460                 {
    461                         long us = (end.tv_sec - start.tv_sec) * 1000000;
    462                         us += (end.tv_nsec - start.tv_nsec) / 1000;
    463                         long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us;
    464                         printf("fd_msg_free       : %d messages freed  in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp);
    465                 }
    466                
     510                for (i=0; i < test_parameter; i++) {
     511                        fd_msg_free( stress_array[i].m );
     512                }
     513               
     514                CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) );
     515                display_result(test_parameter, &start, &end, "fd_msg_free", "messages", "freed");
     516               
     517               
     518                for (i=0; i < test_parameter; i++) {
     519                        free(stress_array[i].b);
     520                }
    467521                free(stress_array);
    468522        }
  • tests/tests.h

    r1088 r1090  
    141141static int gnutls_debug = 0;
    142142
     143static int test_parameter = 0;
    143144
    144145static inline void parse_cmdline(int argc, char * argv[]) {
    145146        int c;
    146147        int no_timeout = 0;
    147         while ((c = getopt (argc, argv, "dqnf:F:g:")) != -1) {
     148        while ((c = getopt (argc, argv, "dqnf:F:g:p:")) != -1) {
    148149                switch (c) {
    149150                        case 'd':       /* Increase verbosity of debug messages.  */
     
    177178                        case 'g':       /* Set a debug level and function for GNU TLS calls.  */
    178179                                gnutls_debug = (int)atoi(optarg);
     180                                break;
     181                               
     182                        case 'p':       /* Set a debug level and function for GNU TLS calls.  */
     183                                test_parameter = (int)atoi(optarg);
    179184                                break;
    180185                               
Note: See TracChangeset for help on using the changeset viewer.