Search in sources :

Example 6 with OProfiler

use of com.orientechnologies.common.profiler.OProfiler in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelect method revertProfiler.

protected void revertProfiler(final OCommandContext iContext, final OIndex<?> index, final List<Object> keyParams, final OIndexDefinition indexDefinition) {
    if (iContext.isRecordingMetrics()) {
        iContext.updateMetric("compositeIndexUsed", -1);
    }
    final OProfiler profiler = Orient.instance().getProfiler();
    if (profiler.isRecording()) {
        profiler.updateCounter(profiler.getDatabaseMetric(index.getDatabaseName(), "query.indexUsed"), "Used index in query", -1);
        int params = indexDefinition.getParamCount();
        if (params > 1) {
            final String profiler_prefix = profiler.getDatabaseMetric(index.getDatabaseName(), "query.compositeIndexUsed");
            profiler.updateCounter(profiler_prefix, "Used composite index in query", -1);
            profiler.updateCounter(profiler_prefix + "." + params, "Used composite index in query with " + params + " params", -1);
            profiler.updateCounter(profiler_prefix + "." + params + '.' + keyParams.size(), "Used composite index in query with " + params + " params and " + keyParams.size() + " keys", -1);
        }
    }
}
Also used : OProfiler(com.orientechnologies.common.profiler.OProfiler)

Example 7 with OProfiler

use of com.orientechnologies.common.profiler.OProfiler in project orientdb by orientechnologies.

the class PolymorphicQueryTest method testSubclassesIndexesFailed.

@Test
public void testSubclassesIndexesFailed() throws Exception {
    database.begin();
    OProfiler profiler = Orient.instance().getProfiler();
    profiler.startRecording();
    for (int i = 0; i < 10000; i++) {
        final ODocument doc1 = new ODocument("IndexInSubclassesTestChild1Fail");
        doc1.field("name", "name" + i);
        doc1.save();
        final ODocument doc2 = new ODocument("IndexInSubclassesTestChild2Fail");
        doc2.field("name", "name" + i);
        doc2.save();
        if (i % 100 == 0) {
            database.commit();
        }
    }
    database.commit();
    long indexUsage = profiler.getCounter("db.demo.query.indexUsed");
    long indexUsageReverted = profiler.getCounter("db.demo.query.indexUseAttemptedAndReverted");
    if (indexUsage < 0) {
        indexUsage = 0;
    }
    if (indexUsageReverted < 0) {
        indexUsageReverted = 0;
    }
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from IndexInSubclassesTestBaseFail where name > 'name9995' and name < 'name9999' order by name ASC"));
    Assert.assertTrue(result.size() == 6);
    long lastIndexUsage = profiler.getCounter("db.demo.query.indexUsed");
    long lastIndexUsageReverted = profiler.getCounter("db.demo.query.indexUseAttemptedAndReverted");
    if (lastIndexUsage < 0) {
        lastIndexUsage = 0;
    }
    if (lastIndexUsageReverted < 0) {
        lastIndexUsageReverted = 0;
    }
    Assert.assertEquals(lastIndexUsage - indexUsage, lastIndexUsageReverted - indexUsageReverted);
    profiler.stopRecording();
}
Also used : OProfiler(com.orientechnologies.common.profiler.OProfiler) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 8 with OProfiler

use of com.orientechnologies.common.profiler.OProfiler in project orientdb by orientechnologies.

the class PolymorphicQueryTest method testBaseWithoutIndexAndSubclassesIndexes.

@Test
public void testBaseWithoutIndexAndSubclassesIndexes() throws Exception {
    database.begin();
    OProfiler profiler = Orient.instance().getProfiler();
    long indexUsage = profiler.getCounter("db.demo.query.indexUsed");
    long indexUsageReverted = profiler.getCounter("db.demo.query.indexUseAttemptedAndReverted");
    if (indexUsage < 0) {
        indexUsage = 0;
    }
    if (indexUsageReverted < 0) {
        indexUsageReverted = 0;
    }
    profiler.startRecording();
    for (int i = 0; i < 10000; i++) {
        final ODocument doc0 = new ODocument("IndexInSubclassesTestBase");
        doc0.field("name", "name" + i);
        doc0.save();
        final ODocument doc1 = new ODocument("IndexInSubclassesTestChild1");
        doc1.field("name", "name" + i);
        doc1.save();
        final ODocument doc2 = new ODocument("IndexInSubclassesTestChild2");
        doc2.field("name", "name" + i);
        doc2.save();
        if (i % 100 == 0) {
            database.commit();
        }
    }
    database.commit();
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from IndexInSubclassesTestBase where name > 'name9995' and name < 'name9999' order by name ASC"));
    Assert.assertTrue(result.size() == 9);
    String lastName = result.get(0).field("name");
    for (int i = 1; i < result.size(); i++) {
        ODocument current = result.get(i);
        String currentName = current.field("name");
        Assert.assertTrue(lastName.compareTo(currentName) <= 0);
        lastName = currentName;
    }
    Assert.assertEquals(profiler.getCounter("db.demo.query.indexUsed"), indexUsage + 2);
    long reverted = profiler.getCounter("db.demo.query.indexUseAttemptedAndReverted");
    Assert.assertEquals(reverted < 0 ? 0 : reverted, indexUsageReverted);
    result = database.query(new OSQLSynchQuery<ODocument>("select from IndexInSubclassesTestBase where name > 'name9995' and name < 'name9999' order by name DESC"));
    Assert.assertTrue(result.size() == 9);
    lastName = result.get(0).field("name");
    for (int i = 1; i < result.size(); i++) {
        ODocument current = result.get(i);
        String currentName = current.field("name");
        Assert.assertTrue(lastName.compareTo(currentName) >= 0);
        lastName = currentName;
    }
    profiler.stopRecording();
}
Also used : OProfiler(com.orientechnologies.common.profiler.OProfiler) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OProfiler (com.orientechnologies.common.profiler.OProfiler)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 OException (com.orientechnologies.common.exception.OException)1 OSizeable (com.orientechnologies.common.util.OSizeable)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)1 ORID (com.orientechnologies.orient.core.id.ORID)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OSQLFunctionRuntime (com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime)1 OSQLFunctionCount (com.orientechnologies.orient.core.sql.functions.misc.OSQLFunctionCount)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1