Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 7 | #include <iostream> |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 8 | #include <vector> |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | #include "ThreadFactoryTests.h" |
| 12 | #include "TimerManagerTests.h" |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 13 | #include "ThreadManagerTests.h" |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 14 | |
| 15 | int main(int argc, char** argv) { |
| 16 | |
| 17 | std::string arg; |
| 18 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 19 | std::vector<std::string> args(argc - 1 > 1 ? argc - 1 : 1); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 20 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 21 | args[0] = "all"; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 22 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 23 | for (int ix = 1; ix < argc; ix++) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 24 | args[ix - 1] = std::string(argv[ix]); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 27 | bool runAll = args[0].compare("all") == 0; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 28 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 29 | if (runAll || args[0].compare("thread-factory") == 0) { |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 30 | |
| 31 | ThreadFactoryTests threadFactoryTests; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 32 | |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 33 | std::cout << "ThreadFactory tests..." << std::endl; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 34 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 35 | size_t count = 1000; |
Marc Slemko | a647903 | 2007-06-05 22:20:14 +0000 | [diff] [blame] | 36 | size_t floodLoops = 1; |
| 37 | size_t floodCount = 100000; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 38 | |
Marc Slemko | 03dedd9 | 2006-07-20 00:58:47 +0000 | [diff] [blame] | 39 | std::cout << "\t\tThreadFactory reap N threads test: N = " << count << std::endl; |
| 40 | |
| 41 | assert(threadFactoryTests.reapNThreads(count)); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 42 | |
Marc Slemko | a647903 | 2007-06-05 22:20:14 +0000 | [diff] [blame] | 43 | std::cout << "\t\tThreadFactory floodN threads test: N = " << floodCount << std::endl; |
| 44 | |
| 45 | assert(threadFactoryTests.floodNTest(floodLoops, floodCount)); |
| 46 | |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 47 | std::cout << "\t\tThreadFactory synchronous start test" << std::endl; |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 48 | |
| 49 | assert(threadFactoryTests.synchStartTest()); |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 50 | |
| 51 | std::cout << "\t\tThreadFactory monitor timeout test" << std::endl; |
| 52 | |
| 53 | assert(threadFactoryTests.monitorTimeoutTest()); |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 56 | if (runAll || args[0].compare("util") == 0) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 57 | |
| 58 | std::cout << "Util tests..." << std::endl; |
| 59 | |
| 60 | std::cout << "\t\tUtil minimum time" << std::endl; |
| 61 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 62 | int64_t time00 = Util::currentTime(); |
| 63 | int64_t time01 = Util::currentTime(); |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 64 | |
| 65 | std::cout << "\t\t\tMinimum time: " << time01 - time00 << "ms" << std::endl; |
| 66 | |
| 67 | time00 = Util::currentTime(); |
| 68 | time01 = time00; |
| 69 | size_t count = 0; |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 70 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 71 | while (time01 < time00 + 10) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 72 | count++; |
| 73 | time01 = Util::currentTime(); |
| 74 | } |
| 75 | |
| 76 | std::cout << "\t\t\tscall per ms: " << count / (time01 - time00) << std::endl; |
| 77 | } |
| 78 | |
| 79 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 80 | if (runAll || args[0].compare("timer-manager") == 0) { |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 81 | |
| 82 | std::cout << "TimerManager tests..." << std::endl; |
| 83 | |
| 84 | std::cout << "\t\tTimerManager test00" << std::endl; |
| 85 | |
| 86 | TimerManagerTests timerManagerTests; |
| 87 | |
| 88 | assert(timerManagerTests.test00()); |
| 89 | } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 90 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 91 | if (runAll || args[0].compare("thread-manager") == 0) { |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 92 | |
| 93 | std::cout << "ThreadManager tests..." << std::endl; |
| 94 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 95 | { |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 96 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 97 | size_t workerCount = 100; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 98 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 99 | size_t taskCount = 100000; |
Marc Slemko | fe5ba12e | 2006-07-20 21:16:27 +0000 | [diff] [blame] | 100 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 101 | int64_t delay = 10LL; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 102 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 103 | std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl; |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 104 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 105 | ThreadManagerTests threadManagerTests; |
| 106 | |
| 107 | assert(threadManagerTests.loadTest(taskCount, delay, workerCount)); |
Marc Slemko | 3a3b53b | 2007-05-22 23:59:54 +0000 | [diff] [blame] | 108 | |
| 109 | std::cout << "\t\tThreadManager block test: worker count: " << workerCount << " delay: " << delay << std::endl; |
| 110 | |
| 111 | assert(threadManagerTests.blockTest(delay, workerCount)); |
| 112 | |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 116 | if (runAll || args[0].compare("thread-manager-benchmark") == 0) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 117 | |
| 118 | std::cout << "ThreadManager benchmark tests..." << std::endl; |
| 119 | |
| 120 | { |
| 121 | |
| 122 | size_t minWorkerCount = 2; |
| 123 | |
| 124 | size_t maxWorkerCount = 512; |
| 125 | |
| 126 | size_t tasksPerWorker = 1000; |
| 127 | |
Mark Slee | 9b82d27 | 2007-05-23 05:16:07 +0000 | [diff] [blame] | 128 | int64_t delay = 10LL; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 129 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 130 | for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) { |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 131 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 132 | size_t taskCount = workerCount * tasksPerWorker; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 133 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 134 | std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 135 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 136 | ThreadManagerTests threadManagerTests; |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 137 | |
David Reiss | 96d2388 | 2007-07-26 21:10:32 +0000 | [diff] [blame] | 138 | threadManagerTests.loadTest(taskCount, delay, workerCount); |
Marc Slemko | c778297 | 2006-07-25 02:26:35 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
Marc Slemko | d466b21 | 2006-07-20 00:04:18 +0000 | [diff] [blame] | 141 | } |
Marc Slemko | 8a40a76 | 2006-07-19 17:46:50 +0000 | [diff] [blame] | 142 | } |