Skip to content

Commit

Permalink
added StatusService for status routes used for benchmarking/monitorin…
Browse files Browse the repository at this point in the history
…g/testing
  • Loading branch information
datomo committed Dec 9, 2023
1 parent b1fcade commit 1b7f136
Show file tree
Hide file tree
Showing 21 changed files with 276 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
public class VersionCollector {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ public interface MonitoringService {
*/
void resetQueryPostCosts();

long getSize();

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public interface TransactionManager {

boolean isActive( PolyXid xid );

long getNumberOfActiveTransactions();

}
1 change: 0 additions & 1 deletion dbms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ dependencies {
implementation group: "io.javalin", name: "javalin", version: javalin_version // Apache 2.0

implementation group: "com.github.rvesse", name: "airline", version: airline_version // Apache 2.0
implementation group: "com.github.oshi", name: "oshi-core", version: oshi_core_version // MIT

implementation group: "com.j256.simplemagic", name: "simplemagic", version: simplemagic_version
implementation group: "org.jetbrains", name: "annotations", version: jetbrains_annotations_version // ISC
Expand Down
45 changes: 35 additions & 10 deletions dbms/src/main/java/org/polypheny/db/PolyphenyDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.polypheny.db.StatusService.ErrorConfig;
import org.polypheny.db.StatusService.StatusType;
import org.polypheny.db.StatusNotificationService.ErrorConfig;
import org.polypheny.db.StatusNotificationService.StatusType;
import org.polypheny.db.adapter.index.IndexManager;
import org.polypheny.db.adapter.java.AdapterTemplate;
import org.polypheny.db.catalog.Catalog;
Expand All @@ -47,6 +47,8 @@
import org.polypheny.db.catalog.impl.PolyCatalog;
import org.polypheny.db.catalog.logistic.DataModel;
import org.polypheny.db.cli.PolyModesConverter;
import org.polypheny.db.config.Config;
import org.polypheny.db.config.Config.ConfigListener;
import org.polypheny.db.config.ConfigManager;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.ddl.DdlManager;
Expand All @@ -59,11 +61,12 @@
import org.polypheny.db.gui.TrayGui;
import org.polypheny.db.iface.Authenticator;
import org.polypheny.db.iface.QueryInterfaceManager;
import org.polypheny.db.information.HostInformation;
import org.polypheny.db.information.JavaInformation;
import org.polypheny.db.information.StatusService;
import org.polypheny.db.languages.LanguageManager;
import org.polypheny.db.languages.QueryLanguage;
import org.polypheny.db.monitoring.core.MonitoringServiceProvider;
import org.polypheny.db.monitoring.information.HostInformation;
import org.polypheny.db.monitoring.information.JavaInformation;
import org.polypheny.db.monitoring.statistics.StatisticQueryProcessor;
import org.polypheny.db.monitoring.statistics.StatisticsManagerImpl;
import org.polypheny.db.partition.FrequencyMap;
Expand Down Expand Up @@ -149,8 +152,8 @@ public static void main( final String[] args ) {
final SingleCommand<PolyphenyDb> parser = SingleCommand.singleCommand( PolyphenyDb.class );
final PolyphenyDb polyphenyDb = parser.parse( args );

StatusService.addSubscriber( log::info, StatusType.INFO );
StatusService.addSubscriber( log::error, StatusType.ERROR );
StatusNotificationService.addSubscriber( log::info, StatusType.INFO );
StatusNotificationService.addSubscriber( log::error, StatusType.ERROR );

// Hide dock icon on macOS systems
System.setProperty( "apple.awt.UIElement", "true" );
Expand All @@ -165,12 +168,14 @@ public static void main( final String[] args ) {
}

polyphenyDb.runPolyphenyDb();
} catch ( ParseException e ) {
} catch (
ParseException e ) {
log.error( "Error parsing command line parameters: " + e.getMessage() );
} catch ( Throwable uncaught ) {
} catch (
Throwable uncaught ) {
if ( log.isErrorEnabled() ) {
log.error( "Uncaught Throwable.", uncaught );
StatusService.printError(
StatusNotificationService.printError(
"Error: " + uncaught.getMessage(),
ErrorConfig.builder().func( ErrorConfig.DO_NOTHING ).doExit( true ).showButton( true ).buttonMessage( "Exit" ).build() );
}
Expand Down Expand Up @@ -217,6 +222,8 @@ public void runPolyphenyDb() {
// we have to set the mode before checking
PolyphenyHomeDirManager dirManager = PolyphenyHomeDirManager.setModeAndGetInstance( mode );

initializeStatusNotificationService();

// Check if Polypheny is already running
if ( GuiUtils.checkPolyphenyAlreadyRunning() ) {
if ( openUiInBrowser ) {
Expand Down Expand Up @@ -360,11 +367,13 @@ public void join( final long millis ) throws InterruptedException {
log.error( "Unable to retrieve java runtime information." );
}
try {
new HostInformation();
HostInformation.getINSTANCE();
} catch ( Exception e ) {
log.error( "Unable to retrieve host information." );
}

StatusService.initialize( transactionManager, server.getServer() );

if ( initializeDockerManager() ) {
return;
}
Expand Down Expand Up @@ -490,6 +499,22 @@ private boolean initializeDockerManager() {
}


private static void initializeStatusNotificationService() {
StatusNotificationService.setPort( RuntimeConfig.WEBUI_SERVER_PORT.getInteger() );
RuntimeConfig.WEBUI_SERVER_PORT.addObserver( new ConfigListener() {
@Override
public void onConfigChange( Config c ) {
StatusNotificationService.setPort( c.getInt() );
}


@Override
public void restart( Config c ) {
StatusNotificationService.setPort( c.getInt() );
}
} );
}

private void initializeIndexManager() {
try {
IndexManager.getInstance().initialize( transactionManager );
Expand Down
14 changes: 7 additions & 7 deletions dbms/src/main/java/org/polypheny/db/gui/SplashHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import javax.swing.border.EtchedBorder;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.StatusService;
import org.polypheny.db.StatusService.ErrorConfig;
import org.polypheny.db.StatusService.StatusType;
import org.polypheny.db.StatusNotificationService;
import org.polypheny.db.StatusNotificationService.ErrorConfig;
import org.polypheny.db.StatusNotificationService.StatusType;


/**
Expand All @@ -58,16 +58,16 @@ public SplashHelper() {
screen = new SplashScreen();
Thread splashT = new Thread( screen );
splashT.start();
statusId = StatusService.addSubscriber( ( m, n ) -> screen.setStatus( m ), StatusType.INFO );
errorId = StatusService.addSubscriber( ( m, n ) -> screen.setError( m, (ErrorConfig) n ), StatusType.ERROR );
statusId = StatusNotificationService.addSubscriber( ( m, n ) -> screen.setStatus( m ), StatusType.INFO );
errorId = StatusNotificationService.addSubscriber( ( m, n ) -> screen.setError( m, (ErrorConfig) n ), StatusType.ERROR );
}


public void setComplete() {
GuiUtils.openUiInBrowser();
this.screen.setComplete();
StatusService.removeSubscriber( statusId );
StatusService.removeSubscriber( errorId );
StatusNotificationService.removeSubscriber( statusId );
StatusNotificationService.removeSubscriber( errorId );
}


Expand Down
129 changes: 129 additions & 0 deletions dbms/src/main/java/org/polypheny/db/information/StatusService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2019-2023 The Polypheny Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.polypheny.db.information;

import io.javalin.Javalin;
import io.javalin.http.Context;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.monitoring.core.MonitoringServiceProvider;
import org.polypheny.db.monitoring.information.HostInformation;
import org.polypheny.db.processing.caching.ImplementationCache;
import org.polypheny.db.processing.caching.QueryPlanCache;
import org.polypheny.db.processing.caching.RoutingPlanCache;
import org.polypheny.db.transaction.TransactionManager;
import org.polypheny.db.util.VersionCollector;

public class StatusService {

private static StatusService INSTANCE = null;

public static final String PREFIX_KEY = "/status";
private final TransactionManager transactionManager;


public static StatusService getInstance() {
if ( INSTANCE == null ) {
throw new GenericRuntimeException( "StatusService not initialized yet" );
}
return INSTANCE;
}


public static void initialize( TransactionManager manager, Javalin webuiServer ) {
if ( INSTANCE != null ) {
throw new GenericRuntimeException( "StatusService already initialized" );
}
INSTANCE = new StatusService( manager, webuiServer );
}


private StatusService( TransactionManager manager, Javalin webuiServer ) {
this.transactionManager = manager;

registerStatusRoutes( webuiServer );
}


private void registerStatusRoutes( Javalin webuiServer ) {

webuiServer.get( PREFIX_KEY + "/uuid", this::getUuid );

webuiServer.get( PREFIX_KEY + "/version", this::getVersion );

webuiServer.get( PREFIX_KEY + "/hash", this::getHash );

webuiServer.get( PREFIX_KEY + "/memory-current", this::getCurrentMemory );

webuiServer.get( PREFIX_KEY + "/transactions-active", this::getActiveTransactions );

webuiServer.get( PREFIX_KEY + "/cache-implementation", this::getImplementationCacheSize );

webuiServer.get( PREFIX_KEY + "/cache-queryplan", this::getQueryPlanCacheSize );

webuiServer.get( PREFIX_KEY + "/cache-routingplan", this::getRoutingPlanCacheSize );

webuiServer.get( PREFIX_KEY + "/monitoring-queue", this::getMonitoringQueueSize );

}


private void getMonitoringQueueSize( Context context ) {
context.result( String.valueOf( MonitoringServiceProvider.getInstance().getSize() ) );
}


private void getRoutingPlanCacheSize( Context context ) {
context.result( String.valueOf( RoutingPlanCache.INSTANCE.getSize() ) );
}


private void getQueryPlanCacheSize( Context context ) {
context.result( String.valueOf( QueryPlanCache.INSTANCE.getSize() ) );
}


public void getUuid( Context context ) {
context.result( RuntimeConfig.INSTANCE_UUID.getString() );
}


public void getVersion( Context context ) {
context.result( VersionCollector.INSTANCE.getVersion() );
}


public void getHash( Context context ) {
context.result( VersionCollector.INSTANCE.getHash() );
}


public void getCurrentMemory( Context context ) {
context.result( String.valueOf( HostInformation.getINSTANCE().getUsedFreeProvider().get().left ) );
}


public void getActiveTransactions( Context context ) {
context.result( String.valueOf( transactionManager.getNumberOfActiveTransactions() ) );
}


public void getImplementationCacheSize( Context context ) {
context.result( String.valueOf( ImplementationCache.INSTANCE.getCacheSize() ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,9 @@ private void registerMonitoringPage() {
im.registerInformation( invalidateAction );
}


public long getCacheSize() {
return implementationCache.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,9 @@ private void registerMonitoringPage() {
im.registerInformation( invalidateAction );
}


public long getSize() {
return planCache.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,9 @@ private void resetPostCosts() {
MonitoringServiceProvider.getInstance().resetQueryPostCosts();
}


public long getSize() {
return planCache.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ private static PolyXid generateNewTransactionId( final NodeId nodeId, final User
}


@Override
public long getNumberOfActiveTransactions() {
return transactions.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
* to the attached subscribers.
*/
@Slf4j
public class StatusService {
public class StatusNotificationService {

private static final String POLY_URL = "http://localhost:8080";
private static int POLY_PORT = 7659;

private static final String POLY_URL = "http://localhost:" + POLY_PORT + "/";

private static final AtomicInteger idBuilder = new AtomicInteger();

Expand All @@ -47,7 +49,7 @@ public class StatusService {


public static synchronized int addInfoSubscriber( BiConsumer<String, Object> printer ) {
return StatusService.addSubscriber( printer, StatusType.INFO );
return StatusNotificationService.addSubscriber( printer, StatusType.INFO );
}


Expand Down Expand Up @@ -89,6 +91,11 @@ public static void removeSubscriber( int id ) {
}


public static void setPort( int port ) {
POLY_PORT = port;
}


public enum StatusType {
INFO,
ERROR
Expand Down
Loading

0 comments on commit 1b7f136

Please sign in to comment.