void BCTest::setUp() { LBIDRange_v r; HWM_t hwm; OID_t oid=1000; extentSize = dbrm.getExtentSize(); maxBlocksAvailable=0; int i=0; fExtentSize=dbrm.getExtentSize(); while ( oid < 5000 ) { int ret=0; ret = dbrm.lookup(oid, r); if (ret==0 && r.size()>0) { dbrm.getHWM(oid, hwm); maxBlocksAvailable+=(r.size()*extentSize); OidRanges_t oid_range(oid, hwm, r); OidRangesList.push_back(oid_range); //cout << "Setup i: " << i++ << " o: " << oid // << " r: " << ret << " s: " << r.size() // << " m: " << maxBlocksAvailable // << endl; hwm=0; r.clear(); } oid++; } //cout << "\t" << OidRangesList.size() << " oid ranges loaded " << endl << endl; i=0; } // setUp()
void ReadRange(const LBIDRange_v& v) { blockCacheClient bc(BRP); int found=0; int notfound=0; int ret=0; for(uint32_t i=0; i<v.size(); i++) { const InlineLBIDRange r= {v[i].start, v[i].size}; FileBuffer fb(-1, -1); for(int j=r.start; j<r.start+r.size; j++) { if (r.size > 1024) continue; ret=bc.read(j, ver, fb); if (ret) found++; else notfound++; ret=0; } totBlocks+=found; totBlocks+=notfound; found=0; notfound=0; } }
void LoadRange(const LBIDRange_v& v, uint32_t& loadCount) { blockCacheClient bc(BRP); uint32_t rCount=0; for (uint32_t i =0; i<v.size() ; i++) { const InlineLBIDRange r= {v[i].start, v[i].size}; if (r.size<=1024) { bc.check(r, ver, rCount ); loadCount+=rCount; } rCount=0; } }
int main(int argc, char *argv[]) { if (argc>=2) thr_cnt=atoi(argv[1]); if (argc>=3) fLoops=atoi(argv[2]); if (thr_cnt<=0) thr_cnt=1; if (thr_cnt>1024) thr_cnt=1024; if (fLoops<=0) fLoops=1; LBIDRange_v r; vector<LBIDRange_v> ranges; DBRM dbrm; uint32_t hwm, lowfbo, highfbo, fbo, extentSize, lowlbid; struct timeval tv, tv2; cout << "Starting " << endl; extentSize = dbrm.getExtentSize(); BRM::OID_t oid=3000; uint32_t totalExt=0; do { int ret = dbrm.lookup(oid, r); if (ret==0 && r.size() > 0) { lowlbid = (r[0].start/extentSize) * extentSize; dbrm.lookup(r[0].start, ver, false, oid, fbo); // need the oid dbrm.getHWM(oid, hwm); lowfbo = fbo - (r[0].start - lowlbid); highfbo = lowfbo + extentSize; r[0].start=lowlbid; if (hwm < highfbo) r[0].size = hwm - lowfbo + 1; else r[0].size = extentSize; for (uint32_t idx=0; idx<r.size(); idx++) totalExt+=r[idx].size; ranges.push_back(r); } oid++; } while ( (r.size() > 0 || oid < 900000) ); cout << ranges.size() << " ranges found" << endl; gettimeofday(&tv, NULL); uint32_t blksLoaded=0; int rangesLoaded=0; for (uint32_t i =0; i<ranges.size() && blksLoaded < cacheSize; i++) { LoadRange(ranges[i], blksLoaded); rangesLoaded++; } cout << endl; gettimeofday(&tv2, NULL); cout << "Loaded: " << blksLoaded << " blks " << rangesLoaded << " ranges sec: " << tv2.tv_sec - tv.tv_sec <<endl; while (ranges.size() > rangesLoaded) ranges.pop_back(); #ifdef BLAH for (uint32_t i =0; i<ranges; i++) ReadRange(ranges[i]); for (uint32_t i =0; i<ranges.size(); i++) { LBIDRange_v rv=ranges[i]; for(uint32_t j=0; j < rv.size(); j++) { const InlineLBIDRange l = {rv[j].start, rv[j].size}; for(uint32_t k=l.start; k<l.start+l.size; k++) { LoadLbid(k, ver); ReadLbid(k, ver); } } } #endif pthread_t thr_id[thr_cnt]; thr_wait_t thr_wait= {0, PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, ranges}; //start threads running cout << "Starting driver threads" << endl; gettimeofday(&tv, NULL); memset(thr_id, 0, thr_cnt*(sizeof(pthread_t))); for(int i=0; i<thr_cnt; i++) { pthread_create(&thr_id[i], NULL, thr_client, &thr_wait); } // waiting until all threads have indicated completion pthread_mutex_lock(&thr_wait.fMutex); while (thr_wait.predicate>0) { pthread_cond_wait(&thr_wait.fCond, &thr_wait.fMutex); } pthread_mutex_unlock(&thr_wait.fMutex); // join threads back to main for(int i=0; i<thr_cnt; i++) { pthread_join(thr_id[i], NULL); } gettimeofday(&tv2, NULL); time_t tm=time(0); char t[50]; ctime_r(&tm, t); t[strlen(t)-1]=0; uint32_t elTime=tv2.tv_sec-tv.tv_sec; uint64_t total = bfoundTot + rfoundTot; uint64_t avgTot=0; uint64_t rangeAvg=0; uint64_t blkAvg=0; if (elTime>0) { avgTot=(bfoundTot+rfoundTot)/elTime; rangeAvg=(rfoundTot)/elTime; blkAvg=(bfoundTot)/elTime; } else { avgTot=bfoundTot+rfoundTot; rangeAvg=rfoundTot; blkAvg=bfoundTot; } cout << "Summary tm " << t << " " << (tv2.tv_sec-tv.tv_sec) << endl << "\tBlk: c " << blockOpCountTot << " pass " << bfoundTot << " fail " << bnfoundTot << //"\tRng: c "<< rangeOpCountTot << " pass " << rfoundTot << " fail " << rnfoundTot << endl << //"\tNoOp: c " << noOpCountTot << " Total " << total << endl << //"\tblks/sec Blk " << blkAvg << " Rng " << rangeAvg << " Tot " << avgTot << " Thr " << avgTot/thr_cnt << endl << endl; " Blks/Sec Blk " << blkAvg << " Thr " << avgTot/thr_cnt << endl << endl; return 0; } // end main