Ignore:
Timestamp:
Jul 3, 2006 2:18:17 PM (18 years ago)
Author:
bennylp
Message:

Fixed minor bug in pool_caching.c that prevent pool from being reused if the capacity has changed when the pool is released

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c

    r580 r581  
    6767#include <stdio.h> 
    6868 
    69 #define THIS_FILE       "pjsip-perf.c" 
    70 #define DEFAULT_COUNT   (PJSIP_MAX_TSX_COUNT/2>10000?10000:PJSIP_MAX_TSX_COUNT/2) 
    71 #define JOB_WINDOW      DEFAULT_COUNT 
     69#if defined(PJ_WIN32) && PJ_WIN32!=0 
     70#  include <windows.h> 
     71#endif 
     72 
     73#define THIS_FILE           "pjsip-perf.c" 
     74#define DEFAULT_COUNT       (PJSIP_MAX_TSX_COUNT/2>10000?10000:PJSIP_MAX_TSX_COUNT/2) 
     75#define JOB_WINDOW          DEFAULT_COUNT 
     76#define TERMINATE_TSX(x,c) 
     77 
     78 
     79#ifndef CACHING_POOL_SIZE 
     80#   define CACHING_POOL_SIZE   (256*1024*1024) 
     81#endif 
    7282 
    7383 
     
    139149                             job_finished, 
    140150                             job_window; 
     151        unsigned             stat_max_window; 
    141152        pj_time_val          first_request; 
    142153        pj_time_val          last_completion; 
     
    588599 
    589600    /* Must create a pool factory before we can allocate any memory. */ 
    590     pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy, 0); 
     601    pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy,  
     602                         CACHING_POOL_SIZE); 
    591603 
    592604    /* Create application pool for misc. */ 
     
    633645             
    634646            transport_type = "tcp"; 
    635             pj_sockaddr_in_init(&local_addr, 0, app.local_port); 
     647            pj_sockaddr_in_init(&local_addr, 0, (pj_uint16_t)app.local_port); 
    636648            status = pjsip_tcp_transport_start(app.sip_endpt, &local_addr, 
    637649                                               app.thread_count, &tpfactory); 
     
    976988        "   --stateless, -s         Set client to operate in stateless mode\n" 
    977989        "                           (default: stateful)\n" 
     990        "   --window=COUNT, -w      Set maximum outstanding job in client (default: %d)\n" 
    978991        "   --real-sdp              Generate real SDP from pjmedia, and also perform\n" 
    979992        "                           proper SDP negotiation (default: dummy)\n" 
     
    986999        "   - sip:1@server-addr     To handle requests statefully (INVITE and non-INVITE)\n" 
    9871000        "   - sip:2@server-addr     To handle INVITE call (INVITE only)\n", 
    988         DEFAULT_COUNT); 
     1001        DEFAULT_COUNT, JOB_WINDOW); 
    9891002} 
    9901003 
     
    10111024        { "verbose",        0, 0, 'v' }, 
    10121025        { "use-tcp",        0, 0, 'T' }, 
     1026        { "window",         1, 0, 'w' }, 
    10131027        { NULL, 0, 0, 0 }, 
    10141028    }; 
     
    10271041    /* Parse options */ 
    10281042    pj_optind = 0; 
    1029     while((c=pj_getopt_long(argc,argv, "p:c:m:t:hsv",  
     1043    while((c=pj_getopt_long(argc,argv, "p:c:m:t:w:hsv",  
    10301044                            long_options, &option_index))!=-1)  
    10311045    { 
     
    10911105            break; 
    10921106 
     1107        case 'w': 
     1108            app.client.job_window = my_atoi(pj_optarg); 
     1109            if (app.client.job_window <= 0) { 
     1110                PJ_LOG(3,(THIS_FILE, "Invalid --window %s", pj_optarg)); 
     1111                return -1; 
     1112            } 
     1113            break; 
     1114 
    10931115        case 'T': 
    10941116            app.use_tcp = PJ_TRUE; 
     
    11841206        tsx->mod_data[mod_test.id] = (void*)1; 
    11851207 
    1186         pjsip_tsx_terminate(tsx, tsx->status_code); 
     1208        TERMINATE_TSX(tsx, tsx->status_code); 
    11871209    } 
    11881210} 
     
    12201242static int client_thread(void *arg) 
    12211243{ 
     1244    unsigned last_timeout_check = 0; 
    12221245    pj_time_val end_time, now; 
    12231246 
     
    12401263        pj_status_t status; 
    12411264 
     1265        /* Calculate current outstanding job */ 
     1266        outstanding = app.client.job_submitted - app.client.job_finished; 
     1267 
     1268        /* Update stats on max outstanding jobs */ 
     1269        if (outstanding > (int)app.client.stat_max_window) 
     1270            app.client.stat_max_window = outstanding; 
     1271 
    12421272        /* Wait if there are more pending jobs than allowed in the 
    12431273         * window. 
    12441274         */ 
    1245         outstanding = app.client.job_submitted - app.client.job_finished; 
    1246         while (outstanding >= (int)app.client.job_window) { 
     1275        for (i=0; outstanding > (int)app.client.job_window && i<100; ++i) { 
    12471276            pjsip_endpt_handle_events(app.sip_endpt, &timeout); 
    12481277            outstanding = app.client.job_submitted - app.client.job_finished; 
    12491278        } 
    12501279 
     1280 
     1281        /* Submit one job */ 
    12511282        if (app.client.method.id == PJSIP_INVITE_METHOD) { 
    12521283            status = make_call(&app.client.dst_uri); 
     
    12591290        ++app.client.job_submitted; 
    12601291 
    1261         for (i=0; i<2; ++i) { 
    1262             unsigned cnt=0; 
    1263             pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &cnt); 
    1264             if (cnt==0) 
     1292        /* Handle event */ 
     1293        pjsip_endpt_handle_events2(app.sip_endpt, &timeout, NULL); 
     1294 
     1295        /* Check for time out */ 
     1296        if (app.client.job_submitted - last_timeout_check >= 2000) { 
     1297            pj_gettimeofday(&now); 
     1298            if (PJ_TIME_VAL_GTE(now, end_time)) 
    12651299                break; 
     1300            last_timeout_check = app.client.job_submitted; 
    12661301        } 
    12671302    } 
     
    12721307        unsigned i; 
    12731308 
    1274         for (i=0; i<2; ++i) { 
    1275             unsigned cnt=0; 
    1276             pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &cnt); 
    1277             if (cnt==0) 
    1278                 break; 
     1309        for (i=0; i<2000; ++i) { 
     1310            pjsip_endpt_handle_events2(app.sip_endpt, &timeout, NULL); 
    12791311        } 
    12801312 
     
    13531385                good_number(str_call, app.server.cur_state.call_cnt); 
    13541386 
    1355                 printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s)\r", 
     1387                printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s)       \r", 
    13561388                       str_stateless, stateless*1000/msec, 
    13571389                       str_stateful, stateful*1000/msec, 
     
    13671399} 
    13681400 
     1401static void write_report(const char *msg) 
     1402{ 
     1403    puts(msg); 
     1404 
     1405#if defined(PJ_WIN32) && PJ_WIN32!=0 
     1406    OutputDebugString(msg); 
     1407    OutputDebugString("\n"); 
     1408#endif 
     1409} 
     1410 
     1411 
    13691412int main(int argc, char *argv[]) 
    13701413{ 
     1414    static char report[1024]; 
    13711415 
    13721416    if (create_app() != 0) 
     
    14591503        if (msec == 0) msec = 1; 
    14601504 
    1461         printf("Total %d %s sent, %d responses received in %d msec:\n" 
    1462                " - 2xx responses:  %7d (rate=%d/sec)\n" 
    1463                " - 3xx responses:  %7d (rate=%d/sec)\n" 
    1464                " - 4xx responses:  %7d (rate=%d/sec)\n" 
    1465                " - 5xx responses:  %7d (rate=%d/sec)\n" 
    1466                " - 6xx responses:  %7d (rate=%d/sec)\n" 
    1467                " - 7xx responses:  %7d (rate=%d/sec)\n" 
    1468                "                       ----------------\n" 
    1469                " TOTAL responses:  %7d (rate=%d/sec)\n", 
    1470                app.client.job_submitted, test_type, 
    1471                app.client.total_responses, msec, 
    1472                app.client.status_class[2], app.client.status_class[2]*1000/msec, 
    1473                app.client.status_class[3], app.client.status_class[3]*1000/msec, 
    1474                app.client.status_class[4], app.client.status_class[4]*1000/msec, 
    1475                app.client.status_class[5], app.client.status_class[5]*1000/msec, 
    1476                app.client.status_class[6], app.client.status_class[6]*1000/msec, 
    1477                app.client.status_class[7], app.client.status_class[7]*1000/msec, 
    1478                app.client.total_responses, app.client.total_responses*1000/msec); 
     1505        pj_ansi_snprintf( 
     1506            report, sizeof(report), 
     1507            "Total %d %s sent, %d responses received in %d ms:\n" 
     1508            " - 2xx responses:  %7d (rate=%d/sec)\n" 
     1509            " - 3xx responses:  %7d (rate=%d/sec)\n" 
     1510            " - 4xx responses:  %7d (rate=%d/sec)\n" 
     1511            " - 5xx responses:  %7d (rate=%d/sec)\n" 
     1512            " - 6xx responses:  %7d (rate=%d/sec)\n" 
     1513            " - 7xx responses:  %7d (rate=%d/sec)\n" 
     1514            "                       ----------------\n" 
     1515            " TOTAL responses:  %7d (rate=%d/sec)\n", 
     1516            app.client.job_submitted, test_type, 
     1517            app.client.total_responses, msec, 
     1518            app.client.status_class[2], app.client.status_class[2]*1000/msec, 
     1519            app.client.status_class[3], app.client.status_class[3]*1000/msec, 
     1520            app.client.status_class[4], app.client.status_class[4]*1000/msec, 
     1521            app.client.status_class[5], app.client.status_class[5]*1000/msec, 
     1522            app.client.status_class[6], app.client.status_class[6]*1000/msec, 
     1523            app.client.status_class[7], app.client.status_class[7]*1000/msec, 
     1524            app.client.total_responses, app.client.total_responses*1000/msec); 
     1525 
     1526        write_report(report); 
     1527 
     1528        pj_ansi_sprintf(report, "Maximum outstanding job: %d",  
     1529                        app.client.stat_max_window); 
     1530        write_report(report); 
     1531 
    14791532 
    14801533    } else { 
Note: See TracChangeset for help on using the changeset viewer.