24 #include <boost/thread/thread.hpp>
25 #include <boost/foreach.hpp>
26 #include <boost/bind.hpp>
30 using namespace impala;
80 for (
int i = 0; i < num_threads; ++i) {
81 threads.add_thread(
new thread(f));
88 vector<Thread*> threads;
89 threads.reserve(num_threads);
90 for (
int i=0; i < num_threads; ++i) {
91 threads.push_back(
new Thread(
"mythreadgroup",
"thread", f));
93 BOOST_FOREACH(
Thread* thread, threads) {
103 bool use_native_threads =
true) {
106 if (use_native_threads) {
107 function<void ()> f =
111 function<void ()> f =
116 cout << (use_native_threads ?
"(Native):" :
"(Impala):")
117 <<
"Time to start up " << num_threads <<
" * " << num_threads_per_executor <<
" = "
118 << num_threads * num_threads_per_executor <<
" threads: "
122 int main(
int argc,
char **argv) {
123 google::InitGoogleLogging(argv[0]);
127 cout <<
"-----------------Benchmark 1: Single-threaded thread creation" << endl;
141 cout <<
"Total time (Native): "
147 total_time_imp.
Start();
155 total_time_imp.Stop();
157 cout <<
"Total time (IMPALA): "
161 int64_t difference = total_time_imp.ElapsedTime() - total_time.
ElapsedTime();
162 cout <<
"Impala thread overhead: "
164 <<
", which is " << (difference * 100.0 / total_time.
ElapsedTime())
165 <<
"%" << endl << endl;
168 cout <<
"-----------------Benchmark 2: Multi-threaded thread creation" << endl;
172 total_time_parallel_native.
Start();
179 total_time_parallel_native.
Stop();
181 cout <<
"Total time (Native): "
188 total_time_parallel_impala.
Start();
195 total_time_parallel_impala.Stop();
197 cout <<
"Total time (IMPALA): "
202 difference = total_time_parallel_impala.ElapsedTime()
204 cout <<
"Impala thread overhead: "
206 <<
", which is " << (difference * 100.0 / total_time_parallel_native.
ElapsedTime())
uint64_t ElapsedTime() const
Returns time in cpu ticks.
int main(int argc, char **argv)
TODO: Consider allowing fragment IDs as category parameters.
void NativeThreadStarter(int num_threads, const function< void()> &f)
void TimeParallelExecutors(int num_threads, int num_threads_per_executor, bool use_native_threads=true)
static std::string Print(bool value, TUnit::type ignored, bool verbose=false)
void InitThreading()
Initialises the threading subsystem. Must be called before a Thread is created.
static void Init()
Initialize CpuInfo.
void ImpalaThreadStarter(int num_threads, const function< void()> &f)