Skip to content

Commit

Permalink
added better tracking of concurrent alg serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Dec 10, 2024
1 parent e3c7690 commit 855de30
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
23 changes: 21 additions & 2 deletions dbms/src/main/java/org/polypheny/db/routing/UiRoutingPageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.AlgRoot;
Expand Down Expand Up @@ -52,7 +56,13 @@
@Slf4j
public class UiRoutingPageUtil {

private static final ExecutorService executorService = Executors.newFixedThreadPool( 10 );
private static final int RUNNERS = 10;
private static final ExecutorService executorService = Executors.newFixedThreadPool( RUNNERS );
private static final AtomicInteger counter = new AtomicInteger( 0 );

public static int runningTasks() {
return counter.get();
}


public static void outputSingleResult( Plan plan, InformationManager queryAnalyzer, long stmtIdx, boolean attachTextualPlan ) {
Expand All @@ -69,7 +79,16 @@ public static void outputSingleResult( Plan plan, InformationManager queryAnalyz


public static void addPhysicalPlanPage( AlgNode optimalNode, InformationManager queryAnalyzer, long stmtIdx, boolean attachTextualPlan ) {
executorService.submit( () -> addRoutedPolyPlanPage( optimalNode, queryAnalyzer, stmtIdx, true, attachTextualPlan ) );
executorService.submit( () -> {
UiRoutingPageUtil.counter.incrementAndGet();
try {
addRoutedPolyPlanPage( optimalNode, queryAnalyzer, stmtIdx, true, attachTextualPlan );
}finally {
UiRoutingPageUtil.counter.decrementAndGet();
}


} );
}


Expand Down
29 changes: 16 additions & 13 deletions dbms/src/test/java/org/polypheny/db/polyalg/PolyAlgParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@
import org.polypheny.db.processing.QueryContext;
import org.polypheny.db.processing.QueryContext.TranslatedQueryContext;
import org.polypheny.db.rex.RexBuilder;
import org.polypheny.db.routing.UiRoutingPageUtil;
import org.polypheny.db.transaction.Statement;
import org.polypheny.db.transaction.Transaction;
import org.polypheny.db.transaction.TransactionException;
import org.polypheny.db.transaction.TransactionManager;
import org.polypheny.db.transaction.TransactionManagerImpl;
import org.polypheny.db.type.entity.PolyValue;
import org.polypheny.db.webui.UiTestingConfigPage;


@SuppressWarnings("SqlNoDataSourceInspection")
Expand Down Expand Up @@ -186,23 +188,24 @@ private static void testQueryRoundTrip( String query, QueryLanguage ql, String n

String logical = null, allocation = null, physical = null;

int tries = 3;
int tries = 5;
try {
// plans are serialized in a separate thread, which might take some time
for ( int i = 0; i < tries; i++ ) {
for ( Information info : transaction.getQueryAnalyzer().getInformationArray() ) {
if ( info instanceof InformationPolyAlg polyInfo ) {
switch ( PlanType.valueOf( polyInfo.planType ) ) {
case LOGICAL -> logical = polyInfo.getTextualPolyAlg();
case ALLOCATION -> allocation = polyInfo.getTextualPolyAlg();
case PHYSICAL -> physical = polyInfo.getTextualPolyAlg();
}
while ( UiRoutingPageUtil.runningTasks() > 0 && tries-- > 0 ) {
Thread.sleep( 2000 );
}
if( tries == 0 ) {
throw new RuntimeException( "Took too long to set all plans" );
}

for ( Information info : transaction.getQueryAnalyzer().getInformationArray() ) {
if ( info instanceof InformationPolyAlg polyInfo ) {
switch ( PlanType.valueOf( polyInfo.planType ) ) {
case LOGICAL -> logical = polyInfo.getTextualPolyAlg();
case ALLOCATION -> allocation = polyInfo.getTextualPolyAlg();
case PHYSICAL -> physical = polyInfo.getTextualPolyAlg();
}
}
if ( logical != null && allocation != null && physical != null ) {
break;
}
Thread.sleep( 2000 );
}

assertNotNull( logical );
Expand Down

0 comments on commit 855de30

Please sign in to comment.