use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.
the class OSessionStoragePerformanceStatisticTest method testReadFromFile.
public void testReadFromFile() {
final OModifiableInteger increment = new OModifiableInteger();
OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = new OSessionStoragePerformanceStatistic(100, new OSessionStoragePerformanceStatistic.NanoTimer() {
private long counter = 0;
@Override
public long getNano() {
return counter += increment.getValue();
}
}, -1);
Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesReadFromFile(), 0);
Assert.assertEquals(sessionStoragePerformanceStatistic.getReadSpeedFromFileInPages(), -1);
sessionStoragePerformanceStatistic.startCommitTimer();
for (int i = 0; i < 50; i++) {
increment.setValue(50);
sessionStoragePerformanceStatistic.startComponentOperation("c1po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
sessionStoragePerformanceStatistic.startComponentOperation("c1po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
sessionStoragePerformanceStatistic.startPageReadFromFileTimer();
sessionStoragePerformanceStatistic.stopPageReadFromFileTimer(10);
increment.setValue(150);
sessionStoragePerformanceStatistic.startComponentOperation("c2po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
sessionStoragePerformanceStatistic.startPageReadFromFileTimer();
sessionStoragePerformanceStatistic.stopPageReadFromFileTimer(10);
sessionStoragePerformanceStatistic.completeComponentOperation();
sessionStoragePerformanceStatistic.completeComponentOperation();
sessionStoragePerformanceStatistic.completeComponentOperation();
}
increment.setValue(100);
for (int i = 0; i < 50; i++) {
sessionStoragePerformanceStatistic.startPageReadFromFileTimer();
sessionStoragePerformanceStatistic.stopPageReadFromFileTimer(10);
}
sessionStoragePerformanceStatistic.stopCommitTimer();
Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesReadFromFile(), 1500);
Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesReadFromFile(null), 1500);
Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesReadFromFile("c1po"), 1000);
Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesReadFromFile("c2po"), 500);
Assert.assertEquals(sessionStoragePerformanceStatistic.getAmountOfPagesReadFromFile("c3po"), -1);
Assert.assertEquals(sessionStoragePerformanceStatistic.getReadSpeedFromFileInPages(), 100000000);
Assert.assertEquals(sessionStoragePerformanceStatistic.getReadSpeedFromFileInPages(null), 100000000);
Assert.assertEquals(sessionStoragePerformanceStatistic.getReadSpeedFromFileInPages("c1po"), 100000000);
Assert.assertEquals(sessionStoragePerformanceStatistic.getReadSpeedFromFileInPages("c2po"), 66666666);
Assert.assertEquals(sessionStoragePerformanceStatistic.getReadSpeedFromFileInPages("c3po"), -1);
final ODocument doc = sessionStoragePerformanceStatistic.toDocument();
Assert.assertEquals(doc.field("amountOfPagesReadFromFile"), 1500L);
Assert.assertEquals(doc.field("readSpeedFromFileInPages"), 100000000L);
final ODocument docC1PO = doc.<Map<String, ODocument>>field("dataByComponent").get("c1po");
Assert.assertEquals(docC1PO.field("amountOfPagesReadFromFile"), 1000L);
Assert.assertEquals(docC1PO.field("readSpeedFromFileInPages"), 100000000L);
final ODocument docC2PO = doc.<Map<String, ODocument>>field("dataByComponent").get("c2po");
Assert.assertEquals(docC2PO.field("amountOfPagesReadFromFile"), 500L);
Assert.assertEquals(docC2PO.field("readSpeedFromFileInPages"), 66666666L);
}
use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.
the class OSessionStoragePerformanceStatisticTest method testSystemCounters.
public void testSystemCounters() {
final OModifiableInteger counterOne = new OModifiableInteger();
OSessionStoragePerformanceStatistic sessionStoragePerformanceStatisticOne = new OSessionStoragePerformanceStatistic(100, new OSessionStoragePerformanceStatistic.NanoTimer() {
@Override
public long getNano() {
counterOne.increment(100);
return counterOne.getValue();
}
}, -1);
final OSessionStoragePerformanceStatistic.PerformanceCountersHolder counters = new OSessionStoragePerformanceStatistic.PerformanceCountersHolder();
sessionStoragePerformanceStatisticOne.pushSystemCounters(counters);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(false);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(false);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(false);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(true);
sessionStoragePerformanceStatisticOne.startPageReadFromCacheTimer();
counterOne.increment(50);
sessionStoragePerformanceStatisticOne.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.startPageReadFromCacheTimer();
counterOne.increment(50);
sessionStoragePerformanceStatisticOne.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.startPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.startPageReadFromFileTimer();
sessionStoragePerformanceStatisticOne.stopPageReadFromFileTimer(2);
sessionStoragePerformanceStatisticOne.startPageWriteInCacheTimer();
counterOne.increment(200);
sessionStoragePerformanceStatisticOne.stopPageWriteInCacheTimer();
sessionStoragePerformanceStatisticOne.startCommitTimer();
counterOne.increment(100);
sessionStoragePerformanceStatisticOne.stopCommitTimer();
OSessionStoragePerformanceStatistic sessionStoragePerformanceStatisticTwo = new OSessionStoragePerformanceStatistic(100, new OSessionStoragePerformanceStatistic.NanoTimer() {
private long counter = 0;
@Override
public long getNano() {
return counter += 100;
}
}, -1);
sessionStoragePerformanceStatisticTwo.incrementPageAccessOnCacheLevel(true);
sessionStoragePerformanceStatisticTwo.startPageReadFromCacheTimer();
sessionStoragePerformanceStatisticTwo.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticTwo.startPageReadFromFileTimer();
sessionStoragePerformanceStatisticTwo.stopPageReadFromFileTimer(1);
sessionStoragePerformanceStatisticTwo.startPageWriteInCacheTimer();
sessionStoragePerformanceStatisticTwo.stopPageWriteInCacheTimer();
sessionStoragePerformanceStatisticTwo.startCommitTimer();
sessionStoragePerformanceStatisticTwo.stopCommitTimer();
sessionStoragePerformanceStatisticTwo.completeComponentOperation();
sessionStoragePerformanceStatisticOne.pushSystemCounters(counters);
sessionStoragePerformanceStatisticTwo.pushSystemCounters(counters);
Assert.assertEquals(counters.getCacheHits(), 40);
Assert.assertEquals(counters.getAmountOfPagesReadFromCache(), 4);
Assert.assertEquals(counters.getAmountOfPagesReadFromFile(), 3);
Assert.assertEquals(counters.getAmountOfPagesWrittenInCache(), 2);
Assert.assertEquals(counters.getReadSpeedFromCacheInPages(), 8000000);
Assert.assertEquals(counters.getReadSpeedFromFileInPages(), 15000000);
Assert.assertEquals(counters.getWriteSpeedInCacheInPages(), 5000000);
Assert.assertEquals(counters.getCommitTime(), 150);
}
use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.
the class OSessionStoragePerformanceStatisticTest method testPushComponentCounters.
public void testPushComponentCounters() {
final OModifiableInteger counterOne = new OModifiableInteger();
OSessionStoragePerformanceStatistic sessionStoragePerformanceStatisticOne = new OSessionStoragePerformanceStatistic(100, new OSessionStoragePerformanceStatistic.NanoTimer() {
@Override
public long getNano() {
counterOne.increment(100);
return counterOne.getValue();
}
}, -1);
OSessionStoragePerformanceStatistic.PerformanceCountersHolder performanceCountersHolder = new OSessionStoragePerformanceStatistic.PerformanceCountersHolder();
final Map<String, OSessionStoragePerformanceStatistic.PerformanceCountersHolder> counters = new HashMap<String, OSessionStoragePerformanceStatistic.PerformanceCountersHolder>();
sessionStoragePerformanceStatisticOne.pushComponentCounters(counters);
sessionStoragePerformanceStatisticOne.pushComponentCounters("c3po", performanceCountersHolder);
sessionStoragePerformanceStatisticOne.startComponentOperation("c3po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(false);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(false);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(false);
sessionStoragePerformanceStatisticOne.incrementPageAccessOnCacheLevel(true);
sessionStoragePerformanceStatisticOne.startPageReadFromCacheTimer();
counterOne.increment(50);
sessionStoragePerformanceStatisticOne.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.startPageReadFromCacheTimer();
counterOne.increment(50);
sessionStoragePerformanceStatisticOne.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.startPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticOne.startPageReadFromFileTimer();
sessionStoragePerformanceStatisticOne.stopPageReadFromFileTimer(2);
sessionStoragePerformanceStatisticOne.startPageWriteInCacheTimer();
counterOne.increment(200);
sessionStoragePerformanceStatisticOne.stopPageWriteInCacheTimer();
sessionStoragePerformanceStatisticOne.completeComponentOperation();
OSessionStoragePerformanceStatistic sessionStoragePerformanceStatisticTwo = new OSessionStoragePerformanceStatistic(100, new OSessionStoragePerformanceStatistic.NanoTimer() {
private long counter = 0;
@Override
public long getNano() {
return counter += 100;
}
}, -1);
sessionStoragePerformanceStatisticTwo.startComponentOperation("c3po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
sessionStoragePerformanceStatisticTwo.incrementPageAccessOnCacheLevel(true);
sessionStoragePerformanceStatisticTwo.completeComponentOperation();
sessionStoragePerformanceStatisticTwo.startComponentOperation("c1po", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
sessionStoragePerformanceStatisticTwo.startPageReadFromCacheTimer();
sessionStoragePerformanceStatisticTwo.stopPageReadFromCacheTimer();
sessionStoragePerformanceStatisticTwo.startPageReadFromFileTimer();
sessionStoragePerformanceStatisticTwo.stopPageReadFromFileTimer(1);
sessionStoragePerformanceStatisticTwo.startPageWriteInCacheTimer();
sessionStoragePerformanceStatisticTwo.stopPageWriteInCacheTimer();
sessionStoragePerformanceStatisticTwo.completeComponentOperation();
sessionStoragePerformanceStatisticOne.pushComponentCounters("c3po", performanceCountersHolder);
Assert.assertEquals(performanceCountersHolder.getCacheHits(), sessionStoragePerformanceStatisticOne.getCacheHits());
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesPerOperation(), sessionStoragePerformanceStatisticOne.getAmountOfPagesPerOperation("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromCache(), sessionStoragePerformanceStatisticOne.getAmountOfPagesReadFromCache("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromFile(), sessionStoragePerformanceStatisticOne.getAmountOfPagesReadFromFile("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesWrittenInCache(), sessionStoragePerformanceStatisticOne.getAmountOfPagesWrittenInCache("c3po"));
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromCacheInPages(), sessionStoragePerformanceStatisticOne.getReadSpeedFromCacheInPages("c3po"));
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromFileInPages(), sessionStoragePerformanceStatisticOne.getReadSpeedFromFileInPages("c3po"));
Assert.assertEquals(performanceCountersHolder.getWriteSpeedInCacheInPages(), sessionStoragePerformanceStatisticOne.getWriteSpeedInCacheInPages("c3po"));
performanceCountersHolder = new OSessionStoragePerformanceStatistic.PerformanceCountersHolder();
sessionStoragePerformanceStatisticTwo.pushComponentCounters("c3po", performanceCountersHolder);
Assert.assertEquals(performanceCountersHolder.getCacheHits(), sessionStoragePerformanceStatisticTwo.getCacheHits());
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesPerOperation(), sessionStoragePerformanceStatisticTwo.getAmountOfPagesPerOperation("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromCache(), sessionStoragePerformanceStatisticTwo.getAmountOfPagesReadFromCache("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromFile(), sessionStoragePerformanceStatisticTwo.getAmountOfPagesReadFromFile("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesWrittenInCache(), sessionStoragePerformanceStatisticTwo.getAmountOfPagesWrittenInCache("c3po"));
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromCacheInPages(), sessionStoragePerformanceStatisticTwo.getReadSpeedFromCacheInPages("c3po"));
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromFileInPages(), sessionStoragePerformanceStatisticTwo.getReadSpeedFromFileInPages("c3po"));
Assert.assertEquals(performanceCountersHolder.getWriteSpeedInCacheInPages(), sessionStoragePerformanceStatisticTwo.getWriteSpeedInCacheInPages("c3po"));
sessionStoragePerformanceStatisticOne.pushComponentCounters("c3po", performanceCountersHolder);
Assert.assertEquals(performanceCountersHolder.getCacheHits(), 40);
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesPerOperation(), 1);
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromCache(), sessionStoragePerformanceStatisticOne.getAmountOfPagesReadFromCache("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromFile(), sessionStoragePerformanceStatisticOne.getAmountOfPagesReadFromFile("c3po"));
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesWrittenInCache(), sessionStoragePerformanceStatisticOne.getAmountOfPagesWrittenInCache("c3po"));
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromCacheInPages(), sessionStoragePerformanceStatisticOne.getReadSpeedFromCacheInPages("c3po"));
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromFileInPages(), sessionStoragePerformanceStatisticOne.getReadSpeedFromFileInPages("c3po"));
Assert.assertEquals(performanceCountersHolder.getWriteSpeedInCacheInPages(), sessionStoragePerformanceStatisticOne.getWriteSpeedInCacheInPages("c3po"));
performanceCountersHolder = new OSessionStoragePerformanceStatistic.PerformanceCountersHolder();
sessionStoragePerformanceStatisticOne.pushComponentCounters("c3po", performanceCountersHolder);
sessionStoragePerformanceStatisticTwo.pushComponentCounters("c1po", performanceCountersHolder);
Assert.assertEquals(performanceCountersHolder.getCacheHits(), sessionStoragePerformanceStatisticOne.getCacheHits());
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesPerOperation(), 2);
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromCache(), 4);
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesReadFromFile(), 3);
Assert.assertEquals(performanceCountersHolder.getAmountOfPagesWrittenInCache(), 2);
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromCacheInPages(), 8000000);
Assert.assertEquals(performanceCountersHolder.getReadSpeedFromFileInPages(), 15000000);
Assert.assertEquals(performanceCountersHolder.getWriteSpeedInCacheInPages(), 5000000);
sessionStoragePerformanceStatisticOne.pushComponentCounters(counters);
sessionStoragePerformanceStatisticTwo.pushComponentCounters(counters);
Assert.assertEquals(counters.get("c3po").getCacheHits(), 40);
Assert.assertEquals(counters.get("c3po").getAmountOfPagesPerOperation(), 1);
Assert.assertEquals(counters.get("c3po").getAmountOfPagesReadFromCache(), 3);
Assert.assertEquals(counters.get("c3po").getAmountOfPagesReadFromFile(), 2);
Assert.assertEquals(counters.get("c3po").getReadSpeedFromCacheInPages(), 7500000);
Assert.assertEquals(counters.get("c3po").getReadSpeedFromFileInPages(), 20000000);
Assert.assertEquals(counters.get("c3po").getWriteSpeedInCacheInPages(), 3333333);
Assert.assertEquals(counters.get("c1po").getCacheHits(), -1);
Assert.assertEquals(counters.get("c1po").getAmountOfPagesPerOperation(), 1);
Assert.assertEquals(counters.get("c1po").getAmountOfPagesReadFromCache(), 1);
Assert.assertEquals(counters.get("c1po").getAmountOfPagesReadFromFile(), 1);
Assert.assertEquals(counters.get("c1po").getReadSpeedFromCacheInPages(), 10000000);
Assert.assertEquals(counters.get("c1po").getReadSpeedFromFileInPages(), 10000000);
Assert.assertEquals(counters.get("c1po").getWriteSpeedInCacheInPages(), 10000000);
}
use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.
the class OReadersWriterSpinLock method acquireReadLock.
public void acquireReadLock() {
final OModifiableInteger lHolds = lockHolds.get();
final int holds = lHolds.intValue();
if (holds > 0) {
// we have already acquire read lock
lHolds.increment();
return;
} else if (holds < 0) {
// write lock is acquired before, do nothing
return;
}
distributedCounter.increment();
WNode wNode = tail.get();
while (wNode.locked) {
distributedCounter.decrement();
while (wNode.locked && wNode == tail.get()) {
wNode.waitingReaders.add(Thread.currentThread());
if (wNode.locked && wNode == tail.get())
LockSupport.park(this);
wNode = tail.get();
}
distributedCounter.increment();
wNode = tail.get();
}
lHolds.increment();
assert lHolds.intValue() == 1;
}
use of com.orientechnologies.common.types.OModifiableInteger in project orientdb by orientechnologies.
the class OSBTreeRidBag method serialize.
@Override
public int serialize(byte[] stream, int offset, UUID ownerUuid) {
for (Map.Entry<OIdentifiable, OModifiableInteger> entry : newEntries.entrySet()) {
OIdentifiable identifiable = entry.getKey();
assert identifiable instanceof ORecord;
Change c = changes.get(identifiable);
final int delta = entry.getValue().intValue();
if (c == null)
changes.put(identifiable, new DiffChange(delta));
else
c.applyDiff(delta);
}
newEntries.clear();
final ORecordSerializationContext context;
boolean remoteMode = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage() instanceof OStorageProxy;
if (remoteMode) {
context = null;
} else
context = ORecordSerializationContext.getContext();
// make sure that we really save underlying record.
if (collectionPointer == null) {
if (context != null) {
final int clusterId = getHighLevelDocClusterId();
assert clusterId > -1;
collectionPointer = ODatabaseRecordThreadLocal.INSTANCE.get().getSbTreeCollectionManager().createSBTree(clusterId, ownerUuid);
}
}
OBonsaiCollectionPointer collectionPointer;
if (this.collectionPointer != null)
collectionPointer = this.collectionPointer;
else {
collectionPointer = OBonsaiCollectionPointer.INVALID;
}
OLongSerializer.INSTANCE.serializeLiteral(collectionPointer.getFileId(), stream, offset);
offset += OLongSerializer.LONG_SIZE;
OBonsaiBucketPointer rootPointer = collectionPointer.getRootPointer();
OLongSerializer.INSTANCE.serializeLiteral(rootPointer.getPageIndex(), stream, offset);
offset += OLongSerializer.LONG_SIZE;
OIntegerSerializer.INSTANCE.serializeLiteral(rootPointer.getPageOffset(), stream, offset);
offset += OIntegerSerializer.INT_SIZE;
// Keep this section for binary compatibility with versions older then 1.7.5
OIntegerSerializer.INSTANCE.serializeLiteral(size, stream, offset);
offset += OIntegerSerializer.INT_SIZE;
if (context == null) {
ChangeSerializationHelper.INSTANCE.serializeChanges(changes, OLinkSerializer.INSTANCE, stream, offset);
} else {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
for (Entry<OIdentifiable, Change> change : this.changes.entrySet()) {
OIdentifiable key = change.getKey();
if (db != null && db.getTransaction().isActive()) {
if (!key.getIdentity().isPersistent()) {
OIdentifiable newKey = db.getTransaction().getRecord(key.getIdentity());
if (newKey != null) {
changes.remove(key);
changes.put(newKey, change.getValue());
}
}
}
}
this.collectionPointer = collectionPointer;
context.push(new ORidBagUpdateSerializationOperation(changes, collectionPointer));
// 0-length serialized list of changes
OIntegerSerializer.INSTANCE.serializeLiteral(0, stream, offset);
offset += OIntegerSerializer.INT_SIZE;
}
return offset;
}
Aggregations