Important
Helios features are now enabled during weekly update windows and are no longer directly tied to SingleStore engine releases. Refer to the release notes to view the latest features available in your Helios cluster.
Distributed Plancache
On this page
Note
This is a Preview feature.
The Distributed PlanCache (DPC) is a third layer of the plancache that supplements the in-memory plancache and the on-disk persistent plancache (PPC).
The DPC improves performance in the following scenarios:
-
Fast scaling: The DPC triggers plan synchronization during a node's reprovisioning phase.
During reprovisioning, recently used query plans are downloaded to nodes’ PPCs. -
Clusters with multiple aggregator nodes: Aggregators periodically sync the most recently used plans from other aggregators.
Overview
When the DPC is enabled, plans are synchronized automatically between nodes.
Similar to how the PPC functions, a plan downloaded to the DPC is usable except when:
-
A variable affecting the plan has changed in the node.
-
A table in a query has changed significantly (for example, the number of rows in the table has changed by a factor of two times or more) since the plan was generated.
In addition to downloading plans from the DPC, nodes also upload plans to the DPC to make those plans available to other nodes.
DPC operations do not interfere with regular cluster operations.
The DPC operates on a best-effort basis and does not guarantee that plan compilation will not occur on a new node.
Remarks
-
DPC requires that the cluster have Unlimited Storage enabled.
DPC utilizes unlimited storage to store plancache files. -
DPC only stores plans generated during
MBC,LLVM, andINTERPRET_interpreter modes.FIRST -
Plan synchronization is not supported on the Master Aggregator.
Enable and Manage the Distributed Plancache
Enable the Distributed Plancache
The enable_ engine variable controls the DPC.
Use the following command to verify the DPC is enabled.
SELECT @@enable_distributed_plancache;
+--------------------------------+
| @@enable_distributed_plancache |
+--------------------------------+
| 1 |
+--------------------------------+Manage the Distributed Plancache
When the DPC is enabled, nodes automatically download, upload, and delete plans from the DPC.
Nodes download plans from the DPC to their local PPC when the cluster scales, is rebalanced, or a new node is added to the cluster.
The download, upload, delete, and synchronization operations occur in the background and are managed by the DPC task queue.
Aggregator Synchronization
Child aggregators can be configured to automatically synchronize their local PPCs with the DPC.
The following diagram shows two child aggregators with different in-memory and disk plans synchronizing through the Distributed Plancache after the configured aggregator synchronization interval.
When enable_ is set to ON, at the interval specified by distributed_, each aggregator performs an aggregator synchronization operation and downloads the most recently used distributed_ query plans from the DPC.
Asynchronous DPC Lookup
With asynchronous DPC lookup, query execution looks for plans in the DPC during query optimization and Code Generation.
Without the Distributed Plancache, each node compiles the query plan locally, even when the same query has already been compiled on another node
The following diagram shows query-plan execution without the Distributed Plancache: a query sent to different aggregators is compiled locally on each node instead of being reused across the cluster.
The following diagram shows asynchronous DPC lookup: the query checks memory and the persistent plancache, then a background thread checks the Distributed Plancache while optimization and code generation proceed.
This behavior is controlled by the session variable enable_.
SET SESSION enable_dpc_lookup = ON;
When there is a PPC miss and the following are true, a thread is launched to lookup and download the plan from the DPC:
-
enable_is enabled.dpc_ lookup -
enable_is not enabled.synchronous_ dpc_ lookup -
The interpreter mode is set to
interpret_.first
Assuming the plan exists in the DPC, there are three different scenarios:
A: Download from the DPC completes before query optimization and code generation complete.
B: Download from the DPC completes after query optimization and code generation complete, but before local asynchronous compilation is launched.
C: Download from the DPC completes after local asynchronous compilation has launched.
Complex queries (for example, large queries with many joins) whose plans are in the DPC often result in Scenario A.
The engine variable max_ controls the maximum concurrent download threads for asynchronous DPC lookups.
Without the Distributed Plancache, each node compiles the query plan locally, even when the same query has already been compiled on another node.
Synchronous DPC Lookup
With synchronous DPC lookup, query execution looks to the DPC before starting query optimization, and Code Generation.
In contrast to asynchronous lookup, synchronous lookup does not launch a separate thread for the DPC lookup; instead synchronous lookup waits until after the DPC lookup has completed before launching local compilation, optimization, and code generation.
If it is known that a query will take a long time for optimization and code generation and it is expected that the query plan will be in the DPC, then synchronous lookup is the better option.
Syncronous DPC lookup is enabled when enable_ is set to ON on aggregator nodes.
The following diagram shows synchronous DPC lookup path showing plan lookup through memory, PPC, and DPC before compilation.
Engine Variables
The following engine variables are used to manage the DPC:
|
Name |
Description |
|---|---|
|
|
Specifies the number of threads used to process tasks in the task queue for the DPC. |
|
|
Specifies the maximum number of plans downloaded in a synchronization task for the DPC. |
|
|
Specifies the interval between aggregators' periodic synchronizations for the DPC. |
|
|
Specifies if aggregators periodically synchronize their local PPC with the DPC. |
|
|
A session variable that enables asynchronous DPC lookups. |
|
|
A session variable that specifies that nodes look for a plan in the DPC when a plan is not found in the node's local PPC. |
|
|
Controls the maximum concurrent download threads for asynchronous DPC lookups. |
Refer to List of Engine Variables for default values.
Resume and Recovery Behavior
Restoring Child-Aggregator Query Plans after Resume
When a cluster resumes or recovers, child aggregators can restore query plans from the Distributed Plancache (DPC) instead of recompiling them locally.
During recovery, DPC download tasks are queued after the global variables are synchronized.
This behavior uses the existing enable_ setting.
When troubleshooting resume or recovery performance, use SHOW DISTRIBUTED_ and the DPC queue status variables to determine whether plan downloads completed or whether plans were recompiled locally.
Plan-file Organization and Database-name Handling
DPC plan-file organization in object storage and database-name handling use the normalized database name.
These changes preserve DPC functionality and do not add new configuration settings.
Observe Distributed Plancache Statistics
Connect to a node and use the SHOW DISTRIBUTED_
SHOW DISTRIBUTED_PLANCACHE STATUS;
+-------------------------------------------------------+-------+
| Stat | Value |
+-------------------------------------------------------+-------+
| Successful Downloads Since Startup | 128 |
| Skipped Downloads Since Startup | 110 |
| Failed Downloads Since Startup | 0 |
| Plans Uploaded Since Startup | 2 |
| Plans Deleted Since Startup | 0 |
| DB Synchronization Since Startup | 1 |
| Successful Downloads From Periodic Sync Since Startup | 12 |
| Skipped Downloads From Periodic Sync Since Startup | 107 |
| Failed Downloads From Periodic Sync Since Startup | 0 |
| Periodic Query Plan Syncs Since Startup | 1 |
| Distributed Plancache Plans Used Since Startup | 90 |
| Currently Queued Populate Download Tasks | 0 |
| Currently Queued Download Tasks | 0 |
| Currently Queued Upload Tasks | 0 |
| Currently Queued Delete Tasks | 0 |
| Avg Plan Download Latency (ms) | 13 |
| Avg Plan Upload Latency (ms) | 38 |
| Avg Plan Delete Latency (ms) | 0 |
| Avg Duration For DB Plan Synchronization (ms) | 1710 |
+-------------------------------------------------------+-------+Note: Failed Downloads indicate that the node tried to download a plan file from the DPC, but failed to do so typically because the plan did not exist in the DPC.
Use the following commands to view the number of tasks in the DPC task queue.
SHOW STATUS LIKE 'Queued_DPC_Uploads';SHOW STATUS LIKE 'Queued_DPC_Downloads';SHOW STATUS LIKE 'Queued_DPC_PopulateDownloads';SHOW STATUS LIKE 'Queued_DPC_Deletes';
If the values of these metrics increase significantly and the number of compilations rises due to slow plan synchronization, SingleStore recommends considering an increase in the DPC worker thread pool size (distributed_).
Use DPC with a New Cluster
Use the following steps to use the DPC for a specific database in a new cluster.
-
Enable the distributed plancache.
This command enables the distributed plancache for the entire cluster group. SET GLOBAL enable_distributed_plancache = ON; -
The plans that need to be downloaded to the new cluster must exist in the DPC, that is, those plans must be compiled locally in any of the nodes after
enable_was turned on.distributed_ plancache -
This can be achieved by either removing and recompiling that plan, or letting the cluster run for a while so the nodes naturally recompile the plan over time.
-
-
Set
distributed_to the number of plans that is expected for the database (default 1000).plancache_ max_ download_ plans SET distributed_plancache_max_download_plans = <number_of_expected_plans>; -
Create a new cluster, attach the database to the new cluster.
-
The plans automatically sync after step 4 has been completed.
-
If more plans need to be synchronized explicitly or if the value set in step 3 was too small, run _
SYNC_ PLANS <database name>on the aggregator node to download the most recently used query plans for that database again (plans that already exist in the DPC are skipped).
Plancache Manager
The Plancache Manager (PCM) is an external service that stores metadata about plans stored in a cluster's plancache.
A cluster with DPC enabled automatically uses the PCM.
Last modified: