Adding the limit of ts connections
authorviric@mandarina
Fri, 02 Oct 2009 20:19:18 +0200
changeset 278 1698b327528d
parent 277 1ee3c4ef9402
child 279 a53597676524
Adding the limit of ts connections
Changelog
TRICKS
main.c
server.c
--- a/Changelog	Fri Oct 02 20:01:16 2009 +0200
+++ b/Changelog	Fri Oct 02 20:19:18 2009 +0200
@@ -13,6 +13,7 @@
 v0.6.5:
  - Fixed a problem that -c and -t, if their pipe was broken, they remained.
  - Fixed a problem (maybe some copypaste once?) on -l, that created always an error msg.
+ - Adding the possibility of limiting the amount of ts connections.
 v0.6.4:
  - Fixed a bug breaking -c and -t.
 v0.6.3:
--- a/TRICKS	Fri Oct 02 20:01:16 2009 +0200
+++ b/TRICKS	Fri Oct 02 20:19:18 2009 +0200
@@ -37,3 +37,16 @@
 $ kill -- -`ts -p`
 in order to kill the job started and all its childs. I find it useful when
 killing 'make's.
+
+
+Limiting the number of ts processes
+-------------------------
+Each queued job remains in the system as a waiting process. On environments
+where the number of processes is quite limited, the user can select the amount
+of the maximum number of ts server connections to ts clients. That will be
+read from the environment variable TS_MAXCONN at the server start, and cannot be
+set again once the server runs:
+$ ts -K     # we assure we will start the server at the next ts call
+$ TS_MAXCONN=5 ts
+Internally there is a maximum of 1000 connexions that cannot be exceeded without
+modifying the source code (server.c).
--- a/main.c	Fri Oct 02 20:01:16 2009 +0200
+++ b/main.c	Fri Oct 02 20:19:18 2009 +0200
@@ -317,6 +317,7 @@
     printf("  TS_SOCKET  the path to the unix socket used by the ts command.\n");
     printf("  TS_MAILTO  where to mail the result (on -m). Local user by default.\n");
     printf("  TS_MAXFINISHED  maximum finished jobs in the queue.\n");
+    printf("  TS_MAXCONN  maximum number of ts connections at once.\n");
     printf("  TS_ONFINISH  binary called on job end (passes jobid, error, outfile, command).\n");
     printf("  TS_ENV  command called on enqueue. Its output determines the job information.\n");
     printf("  TS_SAVELIST  filename which will store the list, if the server dies.\n");
--- a/server.c	Fri Oct 02 20:01:16 2009 +0200
+++ b/server.c	Fri Oct 02 20:19:18 2009 +0200
@@ -124,10 +124,21 @@
     int max;
     struct rlimit rlim;
     int res;
+    const char *str;
 
     max = MAXCONN;
+
+    str = getenv("TS_MAXCONN");
+    if (str != NULL)
+    {
+        int user_maxconn;
+        user_maxconn = abs(atoi(str));
+        if (max > user_maxconn)
+            max = user_maxconn;
+    }
+
     if (max > FD_SETSIZE)
-        max = FD_SETSIZE;
+        max = FD_SETSIZE - MARGIN;
 
     /* I'd like to use OPEN_MAX or NR_OPEN, but I don't know if any
      * of them is POSIX compliant */
@@ -138,13 +149,13 @@
     else
     {
         if (max > rlim.rlim_cur)
-            max = rlim.rlim_cur;
+            max = rlim.rlim_cur - MARGIN;
     }
 
-    if (max - MARGIN < 1)
+    if (max < 1)
         error("Too few opened descriptors available");
 
-    return max - MARGIN;
+    return max;
 }
 
 void server_main(int notify_fd, char *_path)