Skip to content

Commit

Permalink
Add specific option for jit compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Oct 5, 2018
1 parent 50f6697 commit 090ae57
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
Expand Up @@ -34,7 +34,7 @@ import scala.collection.{Map, mutable}


class QueryCachingTest extends CypherFunSuite with GraphDatabaseTestSupport with TableDrivenPropertyChecks { class QueryCachingTest extends CypherFunSuite with GraphDatabaseTestSupport with TableDrivenPropertyChecks {


override def databaseConfig(): Map[Setting[_], String] = Map(GraphDatabaseSettings.cypher_expression_engine -> "DEFAULT", override def databaseConfig(): Map[Setting[_], String] = Map(GraphDatabaseSettings.cypher_expression_engine -> "ONLY_WHEN_HOT",
GraphDatabaseSettings.cypher_expression_recompilation_limit -> "1") GraphDatabaseSettings.cypher_expression_recompilation_limit -> "1")


test("re-uses cached plan across different execution modes") { test("re-uses cached plan across different execution modes") {
Expand Down
Expand Up @@ -25,5 +25,6 @@ case object CypherExpressionEngineOption extends CypherOptionCompanion[CypherExp
case object default extends CypherExpressionEngineOption("default") case object default extends CypherExpressionEngineOption("default")
case object interpreted extends CypherExpressionEngineOption("interpreted") case object interpreted extends CypherExpressionEngineOption("interpreted")
case object compiled extends CypherExpressionEngineOption("compiled") case object compiled extends CypherExpressionEngineOption("compiled")
val all: Set[CypherExpressionEngineOption] = Set(interpreted, compiled) case object onlyWhenHot extends CypherExpressionEngineOption("only_when_hot")
val all: Set[CypherExpressionEngineOption] = Set(interpreted, compiled, onlyWhenHot)
} }
Expand Up @@ -124,8 +124,8 @@ class ExecutionEngine(val queryService: GraphDatabaseQueryService,
tracer: QueryCompilationEvent, tracer: QueryCompilationEvent,
transactionalContext: TransactionalContext, transactionalContext: TransactionalContext,
params: MapValue): (() => ExecutableQuery, (Int) => Option[ExecutableQuery]) = preParsedQuery.expressionEngine match { params: MapValue): (() => ExecutableQuery, (Int) => Option[ExecutableQuery]) = preParsedQuery.expressionEngine match {
//the default is to start with interpreted and change to compiled when hot enough //check if we need to jit compiling of queries
case CypherExpressionEngineOption.default if config.recompilationLimit > 0 => case CypherExpressionEngineOption.onlyWhenHot if config.recompilationLimit > 0 =>
val primary: () => ExecutableQuery = () => masterCompiler.compile(preParsedQuery, val primary: () => ExecutableQuery = () => masterCompiler.compile(preParsedQuery,
tracer, transactionalContext, params) tracer, transactionalContext, params)
val secondary: (Int) => Option[ExecutableQuery] = val secondary: (Int) => Option[ExecutableQuery] =
Expand All @@ -137,11 +137,11 @@ class ExecutionEngine(val queryService: GraphDatabaseQueryService,


(primary, secondary) (primary, secondary)
//We have recompilationLimit == 0, go to compiled directly //We have recompilationLimit == 0, go to compiled directly
case CypherExpressionEngineOption.default => case CypherExpressionEngineOption.onlyWhenHot =>
(() => masterCompiler.compile(preParsedQuery.copy(expressionEngine = CypherExpressionEngineOption.compiled), (() => masterCompiler.compile(preParsedQuery.copy(recompilationLimitReached = true),
tracer, transactionalContext, params), (_) => None) tracer, transactionalContext, params), (_) => None)
//In the other cases we have no recompilation step //In the other cases we have no recompilation step
case _ => (() => masterCompiler.compile(preParsedQuery,tracer, transactionalContext, params), (_) => None) case _ => (() => masterCompiler.compile(preParsedQuery, tracer, transactionalContext, params), (_) => None)
} }


private def getOrCompile(context: TransactionalContext, private def getOrCompile(context: TransactionalContext,
Expand Down
Expand Up @@ -53,14 +53,15 @@ case class PreParsedQuery(statement: String,
} }


val expressionEngineInfo = expressionEngine match { val expressionEngineInfo = expressionEngine match {
case CypherExpressionEngineOption.compiled => s"expressionEngine=${expressionEngine.name}" case CypherExpressionEngineOption.default | CypherExpressionEngineOption.onlyWhenHot => ""
case _ => "" case _ => s"expressionEngine=${expressionEngine.name}"
} }


val debugFlags = debugOptions.map(flag => s"debug=$flag").mkString(" ") val debugFlags = debugOptions.map(flag => s"debug=$flag").mkString(" ")


s"CYPHER ${version.name} $plannerInfo $runtimeInfo $updateStrategyInfo $expressionEngineInfo $debugFlags $statement" s"CYPHER ${version.name} $plannerInfo $runtimeInfo $updateStrategyInfo $expressionEngineInfo $debugFlags $statement"
} }


def useCompiledExpressions: Boolean = expressionEngine == CypherExpressionEngineOption.compiled || recompilationLimitReached def useCompiledExpressions: Boolean = expressionEngine == CypherExpressionEngineOption.compiled ||
(expressionEngine == CypherExpressionEngineOption.onlyWhenHot && recompilationLimitReached)
} }
Expand Up @@ -246,7 +246,7 @@ public class GraphDatabaseSettings implements LoadableConfig
"never be compiled." ) "never be compiled." )
@Internal @Internal
public static final Setting<String> cypher_expression_engine = setting( public static final Setting<String> cypher_expression_engine = setting(
"unsupported.cypher.expression_engine", optionsIgnoreCase( "INTERPRETED", "COMPILED", DEFAULT ), "INTERPRETED" ); "unsupported.cypher.expression_engine", optionsIgnoreCase( "INTERPRETED", "COMPILED", "ONLY_WHEN_HOT", DEFAULT ), DEFAULT );


