Page History
...
Time Spent per Batch (ms)/ BATCH_SIZE | 10000 | 1000 | 100 | 1 |
---|---|---|---|---|
Average Time w/o multithreading | 6.20 | 0.63 | 0.07 | 0.0009 |
Average Time w prange | 2.31 | 1.09 | 0.99 | 0.94 |
Max Time w/o multithreading | 15.49 | 13.79 | 13.45 | 13.34 |
Max Time w prange | 4.28 | 2.69 | 3.11 | 9.18 |
Min Time w/o multithreading | 1.54 | 0.16 | 0.01 | 0.0 ... |
Min Time w prange | 1.31 | 0.92 | 0.78 | 0.67 |
Std. Time w/o multithreading | 6.56 | 2.44 | 0.77 | 0.08 |
Std. Time w prange | 1.39 | 0.30 | 0.14 | 0.13 |
Simple Cython parallel performance test
We investigated how much time does Cython need to enter and exit a loop that activates and join threads (note that threads are created only once by Cython). With the simple code below, it takes about ~0.3 ms to complete.
from cython.parallel import prange def do_prange(int n, int batch_size): cdef timeval tv_st, tv_en gettimeofday(&tv_st, NULL) gettimeofday(&tv_en, NULL) |
---|
Simple std::thread performance test
This seems to be to be the case when using std::thread in c++. Running the code below also consumes about 0.3 ms.
#include <iostream> #include <thread> #include <vector> #include <sys/time.h> using namespace std; void func(int tid) { int a; a=tid; //cout << "Lanched by thread " << tid << endl; } int main() { vector<thread> th; int nr_threads = 10; struct timeval tv_st, tv_en; gettimeofday(&tv_st, NULL);
// Launch a group of threads for (int i = 0; i < nr_threads; ++i) { th.push_back(thread(func, i)); } // Join the threads with the main thread for (auto &t : th) { t.join(); }
gettimeofday(&tv_en, NULL); unsigned long ut_st, ut_en; ut_st = 1000000 * tv_st.tv_sec + tv_st.tv_usec; ut_en = 1000000 * tv_en.tv_sec + tv_en.tv_usec; cout << ut_st << " " << ut_en << " " << ut_en - ut_st << endl;
return 0; } |
---|
Conclusion
We learned that using multithreading in Smd0 has an overhead of 0.3 ms and this could hurt its performance when batch size is set to too small (e.g. 1). However, this is unlikely going the case for how we actually process the events since batch size is going to be around 1000 or more.