From 425a40f5e401fe226a89f05f3149ea069f4c3951 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Fri, 13 Jan 2012 01:49:40 +0100 Subject: [PATCH] add -delayedspinup=ms --- jobflow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jobflow.c b/jobflow.c index 54be231..512fdf3 100644 --- a/jobflow.c +++ b/jobflow.c @@ -1,3 +1,8 @@ +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 + #include "../lib/include/optparser.h" #include "../lib/include/stringptr.h" #include "../lib/include/stringptrlist.h" @@ -12,6 +17,7 @@ #include #include #include +#include /* defines the amount of milliseconds to sleep between each call to the reaper, * once all free slots are exhausted */ @@ -46,6 +52,8 @@ typedef struct { job_info* free_slots[MAX_SLOTS]; unsigned free_slots_count; char* tempdir; + int delayedspinup_interval; /* use a random delay until the queue gets filled for the first time. + the top value in ms can be supplied via a command line switch */ int buffered:1; /* write stdout and stderr of each task into a file, and print it to stdout once the process ends. this prevents mixing up of the output of multiple tasks. */ @@ -180,6 +188,9 @@ void parse_args(int argc, char** argv) { if(!prog_state.statefile) die("-delayedflush needs -statefile\n"); prog_state.delayedflush = 1; } + + op_temp = op_get(op, SPL("delayedspinup")); + prog_state.delayedspinup_interval = op_temp ? atoi(op_temp) : 0; prog_state.cmd_startarg = 0; prog_state.subst_entries = NULL; @@ -246,6 +257,8 @@ int main(int argc, char** argv) { char tempdir_buf[256]; char temp_state[256]; + srand(time(NULL)); + if(argc > 4096) argc = 4096; prog_state.threads_running = 0; prog_state.free_slots_count = 0; @@ -316,6 +329,9 @@ int main(int argc, char** argv) { if(!prog_state.free_slots_count) msleep(SLEEP_MS); } + if(prog_state.delayedspinup_interval && n < prog_state.numthreads) + msleep(rand() % (prog_state.delayedspinup_interval + 1)); + launch_job(prog_state.free_slots[prog_state.free_slots_count-1], cmd_argv); prog_state.free_slots_count--; -- 2.11.4.GIT