Browse Source

Fixes a race condition

Also, fixes a couple of errant frameworks who were
not cleaning exiting their start shells.
msmith-techempower 8 years ago
parent
commit
9531785f3e

+ 1 - 1
frameworks/CSharp/revenj/benchmark_config.json

@@ -1,5 +1,5 @@
 {
 {
-  "framework": "Revenj",
+  "framework": "revenj",
   "tests": [{
   "tests": [{
     "windows": {
     "windows": {
       "setup_file": "setup",
       "setup_file": "setup",

+ 1 - 2
frameworks/CSharp/revenj/setup.sh

@@ -32,5 +32,4 @@ echo "Copying the configuration template"
 cat $TROOT/Revenj.Http.exe.config | sed 's|\(ConnectionString.*server=\)localhost|\1'"${DBHOST}"'|' > $TROOT/exe/Revenj.Http.exe.config
 cat $TROOT/Revenj.Http.exe.config | sed 's|\(ConnectionString.*server=\)localhost|\1'"${DBHOST}"'|' > $TROOT/exe/Revenj.Http.exe.config
 
 
 echo "Running the Revenj instance"
 echo "Running the Revenj instance"
-mono $TROOT/exe/Revenj.Http.exe
-sleep 5
+mono $TROOT/exe/Revenj.Http.exe &

+ 1 - 1
frameworks/Java/revenj/benchmark_config.json

@@ -1,5 +1,5 @@
 {
 {
-  "framework": "Revenj.JVM",
+  "framework": "revenj",
   "tests": [{
   "tests": [{
     "default": {
     "default": {
       "setup_file": "setup",
       "setup_file": "setup",

+ 12 - 15
toolset/benchmark/benchmarker.py

@@ -546,7 +546,6 @@ class Benchmarker:
           p.communicate("""
           p.communicate("""
             sudo restart mysql
             sudo restart mysql
             sudo restart mongod
             sudo restart mongod
-            sudo service redis-server restart
             sudo service postgresql restart
             sudo service postgresql restart
             sudo service cassandra restart
             sudo service cassandra restart
             /opt/elasticsearch/elasticsearch restart
             /opt/elasticsearch/elasticsearch restart
@@ -556,7 +555,6 @@ class Benchmarker:
           st = verify_database_connections([
           st = verify_database_connections([
             ("mysql", self.database_host, 3306),
             ("mysql", self.database_host, 3306),
             ("mongodb", self.database_host, 27017),
             ("mongodb", self.database_host, 27017),
-            ("redis", self.database_host, 6379),
             ("postgresql", self.database_host, 5432),
             ("postgresql", self.database_host, 5432),
             ("cassandra", self.database_host, 9160),
             ("cassandra", self.database_host, 9160),
             ("elasticsearch", self.database_host, 9200)
             ("elasticsearch", self.database_host, 9200)
@@ -573,9 +571,9 @@ class Benchmarker:
           print "Error: Unable to recover port, cannot start test"
           print "Error: Unable to recover port, cannot start test"
           return exit_with_code(1)
           return exit_with_code(1)
 
 
-        result = test.start(out)
+        result, process = test.start(out)
         if result != 0:
         if result != 0:
-          self.__stop_test(out)
+          self.__stop_test(out, process)
           time.sleep(5)
           time.sleep(5)
           out.write( "ERROR: Problem starting {name}\n".format(name=test.name) )
           out.write( "ERROR: Problem starting {name}\n".format(name=test.name) )
           out.flush()
           out.flush()
@@ -613,13 +611,13 @@ class Benchmarker:
         ##########################
         ##########################
         out.write(header("Stopping %s" % test.name))
         out.write(header("Stopping %s" % test.name))
         out.flush()
         out.flush()
-        self.__stop_test(out)
+        self.__stop_test(out, process)
         out.flush()
         out.flush()
         time.sleep(15)
         time.sleep(15)
 
 
         if self.__is_port_bound(test.port):
         if self.__is_port_bound(test.port):
           # This can happen sometimes - let's try again
           # This can happen sometimes - let's try again
-          self.__stop_test(out)
+          self.__stop_test(out, process)
           out.flush()
           out.flush()
           time.sleep(15)
           time.sleep(15)
           if self.__is_port_bound(test.port):
           if self.__is_port_bound(test.port):
@@ -664,7 +662,7 @@ class Benchmarker:
         traceback.print_exc(file=out)
         traceback.print_exc(file=out)
         out.flush()
         out.flush()
         try:
         try:
-          self.__stop_test(out)
+          self.__stop_test(out, process)
         except (subprocess.CalledProcessError) as e:
         except (subprocess.CalledProcessError) as e:
           self.__write_intermediate_results(test.name,"<setup.py>#stop() raised an error")
           self.__write_intermediate_results(test.name,"<setup.py>#stop() raised an error")
           out.write(header("Subprocess Error: Test .stop() raised exception %s" % test.name))
           out.write(header("Subprocess Error: Test .stop() raised exception %s" % test.name))
@@ -675,7 +673,7 @@ class Benchmarker:
       # TODO - subprocess should not catch this exception!
       # TODO - subprocess should not catch this exception!
       # Parent process should catch it and cleanup/exit
       # Parent process should catch it and cleanup/exit
       except (KeyboardInterrupt) as e:
       except (KeyboardInterrupt) as e:
-        self.__stop_test(out)
+        self.__stop_test(out, process)
         out.write(header("Cleaning up..."))
         out.write(header("Cleaning up..."))
         out.flush()
         out.flush()
         self.__finish()
         self.__finish()
@@ -692,13 +690,12 @@ class Benchmarker:
   # __stop_test(benchmarker)
   # __stop_test(benchmarker)
   # Stops all running tests
   # Stops all running tests
   ############################################################
   ############################################################
-  def __stop_test(self, out):
-    # Find the PID of the daemon (and remove trailing newline)
-    pid = subprocess.check_output(['pgrep','TFBReaper']).strip()
-    # Kill the children
-    subprocess.call(['pkill', '-P', pid], stderr=out, stdout=out)
-    # Kill the parent
-    subprocess.call(['kill', pid], stderr=out, stdout=out)
+  def __stop_test(self, out, process):
+    if process is not None:
+      # Kill the children
+      subprocess.call(['pkill', '-P', process.pid], stderr=out, stdout=out)
+      # Kill the parent 
+      process.terminate()
 
 
   ############################################################
   ############################################################
   # End __stop_test
   # End __stop_test

+ 1 - 1
toolset/benchmark/framework_test.py

@@ -347,7 +347,7 @@ class FrameworkTest:
     logging.info("Executed %s.sh, returning %s", self.setup_file, retcode)
     logging.info("Executed %s.sh, returning %s", self.setup_file, retcode)
     os.chdir(previousDir)
     os.chdir(previousDir)
 
 
-    return retcode
+    return retcode, p
   ############################################################
   ############################################################
   # End start
   # End start
   ############################################################
   ############################################################

+ 9 - 18
toolset/setup/linux/TFBReaper.c

@@ -1,28 +1,13 @@
+#define _DEFAULT_SOURCE
+
 #include <stdlib.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <sys/prctl.h>
 #include <sys/prctl.h>
 #include <sys/syscall.h>
 #include <sys/syscall.h>
-#include <asm/unistd.h>
 #include <string.h>
 #include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 
 
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
-  pid_t process_id = 0;
-  pid_t sid = 0;
-  // Create child process
-  process_id = fork();
-  // PARENT PROCESS. Need to kill it.
-  if (process_id > 0)
-  {
-    // Parent returns success in exit status
-    exit(0);
-  }
-
-  // Here we are as the child with no parent.
-
   // Gather the command line arguments for the pass-through.
   // Gather the command line arguments for the pass-through.
   int count = argc - 1;
   int count = argc - 1;
   int *sizes = malloc(sizeof(int) * count);
   int *sizes = malloc(sizeof(int) * count);
@@ -55,13 +40,19 @@ int main(int argc, char *argv[])
   // See: http://man7.org/linux/man-pages/man2/prctl.2.html
   // See: http://man7.org/linux/man-pages/man2/prctl.2.html
   prctl(PR_SET_CHILD_SUBREAPER,1);
   prctl(PR_SET_CHILD_SUBREAPER,1);
 
 
+  // Sets the process group id to that of the process id of
+  // this process. All child processes should inherit this
+  // group id unless setpgrp is called directly (which some
+  // will do).
+  setpgrp();
+
   // This invokes whatever was passed as arguments to TFBReaper
   // This invokes whatever was passed as arguments to TFBReaper
   // on the system. This program is merely a pass-through to
   // on the system. This program is merely a pass-through to
   // a shell with the subreaper stuff enabled.
   // a shell with the subreaper stuff enabled.
   int ret = system(result);
   int ret = system(result);
   free(result);
   free(result);
 
 
-  // We need to wait forever; the suite will clean this child
+  // We need to wait forever; the suite will clean this 
   // process up later.
   // process up later.
   for(;;){}
   for(;;){}