Optimize Superset
To optimize Apache Superset itself, tune how it caches results, how many requests and queries it can run at once, and how charts and dashboards ask for data. This page covers superset_config.py settings, deployment, chart and dashboard options, and how to find slow queries.
For dataset and table design, see Optimize Data.
Superset settings and deployment
Enable async query execution
By default, chart queries run inside the Superset web server, so long queries tie up web workers and can time out. With async execution, Celery workers run the queries in the background and the browser picks up the results when they're ready.
- SQL Lab: in Edit database → Advanced → Performance, turn on Asynchronous query execution.
- Dashboards and charts: turn on the
GLOBAL_ASYNC_QUERIESfeature flag insuperset_config.py.
Both need running Celery workers, Redis, and a results backend. Set these up with the Celery configuration guide.
Cancel queries when users leave the page
When someone closes the browser tab or moves to another page while a query is still running, the database keeps working on a result nobody will see. Superset can cancel those queries for you:
- Open Settings → Database Connections and edit the database.
- Go to Advanced → SQL Lab.
- Turn on Cancel query on window unload event (Terminate running queries when browser window closed or navigated to another page).
This applies to queries run from SQL Lab, and only on databases that support query cancellation, such as PostgreSQL, MySQL, Presto, Hive and Snowflake.
Cache the right datasets
Caching saves a query's result so the next chart load reuses it instead of querying the database again. Cache results take memory in your cache store (usually Redis), so cache where it pays off:
- Don't set one cache timeout for the whole database. It fills the cache with results that didn't need caching.
- Skip caching for fast queries. If a query returns in well under a second, caching it saves little and still uses memory.
- Cache datasets on large tables and slow queries. These are the ones that are expensive to re-run.
- Match the timeout to how often the data refreshes. If a job refreshes the table once a day, a cache timeout of 6–8 hours (
21600–28800seconds) works well. Most dashboard loads come from the cache, and new data shows up within a few hours of the refresh without anyone clicking Force refresh.
Set the timeout per dataset in Edit dataset → Settings → Cache timeout (in seconds), or per chart in the chart's Edit properties. A chart's timeout overrides its dataset's, and a dataset's overrides the database's.
Warm up the cache after data refreshes
The first person to open a dashboard after the cache expires waits for every query. A scheduled cache warm-up runs those queries ahead of time. Schedule it shortly after your data refresh job, so the cache is filled with fresh data before people arrive.
Add the cache task to Celery beat in superset_config.py:
from celery.schedules import crontab
class CeleryConfig:
broker_url = "redis://localhost:6379/0"
result_backend = "redis://localhost:6379/0"
imports = (
"superset.sql_lab",
"superset.tasks.scheduler",
"superset.tasks.cache",
)
beat_schedule = {
"cache-warmup-daily": {
"task": "cache-warmup",
"schedule": crontab(minute=30, hour=6), # after the nightly refresh
"kwargs": {
"strategy_name": "top_n_dashboards",
"top_n": 10,
"since": "7 days ago",
},
},
}
CELERY_CONFIG = CeleryConfig
top_n_dashboards warms the most viewed dashboards. The dashboard_tags strategy warms dashboards with given tags instead. This needs Celery workers and Celery beat running; see the Celery configuration guide.
Use Redis for every cache
Superset keeps several caches. Point all of them at Redis rather than the in-memory or filesystem defaults, so they're shared across web servers and workers and survive restarts:
REDIS_URL = "redis://localhost:6379"
CACHE_CONFIG = {
"CACHE_TYPE": "RedisCache",
"CACHE_DEFAULT_TIMEOUT": 86400,
"CACHE_KEY_PREFIX": "superset_",
"CACHE_REDIS_URL": f"{REDIS_URL}/1",
}
DATA_CACHE_CONFIG = {
"CACHE_TYPE": "RedisCache",
"CACHE_DEFAULT_TIMEOUT": 21600, # 6 hours
"CACHE_KEY_PREFIX": "superset_data_",
"CACHE_REDIS_URL": f"{REDIS_URL}/2",
}
FILTER_STATE_CACHE_CONFIG = {
"CACHE_TYPE": "RedisCache",
"CACHE_DEFAULT_TIMEOUT": 86400,
"CACHE_KEY_PREFIX": "superset_filter_",
"CACHE_REDIS_URL": f"{REDIS_URL}/3",
}
EXPLORE_FORM_DATA_CACHE_CONFIG = {
"CACHE_TYPE": "RedisCache",
"CACHE_DEFAULT_TIMEOUT": 86400,
"CACHE_KEY_PREFIX": "superset_explore_",
"CACHE_REDIS_URL": f"{REDIS_URL}/4",
}
DATA_CACHE_CONFIG holds chart results. Its timeout is the default when neither the chart, dataset nor database sets one.
Use PostgreSQL for the metadata database
Superset stores users, charts, dashboards, logs and query history in its metadata database. SQLite is only for trying Superset out: it locks on writes and slows down as the logs grow. In production, use PostgreSQL (or MySQL):
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://superset:password@db-host:5432/superset"
Size the web server
Superset runs on Gunicorn. Each worker handles one request at a time per thread, and a dashboard sends one request per chart, so too few workers makes charts queue up.
gunicorn \
-w 8 \
-k gevent \
--worker-connections 1000 \
--timeout 120 \
-b 0.0.0.0:8088 \
--limit-request-line 0 \
--limit-request-field_size 0 \
"superset.app:create_app()"
- A common starting point is
2 × CPU cores + 1workers. - With the official Docker image, set
SERVER_WORKER_AMOUNT,SERVER_THREADS_AMOUNT,SERVER_WORKER_CLASSandGUNICORN_TIMEOUTas environment variables instead. - Keep
SUPERSET_WEBSERVER_TIMEOUTinsuperset_config.pyequal to the Gunicorn timeout, andSQLLAB_TIMEOUT(synchronous SQL Lab queries) below it.
Size and separate Celery workers
Celery workers run async queries, alerts, reports, thumbnails and cache warm-up. The -c option sets how many tasks each worker runs at once:
celery --app=superset.tasks.celery_app:app worker --pool=prefork -O fair -c 8
If large reports slow down async chart queries, run a second worker pool on its own queue and route the report tasks to it with Celery's task_routes setting, then start that worker with -Q <queue name>.
Set row limits
Row limits stop a single query from pulling millions of rows into Superset and the browser:
ROW_LIMIT = 50000 # maximum rows a chart can return
SQL_MAX_ROW = 100000 # maximum rows an async SQL Lab query can return
DISPLAY_MAX_ROW = 10000 # rows SQL Lab shows in the browser
Lower these if your users don't need that many rows.
Set query timeouts in the database
A runaway query keeps running in the database even after Superset gives up on it. Set a timeout on the database side as well. For PostgreSQL, add this in Edit database → Advanced → Other → Engine Parameters:
{
"connect_args": {
"options": "-c statement_timeout=300000"
}
}
That stops any query from Superset after 5 minutes. Other databases have equivalents, such as STATEMENT_TIMEOUT_IN_SECONDS on a Snowflake warehouse or max_execution_time in ClickHouse.
Serve static files efficiently
Superset's JavaScript and CSS bundles are large. Put a reverse proxy such as Nginx in front of Superset to cache and compress /static/ files, and enable HTTP/2. To serve them from a CDN, set STATIC_ASSETS_PREFIX in superset_config.py to the CDN URL.
Keep the database close to Superset
Every chart query travels from Superset to the database and its results travel back. Every chart on a dashboard pays that round trip, so network distance adds up quickly.
- Same region, same network. Run Superset in the same cloud region, and ideally the same VPC or data center, as the databases behind your dashboards. Cross-region or on-premises-to-cloud connections can add tens to hundreds of milliseconds to every query and charge for the data transferred out.
- Connect over a private network. Use private endpoints or VPC peering rather than the public internet, which is slower and less predictable.
- Bring the data to Superset if the source is far away. If the source system lives in another region, replicate or load the tables Superset needs into a warehouse or read replica next to Superset, and point your datasets there.
Charts and dashboards
Lower row limits and use server pagination
Set each chart's Row limit to what the chart can actually show. For table charts with many rows, turn on Server pagination so Superset fetches one page at a time instead of every row.
Use a bounded default time range
Set the dashboard's time filter, and each chart's Time range, to a bounded default such as Last week or Last month instead of No filter. People can still widen it when they need to.
Split large dashboards into tabs
Charts in a tab that isn't open don't run their queries until someone opens that tab. Splitting a 30-chart dashboard into tabs cuts the first load to the charts on the first tab.
Scope native filters
By default a native filter applies to every chart it can. In the filter's Scoping settings, apply it only to the charts that need it, so changing it doesn't re-run unrelated charts.
Use fewer, richer charts
Each chart is a separate query. Combine related numbers where you can: a table with several metrics, or a Big Number with trendline, instead of many small charts that each query the same table.
Show KPI cards from one query with Handlebars
A row of 10 Big Number cards runs 10 queries, usually against the same table. A single Handlebars chart can show all 10 numbers from one query:
- Create a Handlebars chart on the dataset.
- Set Query mode to Aggregate, add every KPI as a metric, and leave Dimensions empty. The query returns one row with one column per metric.
- Give each metric a simple label without spaces, such as
revenueororders, so the template can refer to it directly. - In Handlebars Template, lay out the cards:
- In CSS Styles, style them as cards:
.kpis {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 12px;
}
.kpi {
padding: 16px;
border-radius: 8px;
background: #f5f7fa;
}
.kpi-label {
display: block;
font-size: 13px;
color: #666;
}
.kpi-value {
font-size: 28px;
font-weight: 600;
}
The dashboard now runs one query instead of 10, and the result is cached as one entry. The trade-off is that Big Number features like the trendline and its own conditional colors need to be rebuilt in the template, so keep Big Number charts for the few KPIs that need a trend.
Find slow queries
Check the SQL a chart runs
In a chart's ⋯ menu, View query shows the exact SQL Superset generates. Copy it into SQL Lab and run it with EXPLAIN (or your database's query profile) to see whether it scans whole tables, misses indexes or skips partition pruning.
Use logs and metrics
- Database slow-query logs (
log_min_duration_statementin PostgreSQL, query history in Snowflake and BigQuery) show which Superset queries take longest. - SQL Lab → Query history shows the duration of each SQL Lab query.
- StatsD metrics: send Superset's timing metrics to your monitoring system:
from superset.stats_logger import StatsdStatsLogger
STATS_LOGGER = StatsdStatsLogger(host="localhost", port=8125, prefix="superset")
Start with the dashboards people open most and the slowest charts on them.
Keep Superset up to date
Each Superset 6.x release includes query and frontend performance fixes. Upgrade regularly, following the Quickstart or your installation guide for the version tag.