Add session property to enforce timeout for query registration in HBO#23354
Add session property to enforce timeout for query registration in HBO#23354feilong-liu merged 1 commit intoprestodb:masterfrom
Conversation
| boolean registerSucceed = false; | ||
| if (enforceHistoryBasedOptimizerRegistrationTimeout(session)) { | ||
| ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
| Future<Boolean> future = executor.submit(() -> statsCalculator.registerPlan(newPlan, session, startTimeInNano, timeoutInMilliseconds)); | ||
| try { | ||
| registerSucceed = future.get(timeoutInMilliseconds, MILLISECONDS); | ||
| } | ||
| catch (Exception ignored) { | ||
| } | ||
| finally { | ||
| executor.shutdownNow(); | ||
| } |
There was a problem hiding this comment.
This is the main change
|
1597d5f to
0934faa
Compare
0934faa to
ce982f2
Compare
There was a problem hiding this comment.
Thanks for adding the doc!
The config properties table is malformed, throwing this error in a local doc build:
/Users/steveburnett/Documents/GitHub/presto/presto-docs/src/main/sphinx/optimizer/history-based-optimization.rst:34: ERROR: Malformed table. Column span alignment problem in table line 3.
See my comment in PR #23335 and my own PR #23322 for how to fix the table.
For the two PRs referenced above, I see imbalance between line 32 and line34. However in my case these two lines match. Is there any fix which can be done here? |
I apologize, I must have been on a wrong branch from another PR. I have restarted my review confirming that I am working with your branch in this PR and you are correct, you don't have this error. Please ignore my previous comment. |
steveburnett
left a comment
There was a problem hiding this comment.
LGTM! (docs)
Pulled this branch, made a new local doc build, and the new property entries in both tables look good. Thanks!
...ook/presto/sql/planner/optimizations/HistoricalStatisticsEquivalentPlanMarkingOptimizer.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Test | ||
| public void testHistoryBasedStatsCalculatorEnforceTimeOut() |
There was a problem hiding this comment.
this looks like it tests cases where the timeout is enabled, but never exceeded. Can you add a test case where the timeout gets enforced, eg. you set the timeout really low (like to 0?) and then check that we don't use hbo stats?
There was a problem hiding this comment.
Added test with time limit to be 0
ce982f2 to
62b9c91
Compare
| "SELECT * FROM nation where substr(name, 1, 1) = 'A'", | ||
| anyTree(node(FilterNode.class, any()).withOutputRowCount(Double.NaN))); | ||
|
|
||
| // HBO Statistics |
There was a problem hiding this comment.
why is this using hbo statistics? Shouldn't registration fail due to exceeding the time limit?
There was a problem hiding this comment.
This is to test the case where HBO statistics are written successfully (with large timeout limit), and later it tests that read of HBO statistics either succeed (if timeout limit is large) or fail (if timeout limit is 0).
I just added a few new test cases too, which is HBO statistics write failed (with 0 timeout limit), and no HBO statistics will be read.
62b9c91 to
bf91cdb
Compare
| public void noProcessQueryEvents() | ||
| { | ||
| try { | ||
| assertFalse(semaphore.tryAcquire(10, TimeUnit.SECONDS)); |
There was a problem hiding this comment.
semaphore is released during the putStats function call. If HBO failed, there will be no putStats function call, hence we will not get the semaphore here. Use this function to assert the case where HBO timeout
Description
HBO optimizer has several external dependency, it retrieves history statistics from external storage, get input table size information from metastore. It also canonicalize and hash the whole query plan, which can also be expensive when the query plan is large.
While latency of HBO optimizer is generally low, we have observed high latency for some queries occasionally. This has prohibited the usage of HBO optimizer in interactive workload with high latency requirement. Since HBO is an opportunistic optimization, i.e. queries still work without HBO, we can choose to skip it if it takes a long time to complete.
In this PR I add a session property to enforce timeout so that we can cap the maximum time spent in HBO optimizer
Motivation and Context
To enable HBO for interactive workload with high latency requirement
Impact
Enable HBO for interactive workload
Test Plan
Run end to end with production traffic, and also add unit tests
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.