Goal
One busy team fills a shared Trino cluster, dashboards sit in QUEUED, and either everything runs at once or nothing does. Resource groups fix this by controlling admission. Work through this list before you put a configuration live, and use the triage section when a queue is stuck.
Know what they don't do: a resource group decides whether a new query may start. When a group exceeds a limit, running queries generally continue and new ones queue. To stop a running query you need query-level limits or a kill.
1. Measure before you size
- Find out what runs now, by user and source:
SELECT resource_group_id, "user", source, state, count(*) AS queries,
max(queued_time_ms) AS max_queued_ms
FROM system.runtime.queries
GROUP BY 1, 2, 3, 4
ORDER BY queries DESC;
system.runtime.queries holds only recent queries on the current coordinator. For peaks over days, use your event listener data (HTTP, Kafka or MySQL listener).
- Record peak concurrent queries, and memory and CPU per workload.
- Set a starting
hardConcurrencyLimitper group from peak useful concurrency, not from the number of users. - Check that every client sets a
source. Without it, selectors can't separate a BI tool from a notebook running as the same user.
trino --server https://trino.example.com --user svc_etl \
--source etl-nightly --client-tags etl,tier1 \
--execute "SELECT current_user"
2. Build the tree
- A group either has sub-groups or accepts queries, never both.
- Parent limits cap the whole subtree. Children can add up to more than the parent so idle capacity is shared.
- Use
${USER}leaf groups to stop one person taking a shared pool.
{
"rootGroups": [
{
"name": "global",
"softMemoryLimit": "90%",
"hardConcurrencyLimit": 60,
"maxQueued": 1000,
"schedulingPolicy": "weighted_fair",
"jmxExport": true,
"subGroups": [
{
"name": "admin",
"softMemoryLimit": "10%",
"hardConcurrencyLimit": 5,
"maxQueued": 20,
"schedulingWeight": 10
},
{
"name": "etl",
"softMemoryLimit": "60%",
"hardConcurrencyLimit": 15,
"maxQueued": 300,
"schedulingWeight": 4,
"jmxExport": true
},
{
"name": "bi",
"softMemoryLimit": "40%",
"softConcurrencyLimit": 20,
"hardConcurrencyLimit": 30,
"maxQueued": 200,
"schedulingWeight": 5,
"jmxExport": true
},
{
"name": "adhoc",
"softMemoryLimit": "40%",
"hardConcurrencyLimit": 20,
"maxQueued": 200,
"schedulingWeight": 1,
"softCpuLimit": "20h",
"hardCpuLimit": "40h",
"subGroups": [
{
"name": "${USER}",
"softMemoryLimit": "15%",
"hardConcurrencyLimit": 3,
"maxQueued": 10
}
]
}
]
}
],
"selectors": [
{ "queryType": "DATA_DEFINITION", "userGroup": "platform-admins", "group": "global.admin" },
{ "userGroup": "platform-admins", "source": "ops-.*", "group": "global.admin" },
{ "user": "svc_etl", "clientTags": ["etl"], "group": "global.etl" },
{ "user": "svc_bi", "group": "global.bi" },
{ "group": "global.adhoc.${USER}" }
],
"cpuQuotaPeriod": "1h"
}
The numbers are examples; replace them with your measurements. userGroup only matches if a group provider is configured.
3. Understand each limit
| Property | Behaviour when reached | Common mistake |
|---|---|---|
hardConcurrencyLimit | New queries queue | Set so high it never applies |
softConcurrencyLimit | New queries run only if peers don't need the slot | Expecting it to be a cap |
softMemoryLimit | New queries queue | Assuming it kills or shrinks running ones |
maxQueued | New queries are rejected | Small value with a bursty BI tool |
softCpuLimit | Permitted concurrency is reduced; needs hardCpuLimit | Setting it alone |
hardCpuLimit | New queries wait for CPU quota within the period | Sized per query rather than per period |
hardPhysicalDataScanLimit | New queries queue for the period | Using a percentage; it takes absolute values only |
- Set
cpuQuotaPeriod(orphysicalDataScanQuotaPeriod) at the top level whenever a matching limit is used. - Remember that memory is checked at admission. Ten queries can be admitted while usage is low, then grow together.
4. Choose the scheduling policy
| Policy | Behaviour | Use for |
|---|---|---|
fair | FIFO within a group; sub-groups take turns | Default, equal teams |
weighted_fair | Sub-group furthest below its expected share of concurrency goes next | Mixed ETL, BI and ad hoc |
weighted | Random choice in proportion to weight or query_priority | Statistical sharing |
query_priority | Strict priority order; all sub-groups must use it too | Trusted schedulers only |
Warning
Under
query_priority, users who can set thequery_prioritysession property can jump the queue and starve everyone else. Restrict it with session property access rules.
5. Order the selectors
- File manager: evaluated top to bottom, first match wins. Put specific rules above general ones.
- Database manager: evaluated by descending
priority. Give every row a distinct priority, and make sureenvironmentinresource_groupsmatchesnode.environment. - End with a catch-all. A query with no matching selector is rejected.
- Prefer
authenticatedUserwhere users can impersonate others.userfollows session changes. - Don't trust
sourceorclientTagsalone for privileged groups: clients set them. Combine with a user or group rule. - Every condition in one selector must match (logical AND).
- Provide an admin path for
DATA_DEFINITION, so thatkill_queryisn't stuck in the queue you're trying to clear.
6. Add query-level limits
Resource groups can't stop a bad query after it starts. Set guards in etc/config.properties, with values from your own measurements:
query.max-execution-time=2h
query.max-run-time=6h
query.max-cpu-time=100h
query.max-scan-physical-bytes=20TB
query.max-run-time includes queued time; query.max-execution-time doesn't. With long queues, a tight run-time limit fails queries that never had a chance to start.
Where workloads need different values, use a session property manager that matches on resource group rather than raising the global limit for everyone.
7. Deploy safely
File manager, in etc/resource-groups.properties on the coordinator:
resource-groups.configuration-manager=file
resource-groups.config-file=etc/resource-groups.json
- Validate the JSON before a restart:
jq empty etc/resource-groups.json. An invalid file can stop the coordinator starting. - Plan a coordinator restart for file changes.
Caution
Restarting the coordinator fails running queries. Drain the workload first, or use the database manager so changes reload without a restart.
Database manager:
resource-groups.configuration-manager=db
resource-groups.config-db-url=jdbc:postgresql://db.example.com:5432/resource_groups
resource-groups.config-db-user=trino_rg
resource-groups.config-db-password=${ENV:RG_DB_PASSWORD}
resource-groups.max-refresh-interval=1h
- If refresh fails for longer than
max-refresh-interval, the cluster stops accepting queries. Treat that database as a production dependency and alert on it. - Test each selector: run one query per client type and check where it landed.
SELECT query_id, "user", source, state, resource_group_id
FROM system.runtime.queries
WHERE created > current_timestamp - INTERVAL '10' MINUTE
ORDER BY created DESC;
8. Triage a stuck queue
| Symptom | Cause | Fix |
|---|---|---|
QUERY_QUEUE_FULL errors | maxQueued reached here or on a parent | Find the blocker; raise the limit only for real bursts |
| Queued, group below its concurrency limit | Parent is full, or memory or CPU limit reached | Check every ancestor, not just the leaf |
| All queries in the catch-all | Missing source, or group provider failing | Check resource_group_id against selectors |
| Queue drains at the start of each period | CPU or scan quota | Raise the quota or move the heavy job |
| Few running, all workers saturated | Queries too large | Lower concurrency and tune the queries |
Find the long runners and stop one deliberately:
SELECT query_id, "user", resource_group_id, started, query
FROM system.runtime.queries
WHERE state = 'RUNNING'
ORDER BY started LIMIT 20;
CALL system.runtime.kill_query(
query_id => '20261125_101500_00042_abcde',
message => 'Stopped by platform on-call: blocking the BI queue');
Warning
Killing a write can leave partial files for some connectors, such as non-transactional Hive tables. Check the target before rerunning the job.
Prevent it next time
- Alert on queued time per group and on rejections, not only queue length.
- Keep the configuration in Git and test selectors in CI with a sample of real user, source and tag combinations.
- Review limits after adding workers: percentages scale, concurrency and CPU quotas don't.
- Move ETL to its own cluster when its peak and the BI peak can't both fit.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get