@Description( "Number of uses before an expression is considered for compilation" ) @Description( "Number of uses before an expression is considered for compilation" )
@Internal @Internal
Expand Down
Expand Up @@ -186,7 +186,9 @@ class NodeIndexContainsScanAcceptanceTest extends ExecutionEngineFunSuite with C


val query = "MATCH (l:Location) WHERE l.name CONTAINS {param} RETURN l" val query = "MATCH (l:Location) WHERE l.name CONTAINS {param} RETURN l"


failWithError(TestConfiguration(Versions.Default, Planners.Default, Runtimes(Runtimes.ProcedureOrSchema, Runtimes.Interpreted, Runtimes.Slotted)) + failWithError(TestConfiguration(Versions.Default, Planners.Default, Runtimes(Runtimes.ProcedureOrSchema,
Runtimes.Interpreted, Runtimes.Slotted,
Runtimes.SlottedWithCompiledExpressions)) +
TestConfiguration(Versions.all, Planners.Cost, Runtimes(Runtimes.Interpreted, Runtimes.Default)) + TestConfiguration(Versions.all, Planners.Cost, Runtimes(Runtimes.Interpreted, Runtimes.Default)) +
TestConfiguration(Versions.V2_3, Planners.Rule, Runtimes(Runtimes.Interpreted, Runtimes.Default)), TestConfiguration(Versions.V2_3, Planners.Rule, Runtimes(Runtimes.Interpreted, Runtimes.Default)),
query, message = List("Expected a string value, but got 42","Expected a string value, but got Int(42)","Expected two strings, but got London and 42"), query, message = List("Expected a string value, but got 42","Expected a string value, but got Int(42)","Expected two strings, but got London and 42"),
Expand Down
Expand Up @@ -37,7 +37,7 @@ class ShortestPathSameNodeAcceptanceTest extends ExecutionEngineFunSuite with Ru
val expectedToFail = TestConfiguration( val expectedToFail = TestConfiguration(
Versions(Versions.Default, V3_1, V3_4), Versions(Versions.Default, V3_1, V3_4),
Planners(Planners.Cost, Planners.Rule, Planners.Default), Planners(Planners.Cost, Planners.Rule, Planners.Default),
Runtimes(Runtimes.Interpreted, Runtimes.Slotted, Runtimes.Default, Runtimes.ProcedureOrSchema)) Runtimes(Runtimes.Interpreted, Runtimes.Slotted, Runtimes.SlottedWithCompiledExpressions, Runtimes.Default, Runtimes.ProcedureOrSchema))


def setupModel(db: GraphDatabaseCypherService) { def setupModel(db: GraphDatabaseCypherService) {
db.inTx { db.inTx {
Expand Down
Expand Up @@ -39,23 +39,36 @@ class ExpressionEngineConfigurationTest
private final AssertableLogProvider logProvider = new AssertableLogProvider(); private final AssertableLogProvider logProvider = new AssertableLogProvider();


@Test @Test
void shouldNotUseCompiledExpressionsFirstTimeWithDefaultSettings() void shouldBeUsingInterpretedByDefault()
{ {
assertNotUsingCompiled( withEngineAndLimit( "DEFAULT", 1 ), "RETURN sin(cos(sin(cos(rand()))))" ); // Given
String query = "RETURN sin(cos(sin(cos(rand()))))";
GraphDatabaseService db = withEngineAndLimit( "DEFAULT", 0 );
int manyTimes = 10;
for ( int i = 0; i < manyTimes; i++ )
{
assertNotUsingCompiled( db, query );
}
}

@Test
void shouldNotUseCompiledExpressionsFirstTimeWithJitEnabled()
{
assertNotUsingCompiled( withEngineAndLimit( "ONLY_WHEN_HOT", 1 ), "RETURN sin(cos(sin(cos(rand()))))" );
} }


@Test @Test
void shouldUseCompiledExpressionsFirstTimeWhenLimitIsZero() void shouldUseCompiledExpressionsFirstTimeWhenLimitIsZero()
{ {
assertUsingCompiled( withEngineAndLimit( "DEFAULT", 0 ), "RETURN sin(cos(sin(cos(rand()))))" ); assertUsingCompiled( withEngineAndLimit( "ONLY_WHEN_HOT", 0 ), "RETURN sin(cos(sin(cos(rand()))))" );
} }


@Test @Test
void shouldUseCompiledExpressionsWhenQueryIsHotWithDefaultSettings() void shouldUseCompiledExpressionsWhenQueryIsHotWithJitEnabled()
{ {
// Given // Given
String query = "RETURN sin(cos(sin(cos(rand()))))"; String query = "RETURN sin(cos(sin(cos(rand()))))";
GraphDatabaseService db = withEngineAndLimit( "DEFAULT", 3 ); GraphDatabaseService db = withEngineAndLimit( "ONLY_WHEN_HOT", 3 );


// When // When
db.execute( query ); db.execute( query );
Expand All @@ -75,7 +88,7 @@ void shouldUseCompiledExpressionsFirstTimeWhenConfigured()
@Test @Test
void shouldUseCompiledExpressionsFirstTimeWhenExplicitlyAskedFor() void shouldUseCompiledExpressionsFirstTimeWhenExplicitlyAskedFor()
{ {
assertUsingCompiled( withEngineAndLimit( "DEFAULT", 42 ), assertUsingCompiled( withEngineAndLimit( "ONLY_WHEN_HOT", 42 ),
"CYPHER expressionEngine=COMPILED RETURN sin(cos(sin(cos(rand()))))" ); "CYPHER expressionEngine=COMPILED RETURN sin(cos(sin(cos(rand()))))" );
} }


Expand Down

0 comments on commit 090ae57

Please sign in to comment.