Navigation


Changeset 1397:239ba25870d8 in freeDiameter for libfdcore/routing_dispatch.c


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.