summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Landden <shawn@git.icu>2021-05-11 21:17:32 +0400
committerGitHub <noreply@github.com>2021-05-11 21:17:32 +0400
commitc7337a78a248b557463f0fe281659efdfe661134 (patch)
treebf050de6f61b7ec0aeb90af25da1a84d67461d9f
parentde21b1a43737fbcf47967a706dab4c60521dbbb1 (diff)
parentac121434aae7d16053d005c508073bf1a8108095 (diff)
downloaddistcc-git-c7337a78a248b557463f0fe281659efdfe661134.tar.gz
Merge pull request #421 from asheplyakov/distccd-dontsleep
prefork: use available cores more efficiently
-rw-r--r--src/prefork.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/prefork.c b/src/prefork.c
index 38e3a19..d7e1d84 100644
--- a/src/prefork.c
+++ b/src/prefork.c
@@ -37,6 +37,7 @@
#include <syslog.h>
#include <signal.h>
#include <fcntl.h>
+#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -91,10 +92,6 @@ int dcc_preforking_parent(int listen_fd)
/* wait for any children to exit, and then start some more */
dcc_reap_kids(TRUE);
-
- /* Another little safety brake here: since children should not exit
- * too quickly, pausing before starting them should be harmless. */
- sleep(1);
}
}
}
@@ -133,10 +130,6 @@ static void dcc_create_kids(int listen_fd) {
++dcc_nkids;
rs_trace("up to %d children", dcc_nkids);
}
-
- /* Don't start them too quickly, or we might overwhelm a machine
- * that's having trouble. */
- sleep(1);
}
}
@@ -151,9 +144,12 @@ static void dcc_create_kids(int listen_fd) {
static int dcc_preforked_child(int listen_fd)
{
int ireq;
- const int child_lifetime = 50;
+ time_t start, now;
+ const int child_requests = 50;
+ const time_t child_lifetime = 60 /* seconds */;
+ start = now = time(NULL);
- for (ireq = 0; ireq < child_lifetime; ireq++) {
+ for (ireq = 0; ireq < child_requests || now - start < child_lifetime; ireq++) {
int acc_fd;
struct dcc_sockaddr_storage cli_addr;
socklen_t cli_len;
@@ -188,6 +184,7 @@ static int dcc_preforked_child(int listen_fd)
(struct sockaddr *) &cli_addr, cli_len);
dcc_close(acc_fd);
+ now = time(NULL);
}
rs_log_info("worn out");