Core of sequential version of myth-buster
- Sequentially connects to all ~30 myth machines and asks each for the total number of processes being run by CS110 students.
- Networking details are abstracted away and packaged in a library routine with the following prototype:
int getNumProcesses(unsigned short num, const unordered_set<string>& sunetIDs);
- num is the myth machine number (e.g. 14 for myth14), and sunetIDs is a hashset housing the SUNet IDs of all students currently enrolled in CS110 according to our /usr/class/cs110/repos/assign3/ directory.
- Here is the sequential (and very slow) implementation of a compileCS110ProcessCountMap, which very brute force and CS106B-ish. (It assumes that sunetIDs has already been configured with the set of all CS110 student SUNet IDs, and it further assumes that counts refers to an initially empty map).
- Full program is right here.
static unsigned short kMinMythMachine = 1;
static unsigned short kMaxMythMachine = 32;
static void compileCS110ProcessCountMap(const unordered_set<string>& sunetIDs,
map<unsigned short, unsigned short>& counts) {
for (unsigned short num = kMinMythMachine; num <= kMaxMythMachine; num++) {
int numProcesses = getNumProcesses(num, sunetIDs);
if (numProcesses >= 0) { // -1 expresses networking failure
counts[num] = numProcesses;
cout << "myth" << num << " has this many CS110-student processes: "
<< numProcesses << endl;
}
}
}
- Each call to getNumProcesses is slow, and the accumulation of some 30 sequential calls is painfully slow.
- Running the sequential version takes on the order of 40 seconds, even though 99% of that time is spent waiting for a network connections to be established.