Skip to content

Commit

Permalink
Merge pull request #4910 from evolvedbinary/refactor/cleanup-performa…
Browse files Browse the repository at this point in the history
…nce-stats

Fix concurrency issues in Performance Stats code
  • Loading branch information
dizzzz authored Oct 11, 2024
2 parents 11dc839 + c8242fc commit 5865e79
Show file tree
Hide file tree
Showing 22 changed files with 910 additions and 554 deletions.
4 changes: 3 additions & 1 deletion exist-core/src/main/java/org/exist/storage/BrokerPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.exist.xmldb.ShutdownListener;
import org.exist.xmldb.XmldbURI;
import org.exist.xquery.PerformanceStats;
import org.exist.xquery.PerformanceStatsService;
import org.exist.xquery.XQuery;

import java.io.IOException;
Expand Down Expand Up @@ -184,6 +185,7 @@ private enum Event {
.build()
);


public String getStatus() {
return status.getCurrentState().name();
}
Expand Down Expand Up @@ -473,7 +475,7 @@ private void _initialize() throws EXistException, DatabaseConfigurationException
this.cacheManager = servicesManager.register(new DefaultCacheManager(this));
this.xQueryPool = servicesManager.register(new XQueryPool());
this.processMonitor = servicesManager.register(new ProcessMonitor());
this.xqueryStats = servicesManager.register(new PerformanceStats(this));
this.xqueryStats = servicesManager.register(new PerformanceStatsService());
final XMLReaderObjectFactory xmlReaderObjectFactory = servicesManager.register(new XMLReaderObjectFactory());
this.xmlReaderPool = servicesManager.register(new XMLReaderPool(xmlReaderObjectFactory, maxBrokers, 0));
final int bufferSize = Optional.of(conf.getInteger(PROPERTY_COLLECTION_CACHE_SIZE))
Expand Down
29 changes: 14 additions & 15 deletions exist-core/src/main/java/org/exist/xquery/GeneralComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ public void visitCastExpr( CastExpression expression )
axis = firstStep.getAxis();

if( ( axis == Constants.SELF_AXIS ) && ( steps.size() > 1 ) ) {
if (steps.get(1) != null) {
axis = steps.get( 1 ).getAxis();
} else {
contextQName = null;
contextStep = null;
axis = Constants.UNKNOWN_AXIS;
optimizeChild = false;
}
if (steps.get(1) != null) {
axis = steps.get( 1 ).getAxis();
} else {
contextQName = null;
contextStep = null;
axis = Constants.UNKNOWN_AXIS;
optimizeChild = false;
}
}
optimizeChild = ( steps.size() == 1 ) && ( ( axis == Constants.CHILD_AXIS ) || ( axis == Constants.ATTRIBUTE_AXIS ) );
}
Expand Down Expand Up @@ -327,8 +327,7 @@ public NodeSet preSelect( Sequence contextSequence, boolean useContext ) throws

// if the right hand sequence has more than one item, we need to merge them
// into preselectResult
if (rightSeq.getItemCount() > 1)
{preselectResult = new NewArrayNodeSet();}
if (rightSeq.getItemCount() > 1) {preselectResult = new NewArrayNodeSet();}

// Iterate through each item in the right-hand sequence
for( final SequenceIterator itRightSeq = Atomize.atomize(rightSeq).iterate(); itRightSeq.hasNext(); ) {
Expand Down Expand Up @@ -399,13 +398,13 @@ else if( key.getType() != indexType ) {
if( preselectResult == null ) {
preselectResult = temp;
} else {
preselectResult.addAll(temp);
preselectResult.addAll(temp);
}
}
}

if( context.getProfiler().traceFunctions() ) {
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.OPTIMIZED_INDEX, System.currentTimeMillis() - start );
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.IndexOptimizationLevel.OPTIMIZED, System.currentTimeMillis() - start );
}

return( ( preselectResult == null ) ? NodeSet.EMPTY_SET : preselectResult );
Expand Down Expand Up @@ -583,7 +582,7 @@ protected Sequence genericCompare( Sequence ls, Sequence contextSequence, Item c
}

if( context.getProfiler().traceFunctions() ) {
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.NO_INDEX, System.currentTimeMillis() - start );
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.IndexOptimizationLevel.NONE, System.currentTimeMillis() - start );
}
return( result );
}
Expand Down Expand Up @@ -652,7 +651,7 @@ protected Sequence nodeSetCompare( NodeSet nodes, Sequence contextSequence ) thr
}

if( context.getProfiler().traceFunctions() ) {
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.NO_INDEX, System.currentTimeMillis() - start );
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.IndexOptimizationLevel.NONE, System.currentTimeMillis() - start );
}
return( result );
}
Expand Down Expand Up @@ -905,7 +904,7 @@ else if( key.getType() != indexType ) {
}

if( context.getProfiler().traceFunctions() ) {
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.BASIC_INDEX, System.currentTimeMillis() - start );
context.getProfiler().traceIndexUsage( context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.IndexOptimizationLevel.BASIC, System.currentTimeMillis() - start );
}
return( result );
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ private abstract class AbstractFilterBase implements StreamFilter {
this.contextId = contextId;
this.limit = limit;
if (limit > -1 && context.getProfiler().traceFunctions()) {
context.getProfiler().traceOptimization(context, PerformanceStats.OptimizationType.PositionalPredicate,
context.getProfiler().traceOptimization(context, PerformanceStats.OptimizationType.POSITIONAL_PREDICATE,
LocationStep.this);
}
}
Expand Down
Loading

0 comments on commit 5865e79

Please sign in to comment.