diff --git a/be/src/benchmarks/thread-create-benchmark.cc b/be/src/benchmarks/thread-create-benchmark.cc index cac1f1c..09bd04e 100644 --- a/be/src/benchmarks/thread-create-benchmark.cc +++ b/be/src/benchmarks/thread-create-benchmark.cc @@ -23,12 +23,23 @@ #include "util/pretty-printer.h" #include "util/thread.h" #include "util/stopwatch.h" +#include #include #include #include "common/names.h" +#include +#include +#include +#include +#include "rpc/thrift-client.h" +#include "rpc/thrift-server.h" +#include "rpc/thrift-thread.h" +using apache::thrift::concurrency::ThreadFactory; +using namespace apache::thrift::concurrency; +using namespace apache::thrift; using namespace impala; // Benchmark for thread creation time using native threads and @@ -73,6 +84,28 @@ using namespace impala; // details. Without blocking, thread creation benchmark times are always within ~5% of // each other. +class RunnableTask : public Runnable { + public: + + void run() { + unsigned int microseconds = 1 << 10; + usleep(microseconds); + boost::this_thread::sleep( boost::posix_time::seconds(60)); + } +}; + +void ThriftThreadStarter(int num_threads) { + boost::shared_ptr thread_factory( + new ThriftThreadFactory("test", "test")); + + for (int i = 0; i < num_threads; ++i) { + RunnableTask* task = new RunnableTask(); + boost::shared_ptr runnable = boost::shared_ptr(task); + boost::shared_ptr thread = thread_factory->newThread(runnable); + thread->start(); + } +} + void EmptyThread() { } @@ -86,17 +119,7 @@ void NativeThreadStarter(int num_threads, const function& f) { } // Runs N Impala Threads, each executing 'f' -void ImpalaThreadStarter(int num_threads, const function& f) { - vector threads; - threads.reserve(num_threads); - for (int i=0; i < num_threads; ++i) { - threads.push_back(new Thread("mythreadgroup", "thread", f)); - } - for (Thread* thread: threads) { - thread->Join(); - delete thread; - } -} +void ImpalaThreadStarter(int num_threads, const function& f) {} // Times how long it takes to run num_threads 'executors', each of // which spawns num_threads_per_executor empty threads, and to wait @@ -121,6 +144,18 @@ void TimeParallelExecutors(int num_threads, int num_threads_per_executor, << PrettyPrinter::Print(sw.ElapsedTime(), TUnit::CPU_TICKS) << endl; } + +void TimeThriftParallelExecutors(int num_threads, int num_threads_per_executor) { + StopWatch sw; + sw.Start(); + ThriftThreadStarter(num_threads); + sw.Stop(); + cout << "(Thrift):" + << "Time to start up " << num_threads << " * " << num_threads_per_executor << " = " + << num_threads * num_threads_per_executor << " threads: " + << PrettyPrinter::Print(sw.ElapsedTime(), TUnit::CPU_TICKS) << endl; +} + int main(int argc, char **argv) { google::InitGoogleLogging(argv[0]); CpuInfo::Init(); @@ -208,5 +243,12 @@ int main(int argc, char **argv) { << ", which is " << (difference * 100.0 / total_time_parallel_native.ElapsedTime()) << "%" << endl; + cout << "-----------------Benchmark 3: Thrift threads" << endl; + for (int j = 0 ; j < 100; j++){ + for (int i = 0; i < 2000; ++i) { + TimeThriftParallelExecutors(1, 30000); + } + } + return 0; }