Navigation


Changeset 1397:239ba25870d8 in freeDiameter for libfdcore


Ignore:
Timestamp:
Nov 15, 2019, 7:40:37 PM (4 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

Allow parametrizing the number of threads for routing in/out.

This is for high-load situations where freeDiameter was limited
by the corresponding queues.

Location:
libfdcore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/config.c

    r1396 r1397  
    6262        fd_g_config->cnf_processing_peers_minimum = 0;
    6363        fd_g_config->cnf_dispthr  = 4;
     64        fd_g_config->cnf_rtinthr = 1;
     65        fd_g_config->cnf_rtoutthr = 1;
     66        fd_g_config->cnf_qin_limit = 20;
     67        fd_g_config->cnf_qout_limit = 30;
     68        fd_g_config->cnf_qlocal_limit = 25;
    6469        fd_list_init(&fd_g_config->cnf_endpoints, NULL);
    6570        fd_list_init(&fd_g_config->cnf_apps, NULL);
     
    104109        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Number of app threads .. : %hu\n", fd_g_config->cnf_dispthr), return NULL);
    105110        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Minimal processing peers : %hu\n", fd_g_config->cnf_processing_peers_minimum), return NULL);
     111        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Number of rtin threads . : %hu\n", fd_g_config->cnf_rtinthr), return NULL);
     112        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Number of rtout threads  : %hu\n", fd_g_config->cnf_rtoutthr), return NULL);
     113        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Incoming queue limit     : %hu\n", fd_g_config->cnf_qin_limit), return NULL);
     114        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Outgoing queue limit     : %hu\n", fd_g_config->cnf_qout_limit), return NULL);
     115        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Local queue limit        : %hu\n", fd_g_config->cnf_qlocal_limit), return NULL);
    106116        if (FD_IS_LIST_EMPTY(&fd_g_config->cnf_endpoints)) {
    107117                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "  Local endpoints ........ : Default (use all available)\n"), return NULL);
  • libfdcore/core.c

    r1325 r1397  
    316316{
    317317        int ret;
     318        CHECK_FCT( fd_queues_init_after_conf() );
     319
    318320        CHECK_POSIX( pthread_mutex_lock(&core_lock) );
    319321        ret = fd_core_start_int();
  • libfdcore/fdcore-internal.h

    r1240 r1397  
    110110/* Message queues */
    111111int fd_queues_init(void);
     112int fd_queues_init_after_conf(void);
    112113int fd_queues_fini(struct fifo ** queue);
    113114
  • libfdcore/fdd.l

    r1396 r1397  
    255255(?i:"SCTP_streams")     { return SCTPSTREAMS; }
    256256(?i:"AppServThreads")   { return APPSERVTHREADS; }
     257(?i:"RoutingInThreads") { return ROUTINGINTHREADS; }
     258(?i:"RoutingOutThreads")        { return ROUTINGOUTTHREADS; }
     259(?i:"IncomingQueueLimit")       { return QINLIMIT; }
     260(?i:"OutgoingQueueLimit")       { return QOUTLIMIT; }
     261(?i:"LocalQueueLimit")  { return QLOCALLIMIT; }
    257262(?i:"ListenOn")         { return LISTENON; }
    258263(?i:"ThreadsPerServer") { return THRPERSRV; }
     
    272277(?i:"TLS_DH_bits")      { return TLS_DH_BITS; }
    273278(?i:"TLS_DH_file")      { return TLS_DH_FILE; }
     279(?i:"RouteRecordInAnswers")     { return RR_IN_ANSWERS; }
     280(?i:"Never")            { return NEVER; }
     281(?i:"Always")           { return ALWAYS; }
    274282
    275283
  • libfdcore/fdd.y

    r1396 r1397  
    108108%token          SCTPSTREAMS
    109109%token          APPSERVTHREADS
     110%token          ROUTINGINTHREADS
     111%token          ROUTINGOUTTHREADS
     112%token          QINLIMIT
     113%token          QOUTLIMIT
     114%token          QLOCALLIMIT
    110115%token          LISTENON
    111116%token          THRPERSRV
     
    148153                        | conffile norelay
    149154                        | conffile appservthreads
     155                        | conffile routinginthreads
     156                        | conffile routingoutthreads
     157                        | conffile qinlimit
     158                        | conffile qoutlimit
     159                        | conffile qlocallimit
    150160                        | conffile noip
    151161                        | conffile noip6
     
    307317                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
    308318                                conf->cnf_dispthr = (uint16_t)$3;
     319                        }
     320                        ;
     321
     322routinginthreads:               ROUTINGINTHREADS '=' INTEGER ';'
     323                        {
     324                                CHECK_PARAMS_DO( ($3 > 0) && ($3 < 256),
     325                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
     326                                conf->cnf_rtinthr = (uint16_t)$3;
     327                        }
     328                        ;
     329
     330routingoutthreads:              ROUTINGOUTTHREADS '=' INTEGER ';'
     331                        {
     332                                CHECK_PARAMS_DO( ($3 > 0) && ($3 < 256),
     333                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
     334                                conf->cnf_rtoutthr = (uint16_t)$3;
     335                        }
     336                        ;
     337
     338qinlimit:               QINLIMIT '=' INTEGER ';'
     339                        {
     340                                CHECK_PARAMS_DO( ($3 >= 0),
     341                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
     342                                conf->cnf_qin_limit = $3;
     343                        }
     344                        ;
     345
     346qoutlimit:              QOUTLIMIT '=' INTEGER ';'
     347                        {
     348                                CHECK_PARAMS_DO( ($3 >= 0),
     349                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
     350                                conf->cnf_qout_limit = $3;
     351                        }
     352                        ;
     353
     354qlocallimit:            QLOCALLIMIT '=' INTEGER ';'
     355                        {
     356                                CHECK_PARAMS_DO( ($3 >= 0),
     357                                        { yyerror (&yylloc, conf, "Invalid value"); YYERROR; } );
     358                                conf->cnf_qlocal_limit = $3;
    309359                        }
    310360                        ;
  • libfdcore/queues.c

    r1127 r1397  
    4545{
    4646        TRACE_ENTRY();
    47         CHECK_FCT( fd_fifo_new ( &fd_g_incoming, 20 ) );
    48         CHECK_FCT( fd_fifo_new ( &fd_g_outgoing, 30 ) );
    49         CHECK_FCT( fd_fifo_new ( &fd_g_local, 25 ) );
     47        CHECK_FCT( fd_fifo_new ( &fd_g_incoming, fd_g_config->cnf_qin_limit ) );
     48        CHECK_FCT( fd_fifo_new ( &fd_g_outgoing, fd_g_config->cnf_qout_limit ) );
     49        CHECK_FCT( fd_fifo_new ( &fd_g_local,    fd_g_config->cnf_qlocal_limit ) );
     50        return 0;
     51}
     52
     53/* Resize according to values given in configuration file */
     54int fd_queues_init_after_conf(void)
     55{
     56        TRACE_ENTRY();
     57        CHECK_FCT( fd_fifo_set_max ( fd_g_incoming, fd_g_config->cnf_qin_limit ) );
     58        CHECK_FCT( fd_fifo_set_max ( fd_g_outgoing, fd_g_config->cnf_qout_limit ) );
     59        CHECK_FCT( fd_fifo_set_max ( fd_g_local,    fd_g_config->cnf_qlocal_limit ) );
    5060        return 0;
    5161}
  • libfdcore/routing_dispatch.c

    r1328 r1397  
    3535
    3636#include "fdcore-internal.h"
     37
     38#ifdef linux
     39/* This needs -D_USE_GNU, and since I have no idea what else that does, let's simply copy the declaration. */
     40
     41/* Set thread name visible in the kernel and its interfaces.  */
     42extern int pthread_setname_np (pthread_t __target_thread, const char *__name);
     43#endif
    3744
    3845/********************************************************************************/
     
    11531160static enum thread_state * disp_state = NULL;
    11541161
    1155 /* Later: make this more dynamic */
    1156 static pthread_t rt_out = (pthread_t)NULL;
    1157 static enum thread_state out_state = NOTRUNNING;
    1158 
    1159 static pthread_t rt_in  = (pthread_t)NULL;
    1160 static enum thread_state in_state = NOTRUNNING;
     1162static pthread_t * rt_out = NULL;
     1163static enum thread_state * out_state = NULL;
     1164
     1165static pthread_t * rt_in  = NULL;
     1166static enum thread_state * in_state = NULL;
    11611167
    11621168/* Initialize the routing and dispatch threads */
     
    11651171        int i;
    11661172       
    1167         /* Prepare the array for dispatch */
     1173        /* Prepare the array for threads */
    11681174        CHECK_MALLOC( disp_state = calloc(fd_g_config->cnf_dispthr, sizeof(enum thread_state)) );
    11691175        CHECK_MALLOC( dispatch = calloc(fd_g_config->cnf_dispthr, sizeof(pthread_t)) );
     1176        CHECK_MALLOC( out_state = calloc(fd_g_config->cnf_rtoutthr, sizeof(enum thread_state)) );
     1177        CHECK_MALLOC( rt_out = calloc(fd_g_config->cnf_rtoutthr, sizeof(pthread_t)) );
     1178        CHECK_MALLOC( in_state = calloc(fd_g_config->cnf_rtinthr, sizeof(enum thread_state)) );
     1179        CHECK_MALLOC( rt_in = calloc(fd_g_config->cnf_rtinthr, sizeof(pthread_t)) );
    11701180       
    11711181        /* Create the threads */
    11721182        for (i=0; i < fd_g_config->cnf_dispthr; i++) {
    11731183                CHECK_POSIX( pthread_create( &dispatch[i], NULL, dispatch_thr, &disp_state[i] ) );
    1174         }
    1175         CHECK_POSIX( pthread_create( &rt_out, NULL, routing_out_thr, &out_state) );
    1176         CHECK_POSIX( pthread_create( &rt_in,  NULL, routing_in_thr,  &in_state) );
     1184#ifdef linux
     1185                pthread_setname_np(dispatch[i], "fd-dispatch");
     1186#endif
     1187        }
     1188        for (i=0; i < fd_g_config->cnf_rtoutthr; i++) {
     1189                CHECK_POSIX( pthread_create( &rt_out[i], NULL, routing_out_thr, &out_state[i] ) );
     1190#ifdef linux
     1191                pthread_setname_np(rt_out[i], "fd-routing-out");
     1192#endif
     1193        }
     1194        for (i=0; i < fd_g_config->cnf_rtinthr; i++) {
     1195                CHECK_POSIX( pthread_create( &rt_in[i], NULL, routing_in_thr, &in_state[i] ) );
     1196#ifdef linux
     1197                pthread_setname_np(rt_in[i], "fd-routing-in");
     1198#endif
     1199        }
    11771200       
    11781201        /* Later: TODO("Set the thresholds for the queues to create more threads as needed"); */
     
    12451268       
    12461269        /* Stop the routing IN thread */
    1247         stop_thread_delayed(&in_state, &rt_in, "IN routing");
     1270        if (rt_in != NULL) {
     1271                for (i=0; i < fd_g_config->cnf_rtinthr; i++) {
     1272                        stop_thread_delayed(&in_state[i], &rt_in[i], "IN routing");
     1273                }
     1274                free(rt_in);
     1275                rt_in = NULL;
     1276        }
     1277        if (in_state != NULL) {
     1278                free(in_state);
     1279                in_state = NULL;
     1280        }
    12481281       
    12491282        /* Destroy the outgoing queue */
     
    12511284       
    12521285        /* Stop the routing OUT thread */
    1253         stop_thread_delayed(&out_state, &rt_out, "OUT routing");
     1286        if (rt_out != NULL) {
     1287                for (i=0; i < fd_g_config->cnf_rtinthr; i++) {
     1288                        stop_thread_delayed(&out_state[i], &rt_out[i], "OUT routing");
     1289                }
     1290                free(rt_out);
     1291                rt_out = NULL;
     1292        }
     1293        if (out_state != NULL) {
     1294                free(out_state);
     1295                out_state = NULL;
     1296        }
    12541297       
    12551298        /* Destroy the local queue */
Note: See TracChangeset for help on using the changeset viewer.