void testFind(int port, int top = 10000000) { DjondbConnection* conn = DjondbConnectionManager::getConnection("localhost", port); if (!conn->open()) { cout << "Not connected" << endl; exit(0); } Logger* log = getLogger(NULL); log->startTimeRecord(); log->info("Testing find performance over: %d finds.", top); for (int x = 0; x < top; x++) { BSONArrayObj* arr = conn->executeQuery("select top 1 * from db:testperformance"); if (arr->length() == 0) { log->info("Error an id was not found"); exit(1); } delete arr; } log->stopTimeRecord(); DTime time = log->recordedTime(); cout << "Total find secs: " << time.totalSecs() << endl; if (time.totalSecs() > 0) { log->info("Found %d: throughtput: %d.", top, (top / time.totalSecs())); } else { log->info("Found :%d, throughtput too high to be measured", top); } if ((time.totalSecs() > 0) && ((top / time.totalSecs()) < 16000)) { log->info("Performance is not good enough"); } }
void* producer(void* arg) { NetworkOutputStream* nos = new NetworkOutputStream(); int socket = nos->open("localhost", _port); printf("Producer started\n"); Logger* log = getLogger(NULL); log->info("Producer starter"); log->startTimeRecord(); if (socket > 0) { NetworkInputStream* nis = new NetworkInputStream(socket); std::auto_ptr<CommandWriter> writer(new CommandWriter(nos)); for (int x = 0; x < MAX_INSERT; x++) { std::auto_ptr<InsertCommand> cmd(new InsertCommand()); BSONObj* obj = new BSONObj(); std::auto_ptr<std::string> guid(uuid()); obj->add("_id", guid->c_str()); char* temp = (char*)malloc(2000); memset(temp, 0, 2000); memset(temp, 'a', 1999); int len = strlen(temp); obj->add("content", temp); free(temp); cmd->setBSON(obj); std::string db("mydb"); cmd->setDB(db); std::string ns("myns"); cmd->setNameSpace(ns); cmd->setOptions(new BSONObj()); writer->writeCommand(cmd.get()); int result = nis->readInt(); EXPECT_EQ(result, 1); if (result != 1) { break; } } nis->close(); } else { printf("Socket is 0"); } log->info("Producer end"); log->stopTimeRecord(); DTime time = log->recordedTime(); if (time.totalSecs() > 0) { log->info("Producer time: %d secs. Operations per sec: %d", time.totalSecs(), MAX_INSERT / time.totalSecs()); } else { EXPECT_TRUE(false) << "Something was wrong network could not execute " << MAX_INSERT << " in 0 secs."; } }
void testCommand(int port, int top = 10000000) { DjondbConnection* conn = DjondbConnectionManager::getConnection("localhost", port); if (!conn->open()) { cout << "Not connected" << endl; exit(0); } Logger* log = getLogger(NULL); log->startTimeRecord(); log->info("Testing command performance over: %d executions.", top); for (int x = 0; x < top; x++) { std::vector<std::string>* dbs = conn->dbs(); if (dbs == NULL) { log->info("Test command failed and returned NULL"); exit(1); } if (dbs->size() == 0) { log->info("Test command failed and returned 0 elements"); exit(1); } delete dbs; } log->stopTimeRecord(); DTime time = log->recordedTime(); cout << "Total secs: " << time.totalSecs() << endl; if (time.totalSecs() > 0) { log->info("Executed %d: throughtput: %d.", top, (top / time.totalSecs())); } else { log->info("Executed %d, throughtput too high to be measured", top); } if ((time.totalSecs() > 0) && ((top / time.totalSecs()) < 5000)) { log->info("Performance is not good enough"); } }
TEST(testUtil, testLogger) { // Test timer // Logger* log = getLogger(NULL); log->startTimeRecord(); Thread::sleep(3000); log->stopTimeRecord(); DTime time = log->recordedTime(); long secs = time.totalSecs(); EXPECT_TRUE(secs > 2); EXPECT_TRUE(secs < 4); }
void testPerfomance(int port, int top = 10000000) { DjondbConnection* conn = DjondbConnectionManager::getConnection("localhost", port); if (!conn->open()) { cout << "Not connected" << endl; exit(0); } // 1k inserts // Logger* log = getLogger(NULL); log->info("Testing performance over: %d inserts.", top); std::vector<std::string>* names = generateNames(top); std::vector<std::string*>* ids = new std::vector<std::string*>(); log->startTimeRecord(); for (int x = 0; x < top; x++) { BSONObj obj; char* text = (char*)malloc(1001); memset(text, 0, 1001); memset(text, 'a', 1000); std::string* id = uuid(); obj.add("_id", id->c_str()); int test = rand() % 100; if (test > 30) { ids->push_back(id); } else { delete id; } obj.add("t", x); obj.add("text", text); obj.add("name", const_cast<char*>(names->at(x).c_str())); conn->insert("db", "testperformance", obj); free(text); // every 10 % will print a message showing the progress if ((x % (top / 10)) == 0) { DTime timeTemp = log->recordedTime(); int progress = (x * 100) / top; if (timeTemp.totalSecs() > 0) { log->info("Inserted %d: throughtput: %d per sec. %d comnpleted", x, (x / timeTemp.totalSecs()), progress); } else { log->info("Inserted :%d, throughtput too high to be measured. %d completed.", x, progress); } } } log->stopTimeRecord(); DTime time = log->recordedTime(); cout << "Total secs: " << time.totalSecs() << endl; if (time.totalSecs() > 0) { log->info("Inserted %d: throughtput: %d.", top, (top / time.totalSecs())); } else { log->info("Inserted %d, throughtput too high to be measured", top); } if ((time.totalSecs() > 0) && ((top / time.totalSecs()) < 16000)) { log->info("Performance is not good enough"); } conn->close(); delete log; }