replace StartingGate with folly::test::Barrier

Summary:
StartingGate was similar to std::barrier except that it guaranteed the
coordinating thread woke the worker threads. While this symmetry is
nice in concept, given enough threads, I doubt it pays for the
duplication.

Just adopt folly::test::Barrier (which is basically std::barrier)
instead.

Reviewed By: strager

Differential Revision: D16942136

fbshipit-source-id: 1691d8ef72b88c8867df74c8ed938f6c8d6ee094
This commit is contained in:
Chad Austin 2019-08-27 17:08:24 -07:00 committed by Facebook Github Bot
parent 95fdcd29d5
commit 4d8aaaf6ab
5 changed files with 18 additions and 23 deletions

View File

@ -5,11 +5,11 @@
* GNU General Public License version 2.
*/
#include <boost/filesystem.hpp>
#include <fb303/test/StartingGate.h>
#include <folly/Benchmark.h>
#include <folly/File.h>
#include <folly/container/Array.h>
#include <folly/init/Init.h>
#include <folly/synchronization/test/Barrier.h>
#include <thrift/lib/cpp/async/TAsyncSocket.h>
#include <thrift/lib/cpp2/async/HeaderClientChannel.h>
#include <iostream>
@ -21,7 +21,6 @@
#include "eden/fs/service/gen-cpp2/EdenService.h"
using namespace facebook::eden;
using namespace facebook::fb303;
using namespace boost::filesystem;
DEFINE_uint64(threads, 1, "The number of concurrent Thrift client threads");
@ -67,7 +66,7 @@ int main(int argc, char** argv) {
const auto samples_per_thread = 131072;
std::vector<std::thread> threads;
StartingGate gate{static_cast<unsigned>(nthreads)};
folly::test::Barrier gate{static_cast<unsigned>(nthreads)};
std::vector<uint64_t> samples(nthreads * samples_per_thread);
for (unsigned i = 0; i < nthreads; ++i) {
threads.emplace_back(
@ -110,7 +109,6 @@ int main(int argc, char** argv) {
});
}
gate.waitThenOpen();
for (auto& thread : threads) {
thread.join();
}

View File

@ -4,11 +4,11 @@
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include <fb303/test/StartingGate.h>
#include <fcntl.h>
#include <folly/Exception.h>
#include <folly/Likely.h>
#include <folly/init/Init.h>
#include <folly/synchronization/test/Barrier.h>
#include <gflags/gflags.h>
#include <inttypes.h>
#include <string.h>
@ -23,7 +23,7 @@ DEFINE_uint64(threads, 1, "The number of concurrent open/close threads");
DEFINE_uint64(iterations, 100000, "Number of open/close iterations per thread");
using namespace facebook::eden;
using facebook::fb303::StartingGate;
using folly::test::Barrier;
int main(int argc, char** argv) {
folly::init(&argc, &argv);
@ -54,7 +54,7 @@ int main(int argc, char** argv) {
::close(fd);
}
StartingGate gate{FLAGS_threads};
folly::test::Barrier gate{FLAGS_threads};
std::mutex result_mutex;
StatAccumulator combined_open;
@ -98,8 +98,6 @@ int main(int argc, char** argv) {
threads.emplace_back([t, &thread] { thread(t); });
}
gate.waitThenOpen();
for (auto& thread : threads) {
thread.join();
}

View File

@ -4,9 +4,9 @@
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include <fb303/test/StartingGate.h>
#include <folly/Benchmark.h>
#include <folly/init/Init.h>
#include <folly/synchronization/test/Barrier.h>
#include "eden/fs/benchharness/Bench.h"
#include "eden/fs/tracing/Tracing.h"
@ -25,7 +25,7 @@ BENCHMARK(Tracer_repeatedly_create_trace_points, n) {
BENCHMARK(Tracer_repeatedly_create_trace_points_from_multiple_threads, n) {
constexpr unsigned threadCount = 8;
std::vector<std::thread> threads;
facebook::fb303::StartingGate gate{threadCount};
folly::test::Barrier gate{1 + threadCount};
{
folly::BenchmarkSuspender suspender;
enableTracing();
@ -42,7 +42,7 @@ BENCHMARK(Tracer_repeatedly_create_trace_points_from_multiple_threads, n) {
}
});
}
gate.waitThenOpen();
gate.wait();
}
for (unsigned i = 0; i < n; ++i) {
TraceBlock block{"foo"};

View File

@ -6,13 +6,12 @@
*/
#include "eden/fs/utils/ProcessAccessLog.h"
#include <fb303/test/StartingGate.h>
#include <folly/Benchmark.h>
#include <folly/synchronization/test/Barrier.h>
#include "eden/fs/benchharness/Bench.h"
#include "eden/fs/utils/ProcessNameCache.h"
using namespace facebook::eden;
using namespace facebook::fb303;
/**
* A high but realistic amount of contention.
@ -26,7 +25,7 @@ BENCHMARK(ProcessAccessLog_repeatedly_add_self, iters) {
ProcessAccessLog processAccessLog{processNameCache};
std::vector<std::thread> threads;
StartingGate gate{kThreadCount};
folly::test::Barrier gate{kThreadCount + 1};
size_t remainingIterations = iters;
size_t totalIterations = 0;
@ -47,10 +46,10 @@ BENCHMARK(ProcessAccessLog_repeatedly_add_self, iters) {
CHECK_EQ(totalIterations, iters);
suspender.dismiss();
// Now wake the threads.
gate.waitThenOpen();
gate.wait();
suspender.dismiss();
// Wait until they're done.
for (auto& thread : threads) {

View File

@ -6,8 +6,8 @@
*/
#include "eden/fs/utils/ProcessNameCache.h"
#include <fb303/test/StartingGate.h>
#include <folly/Benchmark.h>
#include <folly/synchronization/test/Barrier.h>
#include "eden/fs/benchharness/Bench.h"
using namespace facebook::eden;
@ -22,7 +22,7 @@ BENCHMARK(ProcessNameCache_repeatedly_add_self, iters) {
ProcessNameCache processNameCache;
std::vector<std::thread> threads;
facebook::fb303::StartingGate gate{kThreadCount};
folly::test::Barrier gate{1 + kThreadCount};
size_t remainingIterations = iters;
size_t totalIterations = 0;
@ -42,10 +42,10 @@ BENCHMARK(ProcessNameCache_repeatedly_add_self, iters) {
CHECK_EQ(totalIterations, iters);
suspender.dismiss();
// Now wake the threads.
gate.waitThenOpen();
gate.wait();
suspender.dismiss();
// Wait until they're done.
for (auto& thread : threads) {