Open deigote opened 1 year ago
I believe this change will require the following test to be updated: https://github.com/deigote/presto-gateway/blob/share-routing-rules-among-all-queries/gateway-ha/src/test/java/com/lyft/data/gateway/ha/router/TestRoutingGroupSelector.java#L85
Given the change in the rules file, the gateway would need restarting?
Small performance improvement plus it very likely closes #166 (it solved it for us at least).
By placing the
Rules
creation inside the lambda, the previous implementation required to read the routing rules config file for each request, adding unnecessary latency. More importantly, it was not thread-safe, as therulesEngine
andruleFactory
were shared among all requests, only theRules
creation wasn't.The
ruleFactory
is of classMVELRuleFactory
, which is stateful - it hasRuleDefinitionReader reader
andParserContext parserContext
as private members. Creating theRules
changes that state, so it should not be shared between concurrent threads.Rules
OTOH is a read-only class after it's created (it's just iterated over by theDefaultRulesEngine
). Given that the rules are the same for all requests, and that theRules
usage is thread-safe, it makes sense to share it across all of them.Since deploying this our profiling tool stopped showing the RoutingGroupSelector (which was consuming around 1-2% before) and we stopped seeing the error described in https://github.com/lyft/presto-gateway/issues/166 .