]> arthur.ath.cx Git - ngircd-alex.git/commitdiff
Implement NGIRCD_PENALTY_MAX environment variable
authorAlexander Barton <alex@barton.de>
Thu, 25 Dec 2014 15:56:36 +0000 (16:56 +0100)
committerAlexander Barton <alex@barton.de>
Thu, 25 Dec 2014 15:56:36 +0000 (16:56 +0100)
NGIRCD_PENALTY_MAX can be used to define the maximum number of seconds
that will be added to the "penalty timer" of a client per call.
Use 0 to disable penalties altogether. Disabling (or reducing) penalties
can greatly speed up "make check" runs for example, see below.

But PLEASE NOTE:
NGIRCD_PENALTY_MAX isn't meant to be used in production!
This is a testing and debugging feature ONLY!

Some example timings on my Linux server:

$ time make NGIRCD_PENALTY_MAX=0 check >/dev/null
real    0m22.643s
user    0m0.428s
sys     0m0.440s

$ time make NGIRCD_PENALTY_MAX=1 check >/dev/null
real    3m1.839s
user    0m0.492s
sys     0m0.408s

$ time make NGIRCD_PENALTY_MAX= check >/dev/null
real    4m27.071s
user    0m0.488s
sys     0m0.516s

src/ngircd/conn-func.c
src/ngircd/conn.c
src/ngircd/conn.h

index fb5c55fa1289b8c8aa3527dbb32b605c6246357c..76369b970fdff36fde6479687e02dc2513a425da 100644 (file)
@@ -97,6 +97,11 @@ Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
        assert(Idx > NONE);
        assert(Seconds >= 0);
 
+       if (Max_Penalty_Add >= 0 && Seconds > Max_Penalty_Add)
+               Seconds = Max_Penalty_Add;
+       if (Seconds <= 0)
+               return;
+
        t = time(NULL);
        if (My_Connections[Idx].delaytime < t)
                My_Connections[Idx].delaytime = t;
@@ -138,7 +143,7 @@ GLOBAL CONN_ID
 Conn_First( void )
 {
        CONN_ID i;
-       
+
        for( i = 0; i < Pool_Size; i++ )
        {
                if( My_Connections[i].sock != NONE ) return i;
@@ -152,7 +157,7 @@ Conn_Next( CONN_ID Idx )
        CONN_ID i = NONE;
 
        assert( Idx > NONE );
-       
+
        for( i = Idx + 1; i < Pool_Size; i++ )
        {
                if( My_Connections[i].sock != NONE ) return i;
index 62561544866413f5abb1534da27caac1e2aa2218..00b5633b9ed687940ca5c84b3b50e1be5bafbbaf 100644 (file)
@@ -36,6 +36,7 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <ctype.h>
 #include <time.h>
 #include <netinet/in.h>
 
@@ -308,6 +309,7 @@ GLOBAL void
 Conn_Init( void )
 {
        CONN_ID i;
+       char *ptr;
 
        Pool_Size = CONNECTION_POOL;
        if ((Conf_MaxConnections > 0) &&
@@ -333,6 +335,15 @@ Conn_Init( void )
 
        for (i = 0; i < Pool_Size; i++)
                Init_Conn_Struct(i);
+
+       ptr = getenv("NGIRCD_PENALTY_MAX");
+       if (ptr && isdigit(*ptr) && atol(ptr) >= 0) {
+               Max_Penalty_Add = atol(ptr);
+               Log(LOG_WARNING,
+                   "Warning: \"NGIRCD_PENALTY_MAX\" is set to %ld!",
+                   Max_Penalty_Add);
+       } else
+               Max_Penalty_Add = -1;
 } /* Conn_Init */
 
 /**
index c642541f07ce486b712f5a3b0e719a438d9ea8da..c2f37613df002393ebe7b3d50c51a7d780fc6ec3 100644 (file)
@@ -42,6 +42,7 @@
 #define CONN_SSL_WANT_READ     128     /* SSL/TLS library needs to read protocol data */
 #define CONN_SSL_FLAGS_ALL     (CONN_SSL_CONNECT|CONN_SSL|CONN_SSL_WANT_WRITE|CONN_SSL_WANT_READ)
 #endif
+
 typedef int CONN_ID;
 
 #include "client.h"
@@ -111,6 +112,8 @@ GLOBAL long WCounter;
 
 #define CONNECTION2ID(x) (long)(x - My_Connections)
 
+GLOBAL time_t Max_Penalty_Add;         /** Maximum penalty time to add at once */
+
 #endif /* CONN_MODULE */