heavydb icon indicating copy to clipboard operation
heavydb copied to clipboard

Calcite parser performance

Open fleapapa opened this issue 9 years ago • 4 comments

Did a test by feeding 1M SQL queries to mapd-server via mapdql. Every query is the same and is "select t.* from t where t.a = t.b and t.c = 99;". Table 't' does not exist, so the queries should incur minimum (I/O) work load. The 1M query strings are stored in file '1'. Ran command "time cat 1 | mapd/bin/mapdql mapd -u $MAPD_USERNAME -p $MAPD_PASSWORD 1>&2 2>/dev/null" to start the test.

Saw a dozen of Calcite threads very busy, but the 1M queries could not be finished in 10 MINUTES.

(For comparison purpose only) Clickhouse took 11 seconds to finish the same 1M queries.

A hand-crafted (minimum) SQL parser using bison/C++ took 15 seconds.

The 10+ minutes seem coming from Calcite parser alone and/or communication overhead between mapd_server and Calcite.

Not sure if this test makes any sense. Parsing time is only a tiny percentage of the time of processing a query, but in applications with very high frequency of queries the tiny parsing time can be magnified significantly.

[ the test was conducted on a Ubutu 16.04 VM hosted on a Macbook Air 2012 ]

fleapapa avatar Sep 17 '17 04:09 fleapapa

For that high frequency of queries to materialize, the execution time would have to be the same order of magnitude of the parsing time. With a fully warmed up JVM, Calcite takes ~3-4 milliseconds IIRC. Having well-formed queries on a big enough data set complete this quickly would be a great problem to have :). But we actually agree it's still not great and have a few ideas how to fix it -- we can multi-thread the Calcite parsing and analysis, cache the relational algebra, optimize Calcite itself etc.

asuhan avatar Sep 17 '17 04:09 asuhan

Thanks for the lightning response again :)

Looking from cpu usage, warming up Calcite JVM seemed taking only 2~3 seconds during which cpu was fully busy. It is suspicious that cpu then became only ~60% busy after JVM was warmed up. There seemed task transition gap in mapd's processing pipeline (if any). Because the table 't' doesn't exist, there should be no or very short I/O waiting time that can contribute to the "gap"...

fleapapa avatar Sep 17 '17 05:09 fleapapa

Later i realized that the gap is not an issue but a consequence of running only one mapdql which is able to send only one query at a time so unable to saturate work load of all mapd and calcite worker threads.

When running the same test command on two separate terminal windows simultaneously, cpu usage became always 100% on my 2-core VM (though now it has 2M queries to parse :)

fleapapa avatar Sep 17 '17 17:09 fleapapa

closing this as issue i believe is understood and working as expected

dwayneberry avatar Nov 19 '17 08:11 dwayneberry