MCPcopy Create free account
hub / github.com/apache/thrift / loadTest

Method loadTest

lib/cpp/test/concurrency/ThreadManagerTests.h:95–189  ·  view source on GitHub ↗

* Dispatch count tasks, each of which blocks for timeout milliseconds then * completes. Verify that all tasks completed and that thread manager cleans * up properly on delete. */

Source from the content-addressed store, hash-verified

93 * up properly on delete.
94 */
95 bool loadTest(size_t count = 100, int64_t timeout = 100LL, size_t workerCount = 4) {
96
97 Monitor monitor;
98
99 size_t activeCount = count;
100
101 shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);
102
103 shared_ptr<ThreadFactory> threadFactory
104 = shared_ptr<ThreadFactory>(new ThreadFactory(false));
105
106 threadManager->threadFactory(threadFactory);
107
108 threadManager->start();
109
110 std::set<shared_ptr<ThreadManagerTests::Task> > tasks;
111
112 for (size_t ix = 0; ix < count; ix++) {
113
114 tasks.insert(shared_ptr<ThreadManagerTests::Task>(
115 new ThreadManagerTests::Task(monitor, activeCount, timeout)));
116 }
117
118 int64_t time00 = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
119
120 for (auto ix = tasks.begin();
121 ix != tasks.end();
122 ix++) {
123
124 threadManager->add(*ix);
125 }
126
127 std::cout << "\t\t\t\tloaded " << count << " tasks to execute" << '\n';
128
129 {
130 Synchronized s(monitor);
131
132 while (activeCount > 0) {
133 std::cout << "\t\t\t\tactiveCount = " << activeCount << '\n';
134 monitor.wait();
135 }
136 }
137
138 int64_t time01 = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
139
140 int64_t firstTime = 9223372036854775807LL;
141 int64_t lastTime = 0;
142
143 double averageTime = 0;
144 int64_t minTime = 9223372036854775807LL;
145 int64_t maxTime = 0;
146
147 for (auto ix = tasks.begin();
148 ix != tasks.end();
149 ix++) {
150
151 shared_ptr<ThreadManagerTests::Task> task = *ix;
152

Callers 1

mainFunction · 0.80

Calls 8

nowFunction · 0.85
threadFactoryMethod · 0.45
startMethod · 0.45
countMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
addMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected