text
stringlengths
0
2.2M
// STRESS TEST
//
// Concerns:
// Test that the system can handle a large number of submitted
// jobs. Also test that in such a situation, the multiplexor will
// at some point use the maximum number of "processors" and no more.
//
// Plan:
// Create multiplexors with large queues and then submit jobs until
// the queues are full. Verify that all the jobs eventually execute,
// and verify that the maximum number of processors used is exactly
// what's specified to the multiplexor.
//
// Testing:
// processJob();
// --------------------------------------------------------------------
if (verbose) cout << "Large Queue Test" << endl
<< "================" << endl;
bslma::TestAllocator ta(veryVeryVeryVerbose);
{
enum {
NUM_THREADS = 7, // total number of threads
MAX_QUEUESIZE = 0x20000,
NUM_QUEUES = 3,
IQUEUE_MAX_PROC=2,
UQUEUE_MAX_PROC=4,
OQUEUE_MAX_PROC=1
};
bdlmt::FixedThreadPool tp(NUM_THREADS, MAX_QUEUESIZE, &ta);
TestQueue importantQueue
(IQUEUE_MAX_PROC, MAX_QUEUESIZE, &tp, &ta);
TestQueue urgentQueue
(UQUEUE_MAX_PROC, MAX_QUEUESIZE, &tp, &ta);
TestQueue otherQueue
(OQUEUE_MAX_PROC, MAX_QUEUESIZE, &tp, &ta);
if (0 != tp.start()) {
ASSERT(!"Could not start thread pool! "
"Threads cannot be created!");
break;
}
if (veryVerbose) cout << "Thread-pool Started" << endl;
UsageTestChecker iChecker(importantQueue.multiplexor());
UsageTestChecker uChecker(urgentQueue.multiplexor());
UsageTestChecker oChecker(otherQueue.multiplexor());
int iJobs = 0, uJobs = 0, oJobs = 0;
bslmt::Semaphore startSemaphore;
iChecker.setSemaphore(&startSemaphore);
uChecker.setSemaphore(&startSemaphore);
oChecker.setSemaphore(&startSemaphore);
if (veryVerbose) cout << " Adding jobs..." << endl;
for (int rc = 0; 0 == rc; ) {
rc = urgentQueue.processJob(uChecker);
if (0 == rc) {
++uJobs;
rc = importantQueue.processJob(iChecker);
if (0 == rc) {
++iJobs;
rc = otherQueue.processJob(oChecker);
if (0 == rc) {
++oJobs;
}
}
}
}
if (veryVerbose) cout << " ...Done adding" << endl;
startSemaphore.post(iJobs+uJobs+oJobs);
tp.stop();
if (veryVerbose) cout << "Thread-pool Stopped" << endl;
ASSERT(iJobs == iChecker.timesCalled());
ASSERT(uJobs == uChecker.timesCalled());
ASSERT(oJobs == oChecker.timesCalled());
if (verbose) {
P_(iJobs); P(iChecker.timesCalled());
P_(uJobs); P(uChecker.timesCalled());
P_(oJobs); P(oChecker.timesCalled());
}
LOOP_ASSERT(iChecker.maxProcessors(),
IQUEUE_MAX_PROC == iChecker.maxProcessors());
// With very low system resources it may be impossible to run the
// dispatching thread frequently enough to get all 4 threads in the
// UNIQUE group executing simultaneously. This check usually works
// but tends to fail during important release builds. Much more
// trouble than it's worth.
//
//LOOP_ASSERT(uChecker.maxProcessors(),
// UQUEUE_MAX_PROC == uChecker.maxProcessors());