From 30075b74c9215ed3401721da019d8ec3c5771627 Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Wed, 1 May 2013 11:26:17 -0700 Subject: [PATCH] Reduce repo contention issues If there were multiple processes (or threads) trying to write to the repo, we were spending a lot of time in raw_spin_lock, resulting in almost no forward progress. The new test case runs in about 8 seconds on my dev server, with a debug build, but didnt complete in 20 minutes when using the current release build of hhvm. I also removed the 20 thread limit on the test runner, which drops the time for SlowJit from about 1:45 to 1:30, and should no longer cause repo-contention issues. --- hphp/runtime/vm/repo.cpp | 4 +-- .../program_functions/repo_contention.php | 34 +++++++++++++++++++ .../repo_contention.php.expect | 5 +++ hphp/test/verify | 3 -- 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 hphp/test/slow/program_functions/repo_contention.php create mode 100644 hphp/test/slow/program_functions/repo_contention.php.expect diff --git a/hphp/runtime/vm/repo.cpp b/hphp/runtime/vm/repo.cpp index b390a822c..afadfb675 100644 --- a/hphp/runtime/vm/repo.cpp +++ b/hphp/runtime/vm/repo.cpp @@ -14,10 +14,10 @@ +----------------------------------------------------------------------+ */ +#include "runtime/vm/repo.h" #include "util/logger.h" #include "util/trace.h" #include "util/repo_schema.h" -#include "runtime/vm/repo.h" namespace HPHP { namespace VM { @@ -425,7 +425,7 @@ static int busyHandler(void* opaque, int nCalls) { Repo* repo UNUSED = static_cast(opaque); // yield to allow other threads access to the machine // spin-wait can starve other threads. - sched_yield(); + usleep(1000 * nCalls); return 1; // Tell SQLite to retry. } diff --git a/hphp/test/slow/program_functions/repo_contention.php b/hphp/test/slow/program_functions/repo_contention.php new file mode 100755 index 000000000..9b98fdd73 --- /dev/null +++ b/hphp/test/slow/program_functions/repo_contention.php @@ -0,0 +1,34 @@ + $handle) { + $status = proc_get_status($handle); + if (!$status['running']) { + proc_close($handle); + unset($handles[$i]); + } + } + } + echo "Done $num procs\n"; + return microtime(true) - $start; +} +if (count($argv) > 1) { + foobar($argv[1]); +} else { + $x10 = main(10); + $x200 = main(200); + echo $x10 * 20 < $x200 ? "Failed" : "Passed", "\n"; +} diff --git a/hphp/test/slow/program_functions/repo_contention.php.expect b/hphp/test/slow/program_functions/repo_contention.php.expect new file mode 100644 index 000000000..73f2870d0 --- /dev/null +++ b/hphp/test/slow/program_functions/repo_contention.php.expect @@ -0,0 +1,5 @@ +Starting 10 procs +Done 10 procs +Starting 200 procs +Done 200 procs +Passed diff --git a/hphp/test/verify b/hphp/test/verify index e455630ee..0ec44a6e0 100755 --- a/hphp/test/verify +++ b/hphp/test/verify @@ -32,9 +32,6 @@ $opt_server = 0; $opt_port = 8080; $opt_home = "."; $opt_threads = `cat /proc/cpuinfo | grep '^processor' | wc -l`; -if ($opt_threads > 20) { - $opt_threads = 20; -} $opt_reduce = ""; $opt_coverage = ""; $opt_hhvm = "hhvm";