Exemplo n.º 1
0
MojErr MojDbPerfUpdateTest::updateObjsViaPut(MojDb& db, const MojChar* kindId, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
	// register all the kinds
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// put objects using createFn
	MojObject objs;
	err = putObjs(db, kindId, numInsertForPut, createFn, objs);
	MojTestErrCheck(err);

	MojObject midObj;
	bool found = objs.at(numInsertForPut/2, midObj);
	MojTestAssert(found);

	MojTime objTime;
	err = putObj(db, midObj, objTime);
	MojTestErrCheck(err);
	MojUInt64 putTime = objTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   putting single object - index %llu - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/2, kindId, numPutIterations, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per put: %llu microsecs", (putTime) / (numPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("Put single object - index %llu - %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/2, numPutIterations, kindId, putTime, putTime/numPutIterations, putTime/(1*numPutIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	MojTime batchTime;
	MojObject::ArrayIterator beginArr;
	err = objs.arrayBegin(beginArr);
	MojErrCheck(err);
	err = batchPutObj(db, beginArr, beginArr + (numInsertForPut / 10), batchTime);
	putTime = batchTime.microsecs();
	MojTestErrCheck(err);
	err = MojPrintF("   putting batch - %llu objects - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/10, kindId, numBatchPutIterations, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per batch put: %llu microsecs\n", (putTime) / (numBatchPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (putTime) / (numInsertForPut/10 * numBatchPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	err = buf.format("Batch put %llu objects %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/10, numBatchPutIterations, kindId, putTime, putTime/numBatchPutIterations, putTime/(numInsertForPut/10*numBatchPutIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 2
0
MojErr MojDbPerfUpdateTest::updateKind(MojDb& db, const MojChar* kindId, const MojChar* kindJson, const MojChar* extraIdxJson, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
	// register all the kinds
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// put objects using createFn
	MojObject objs;
	err = putObjs(db, kindId, numObjectsBeforeUpdateKind, createFn, objs);
	MojTestErrCheck(err);

	// add an index
	MojObject kindObj;
	err = kindObj.fromJson(kindJson);
	MojTestErrCheck(err);
	MojObject indexes;
	kindObj.get(_T("indexes"), indexes);
	MojTestErrCheck(err);

	MojObject extraIdx;
	err = extraIdx.fromJson(extraIdxJson);
	MojTestErrCheck(err);
	indexes.push(extraIdx);

	err = kindObj.put(_T("indexes"), indexes);
	MojTestErrCheck(err);

	MojTime addIndexTime;
	MojTime dropIndexTime;
	err = timeUpdateKind(db, kindJson, kindObj, addIndexTime, dropIndexTime);
	MojTestErrCheck(err);

	MojUInt64 addTime = addIndexTime.microsecs();
	MojUInt64 dropTime = dropIndexTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   updating kind %s - adding index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, addTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per add/reindex: %llu microsecs\n", (addTime) / (numUpdateKindIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   updating kind %s - dropping index %s %llu times took: %llu microsecs\n", kindId, extraIdxJson, numUpdateKindIterations, dropTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per drop: %llu microsecs", (dropTime) / (numUpdateKindIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("Updating kind %s - adding index %s %llu times,%s,%llu,%llu,%llu,\nUpdating kind %s - dropping index %s %llu times,%s,%llu,%llu,%llu,\n",
			kindId, extraIdxJson, numUpdateKindIterations, kindId, addTime, addTime/numUpdateKindIterations, addTime/(1*numUpdateKindIterations),
			kindId, extraIdxJson, numUpdateKindIterations, kindId, dropTime, dropTime/numUpdateKindIterations, dropTime/(1*numUpdateKindIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 3
0
MojErr MojDbPerfCreateTest::testBatchInsertLgArrayObj(MojDb& db, const MojChar* kindId)
{
	// register all the kinds again
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// time put with large array objects (20 properties + 2 arrays of 5 elements each)
	MojTime batchLgArrayObjTime = 0;
	for (int i = 0; i < numRepetitions; i++) {
		err = putLargeArrayObj(db, kindId, batchLgArrayObjTime);
		MojTestErrCheck(err);
		MojDbQuery q;
		err = q.from(kindId);
		MojTestErrCheck(err);
		MojUInt32 count = 0;
		err = db.del(q, count);
		MojTestErrCheck(err);
	}

	MojUInt64 putTime = batchLgArrayObjTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   time to batch put %llu %s objects %d times: %llu microsecs\n", numInsert, kindId, numRepetitions, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per batch: %llu microsecs", (putTime) / (numRepetitions));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (putTime) / (numInsert * numRepetitions));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);
	MojString buf;
	err = buf.format("batch put %llu objects %d times,%s,%llu,%llu,%llu,\n", numInsert, numRepetitions, kindId, putTime, putTime/numRepetitions, putTime / (numInsert * numRepetitions));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 4
0
MojErr MojDbPerfCreateTest::testInsertMedArrayObj(MojDb& db, const MojChar* kindId)
{
	// register all the kinds again
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// time put with med array objects (10 properties + 1 array of 5 elements)
	MojTime medArrayObjTime;
	for (int i = 0; i < numRepetitions; i++) {
		err = putMedArrayObj(db, kindId, medArrayObjTime);
		MojTestErrCheck(err);
		MojDbQuery q;
		err = q.from(kindId);
		MojTestErrCheck(err);
		MojUInt32 count = 0;
		err = db.del(q, count, MojDb::FlagPurge);
		MojTestErrCheck(err);
	}

	MojUInt64 putTime = medArrayObjTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   time to put %llu %s objects %d times: %llu microsecs\n", numInsert, kindId, numRepetitions, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (putTime) / (numInsert * numRepetitions));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);
	MojString buf;
	err = buf.format("put %llu objects %d times,%s,%llu,%llu,%llu,\n", numInsert, numRepetitions, kindId, putTime, putTime/numRepetitions, putTime / (numInsert * numRepetitions));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);


	return MojErrNone;
}
Exemplo n.º 5
0
MojErr MojDbPerfCreateTest::testInsertLgNestedObj(MojDb& db, const MojChar* kindId)
{
	// register all the kinds again
	MojUInt64 time = 0;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// time put with large nested objects (3 levels of nesting, 20 properties)
	MojUInt64 largeNestedObjTime = 0;
	for (int i = 0; i < numRepetitions; i++) {
		err = putLargeNestedObj(db, kindId, largeNestedObjTime);
		MojTestErrCheck(err);
		MojDbQuery q;
		err = q.from(kindId);
		MojTestErrCheck(err);
		MojUInt32 count = 0;
		err = db.del(q, count, MojDb::FlagPurge);
		MojTestErrCheck(err);
	}

	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   time to put %llu %s nested objects %d times: %llu nanosecs\n", numInsert, kindId, numRepetitions, largeNestedObjTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu nanosecs", (largeNestedObjTime) / (numInsert * numRepetitions));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);
	MojString buf;
	err = buf.format("put %llu objects %d times,%s,%llu,%llu,%llu,\n", numInsert, numRepetitions, kindId, largeNestedObjTime, largeNestedObjTime/numRepetitions, largeNestedObjTime / (numInsert * numRepetitions));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);


	return MojErrNone;
}
Exemplo n.º 6
0
MojErr MojDbPerfUpdateTest::updateObjsViaMerge(MojDb& db, const MojChar* kindId, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
	// register all the kinds
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// put objects using createFn
	MojObject objs;
	err = putObjs(db, kindId, numInsertForPut, createFn, objs);
	MojTestErrCheck(err);

	MojObject midObj;
	bool found = objs.at(numInsertForPut/2, midObj);
	MojTestAssert(found);

	MojTime objTime;
	err = mergeObj(db, midObj, objTime);
	MojTestErrCheck(err);
	MojUInt64 mergeTime = objTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   merging single object - index %llu - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/2, kindId, numMergeIterations, mergeTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per merge: %llu microsecs", (mergeTime) / (numMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("Merge single object - index %llu - %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/2, numMergeIterations, kindId, mergeTime, mergeTime/numMergeIterations, mergeTime/(1*numMergeIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	MojTime batchTime;
	MojObject::ArrayIterator beginArr;
	err = objs.arrayBegin(beginArr);
	MojErrCheck(err);
	err = batchMergeObj(db, beginArr, beginArr + (numInsertForPut / 10), batchTime);
	MojTestErrCheck(err);
	mergeTime = batchTime.microsecs();
	err = MojPrintF("   merging batch - %llu objects - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/10, kindId, numBatchMergeIterations, mergeTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per batch merge: %llu microsecs\n", (mergeTime) / (numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (mergeTime) / (numInsertForPut/10 * numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	err = buf.format("Batch merge %llu objects %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/10, numBatchMergeIterations, kindId, mergeTime, mergeTime/numBatchMergeIterations, mergeTime/(numInsertForPut/10*numBatchMergeIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	MojTime mergeQueryTime;
	MojTestErrCheck(err);
	MojDbQuery query;
	err = query.from(kindId);
	MojTestErrCheck(err);
	query.limit(numInsertForPut/5);
	query.desc(true);

	MojObject queryObj;
	err = query.toObject(queryObj);
	MojTestErrCheck(err);
	MojString queryStr;
	err = queryObj.stringValue(queryStr);
	MojTestErrCheck(err);

	MojObject props;
	err = props.putString(_T("newKey"), _T("here's a new value"));
	MojTestErrCheck(err);
	MojUInt32 count;
	err = queryMergeObj(db, query, props, count, mergeQueryTime);
	MojTestErrCheck(err);
	mergeTime = mergeQueryTime.microsecs();
	err = MojPrintF("   merging with query - %d objects - of kind %s %llu times took: %llu microsecs\n", count, kindId, numBatchMergeIterations, mergeTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per merge: %llu microsecs\n", (mergeTime) / (numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (mergeTime) / (count * numBatchMergeIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	err = buf.format("Merge with query %s,,,,,\nMerge with query - %d objects - %llu times,%s,%llu,%llu,%llu,\n", queryStr.data(), count, numBatchMergeIterations, kindId, mergeTime, mergeTime/numBatchMergeIterations, mergeTime/(count*numBatchMergeIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 7
0
MojErr MojDbPerfCreateTest::testCreate()
{
	MojDb db;

	MojErr err = db.open(MojDbTestDir);
	MojTestErrCheck(err);

	// time put kind
	MojUInt64 putKindTime = 0;
	for (int i = 0; i < numRepetitions; i++) {
		err = putKinds(db, putKindTime);
		MojTestErrCheck(err);
		err = delKinds(db);
		MojTestErrCheck(err);
	}

	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   putKind took: %llu nanosecs", (putKindTime / (numKinds * numRepetitions)));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("put Kind,all %llu kinds,%llu,%llu,%llu,\n", numKinds, putKindTime, putKindTime/numRepetitions, putKindTime / (numKinds * numRepetitions));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	// insert objects with one index
	err = testInsertSmallObj(db, MojPerfSmKindId);
	MojTestErrCheck(err);
	err = testInsertMedObj(db, MojPerfMedKindId);
	MojTestErrCheck(err);
	err = testInsertLgObj(db, MojPerfLgKindId);
	MojTestErrCheck(err);
	err = testInsertMedNestedObj(db, MojPerfMedNestedKindId);
	MojTestErrCheck(err);
	err = testInsertLgNestedObj(db, MojPerfLgNestedKindId);
	MojTestErrCheck(err);
	err = testInsertMedArrayObj(db, MojPerfMedArrayKindId);
	MojTestErrCheck(err);
	err = testInsertLgArrayObj(db, MojPerfLgArrayKindId);
	MojTestErrCheck(err);

	// insert objects with two indices
	err = testInsertSmallObj(db, MojPerfSmKind2Id);
	MojTestErrCheck(err);
	err = testInsertMedObj(db, MojPerfMedKind2Id);
	MojTestErrCheck(err);
	err = testInsertLgObj(db, MojPerfLgKind2Id);
	MojTestErrCheck(err);
	err = testInsertMedNestedObj(db, MojPerfMedNestedKind2Id);
	MojTestErrCheck(err);
	err = testInsertLgNestedObj(db, MojPerfLgNestedKind2Id);
	MojTestErrCheck(err);
	err = testInsertMedArrayObj(db, MojPerfMedArrayKind2Id);
	MojTestErrCheck(err);
	err = testInsertLgArrayObj(db, MojPerfLgArrayKind2Id);
	MojTestErrCheck(err);

	// batch insert with one index
	err = testBatchInsertLgObj(db, MojPerfLgKindId);
	MojTestErrCheck(err);
	err = testBatchInsertLgNestedObj(db, MojPerfLgNestedKindId);
	MojTestErrCheck(err);
	err = testBatchInsertLgArrayObj(db, MojPerfLgArrayKindId);
	MojTestErrCheck(err);

	// batch insert with two indices
	err = testBatchInsertLgObj(db, MojPerfLgKind2Id);
	MojTestErrCheck(err);
	err = testBatchInsertLgNestedObj(db, MojPerfLgNestedKind2Id);
	MojTestErrCheck(err);
	err = testBatchInsertLgArrayObj(db, MojPerfLgArrayKind2Id);
	MojTestErrCheck(err);

	err = db.close();
	MojTestErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 8
0
MojErr MojDbPerfCreateTest::testCreate()
{

	//setup the test storage engine
#ifdef MOJ_USE_BDB
	MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbBerkeleyEngine());
#elif MOJ_USE_LDB
	MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbLevelEngine());
#else
    MojRefCountedPtr<MojDbStorageEngine> engine;
#endif
	MojAllocCheck(engine.get());
    MojDb db;

	MojErr err = db.open(MojDbTestDir, engine.get());
	MojTestErrCheck(err);

	// time put kind
	MojTime putKindTime;
	for (int i = 0; i < numRepetitions; i++) {
		err = putKinds(db, putKindTime);
		MojTestErrCheck(err);
		err = delKinds(db);
		MojTestErrCheck(err);
	}

	MojUInt64 putKind = putKindTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   putKind took: %llu microsecs", (putKind / (numKinds * numRepetitions)));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("put Kind,all %llu kinds,%llu,%llu,%llu,\n", numKinds, putKind, putKind/numRepetitions, putKind / (numKinds * numRepetitions));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	// insert objects with one index
	err = testInsertSmallObj(db, MojPerfSmKindId);
	MojTestErrCheck(err);
	err = testInsertMedObj(db, MojPerfMedKindId);
	MojTestErrCheck(err);
	err = testInsertLgObj(db, MojPerfLgKindId);
	MojTestErrCheck(err);
	err = testInsertMedNestedObj(db, MojPerfMedNestedKindId);
	MojTestErrCheck(err);
	err = testInsertLgNestedObj(db, MojPerfLgNestedKindId);
	MojTestErrCheck(err);
	err = testInsertMedArrayObj(db, MojPerfMedArrayKindId);
	MojTestErrCheck(err);
	err = testInsertLgArrayObj(db, MojPerfLgArrayKindId);
	MojTestErrCheck(err);

	// insert objects with two indices
	err = testInsertSmallObj(db, MojPerfSmKind2Id);
	MojTestErrCheck(err);
	err = testInsertMedObj(db, MojPerfMedKind2Id);
	MojTestErrCheck(err);
	err = testInsertLgObj(db, MojPerfLgKind2Id);
	MojTestErrCheck(err);
	err = testInsertMedNestedObj(db, MojPerfMedNestedKind2Id);
	MojTestErrCheck(err);
	err = testInsertLgNestedObj(db, MojPerfLgNestedKind2Id);
	MojTestErrCheck(err);
	err = testInsertMedArrayObj(db, MojPerfMedArrayKind2Id);
	MojTestErrCheck(err);
	err = testInsertLgArrayObj(db, MojPerfLgArrayKind2Id);
	MojTestErrCheck(err);

	// batch insert with one index
	err = testBatchInsertLgObj(db, MojPerfLgKindId);
	MojTestErrCheck(err);
	err = testBatchInsertLgNestedObj(db, MojPerfLgNestedKindId);
	MojTestErrCheck(err);
	err = testBatchInsertLgArrayObj(db, MojPerfLgArrayKindId);
	MojTestErrCheck(err);

	// batch insert with two indices
	err = testBatchInsertLgObj(db, MojPerfLgKind2Id);
	MojTestErrCheck(err);
	err = testBatchInsertLgNestedObj(db, MojPerfLgNestedKind2Id);
	MojTestErrCheck(err);
	err = testBatchInsertLgArrayObj(db, MojPerfLgArrayKind2Id);
	MojTestErrCheck(err);

	err = db.close();
	MojTestErrCheck(err);

	return MojErrNone;
}