nodetool setconcurrentviewbuilders
Sets the number of concurrent threads used for building materialized views.
Synopsis
Section titled “Synopsis”nodetool [connection_options] setconcurrentviewbuilders <value>See connection options for connection options.
Description
Section titled “Description”nodetool setconcurrentviewbuilders controls how many threads are dedicated to building materialized views. When a materialized view is created or needs to be rebuilt, Cassandra populates it by reading data from the base table and writing corresponding entries to the view. This setting determines how many of these build operations can run in parallel.
What Are Materialized Views?
Section titled “What Are Materialized Views?”Materialized views are automatically maintained copies of base table data, organized by a different primary key to support different query patterns. When data is written to the base table, Cassandra automatically updates all associated materialized views.
-- Base tableCREATE TABLE users ( user_id uuid PRIMARY KEY, email text, country text, created_at timestamp);
-- Materialized view to query users by emailCREATE MATERIALIZED VIEW users_by_email AS SELECT * FROM users WHERE email IS NOT NULL AND user_id IS NOT NULL PRIMARY KEY (email, user_id);
-- Materialized view to query users by countryCREATE MATERIALIZED VIEW users_by_country AS SELECT * FROM users WHERE country IS NOT NULL AND user_id IS NOT NULL PRIMARY KEY (country, user_id);When View Building Occurs
Section titled “When View Building Occurs”View building happens in these scenarios:
| Scenario | Description |
|---|---|
| New view creation | When CREATE MATERIALIZED VIEW is executed, existing base table data must be copied to the view |
| Node bootstrap | When a new node joins, it builds local view data from streamed base table data |
| View rebuild | After corruption or manual truncation of view data |
| Repair | View data may be rebuilt during certain repair operations |
How View Building Works
Section titled “How View Building Works”Each view builder thread:
- Reads partitions from the base table
- Transforms the data according to the view definition
- Writes entries to the materialized view
- Tracks progress for resumption if interrupted
Non-Persistent Setting
This setting is applied at runtime only and does not persist across node restarts. After a restart, the value reverts to the concurrent_materialized_view_builders setting in cassandra.yaml (default: 1).
To make the change permanent, update cassandra.yaml:
concurrent_materialized_view_builders: 2Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
value | Number of concurrent view builder threads (default: 1) |
Examples
Section titled “Examples”View Current Setting
Section titled “View Current Setting”nodetool getconcurrentviewbuildersSet to 2 Concurrent Builders
Section titled “Set to 2 Concurrent Builders”nodetool setconcurrentviewbuilders 2Set to 4 for Faster Building
Section titled “Set to 4 for Faster Building”nodetool setconcurrentviewbuilders 4When to Adjust View Builders
Section titled “When to Adjust View Builders”Scenario 1: Creating a New Materialized View on Large Table
Section titled “Scenario 1: Creating a New Materialized View on Large Table”Situation: Creating a view on a table with billions of rows—initial build will take a long time.
Diagnosis:
# Check current view build statusnodetool viewbuildstatus
# Check current settingnodetool getconcurrentviewbuildersAction: Increase builders to speed up initial population:
# Increase during view creationnodetool setconcurrentviewbuilders 4
# Monitor progresswatch -n 30 'nodetool viewbuildstatus'
# After completion, restore default to conserve resourcesnodetool setconcurrentviewbuilders 1Scenario 2: Multiple Views Being Built Simultaneously
Section titled “Scenario 2: Multiple Views Being Built Simultaneously”Situation: Several materialized views are being created or rebuilt at the same time.
Diagnosis:
# Check how many views are buildingnodetool viewbuildstatusExample output:
Keyspace View Statusmyks users_by_email BUILDING (45%)myks users_by_country BUILDING (23%)myks users_by_created STARTEDAction: With multiple views building, more threads can help:
nodetool setconcurrentviewbuilders 4Scenario 3: View Build Impacting Production Traffic
Section titled “Scenario 3: View Build Impacting Production Traffic”Situation: View building is consuming too many resources, causing latency spikes.
Diagnosis:
# Check disk I/Oiostat -x 1 5
# Check latenciesnodetool proxyhistograms
# Check if view building is activenodetool viewbuildstatusAction: Reduce builders to minimize impact:
# Slow down view buildingnodetool setconcurrentviewbuilders 1
# Or pause entirely during peak hours by setting to 0 (if supported)Scenario 4: Node Bootstrap Taking Too Long
Section titled “Scenario 4: Node Bootstrap Taking Too Long”Situation: New node is joining and building views is a bottleneck.
Diagnosis:
# On the new nodenodetool viewbuildstatusnodetool netstatsAction: Increase builders to speed up bootstrap:
nodetool setconcurrentviewbuilders 4Scenario 5: Off-Peak Maintenance Window
Section titled “Scenario 5: Off-Peak Maintenance Window”Situation: Want to complete view builds quickly during a maintenance window.
Action:
# During maintenance window - maximize throughputnodetool setconcurrentviewbuilders 8
# Monitor progressnodetool viewbuildstatus
# After completion or before peak hoursnodetool setconcurrentviewbuilders 1Impact on Cluster Performance
Section titled “Impact on Cluster Performance”Resource Consumption
Section titled “Resource Consumption”| Resource | Impact of More Builders |
|---|---|
| CPU | Higher utilization during builds |
| Disk I/O | More concurrent reads (base table) and writes (view) |
| Memory | More data buffered in memory |
| Network | Minimal (view building is local) |
Trade-offs
Section titled “Trade-offs”| Setting | Build Speed | Production Impact | Use Case |
|---|---|---|---|
| 1 (default) | Slow | Minimal | Normal operations |
| 2-4 | Moderate | Noticeable | Off-peak view creation |
| 4-8 | Fast | Significant | Maintenance windows |
| 8+ | Very fast | High | Emergency rebuilds |
Monitoring During View Building
Section titled “Monitoring During View Building”#!/bin/bash# monitor_view_build.sh - Watch view build progress and impact
while true; do clear echo "=== $(date) ===" echo ""
echo "--- View Build Status ---" nodetool viewbuildstatus echo ""
echo "--- Current View Builders ---" nodetool getconcurrentviewbuilders echo ""
echo "--- Disk I/O ---" iostat -x 1 1 | grep -E "Device|sd|nvme" | tail -2 echo ""
echo "--- Latencies ---" nodetool proxyhistograms | head -10
sleep 30doneMetrics to Monitor
Section titled “Metrics to Monitor”View Build Progress
Section titled “View Build Progress”# Check status of all view buildsnodetool viewbuildstatusExample output:
Keyspace View Statusmyks users_by_email BUILDING (78%)myks users_by_country SUCCESSmyks users_by_created BUILDING (12%)Thread Pool Statistics
Section titled “Thread Pool Statistics”# View builder tasks appear in tpstatsnodetool tpstats | grep -i viewKey Metrics
Section titled “Key Metrics”| Metric | How to Check | Concern Threshold |
|---|---|---|
| Build progress | nodetool viewbuildstatus | Stuck at same percentage |
| Disk I/O util | iostat -x 1 | Sustained 100% |
| Read latency | nodetool proxyhistograms | P99 significantly elevated |
| Write latency | nodetool proxyhistograms | P99 significantly elevated |
Recommended Values
Section titled “Recommended Values”General Guidelines
Section titled “General Guidelines”| Scenario | Recommended Value | Notes |
|---|---|---|
| Normal operations | 1 | Minimize impact on production |
| Small table view creation | 1-2 | Quick enough, low impact |
| Large table view creation | 2-4 | Balance speed and impact |
| Maintenance window | 4-8 | Maximize throughput |
| Multiple simultaneous views | 2-4 | Parallel progress |
| HDD storage | 1-2 | Limited by disk I/O |
| SSD/NVMe storage | 2-8 | Can handle more parallelism |
Hardware Considerations
Section titled “Hardware Considerations”| Storage Type | CPU Cores | Suggested Max |
|---|---|---|
| HDD | Any | 2 |
| SATA SSD | 4-8 | 2-4 |
| SATA SSD | 16+ | 4-6 |
| NVMe SSD | 16+ | 4-8 |
Materialized View Build Process Details
Section titled “Materialized View Build Process Details”Build Phases
Section titled “Build Phases”- Initialization - View metadata created, build job scheduled
- Scanning - Base table partitions read sequentially
- Transformation - Data transformed to view schema
- Writing - View entries written to local SSTables
- Completion - Build marked complete, view becomes queryable
Progress Tracking
Section titled “Progress Tracking”Build progress is tracked in system.view_builds_in_progress:
SELECT * FROM system.view_builds_in_progress;Resumption After Failure
Section titled “Resumption After Failure”If a node crashes during view building:
- Progress is checkpointed periodically
- On restart, build resumes from last checkpoint
- No need to restart from scratch
Interaction with Other Settings
Section titled “Interaction with Other Settings”Compaction
Section titled “Compaction”View building creates new SSTables, which may trigger compaction:
# If view builds cause compaction storms, considercompaction_throughput: 64MiB/sConcurrent Reads/Writes
Section titled “Concurrent Reads/Writes”View building uses the same read/write paths:
concurrent_reads: 32 # View building reads from base tableconcurrent_writes: 32 # View building writes to viewHigh view builder count can compete with production traffic for these thread pools.
Memory
Section titled “Memory”More builders mean more data in memory:
# Ensure adequate heap for concurrent builds-Xmx8GCluster-Wide Configuration
Section titled “Cluster-Wide Configuration”Apply to All Nodes
Section titled “Apply to All Nodes”#!/bin/bashVALUE="${1:-1}"# Get list of node IPs from local nodetool status
nodes=$(nodetool status | grep "^UN" | awk '{print $2}')
echo "Setting concurrent view builders to $VALUE on all nodes..."
for node in $nodes; do echo -n "$node: " ssh "$node" "nodetool setconcurrentviewbuilders $VALUE \" && echo "set to $VALUE" \ || echo "FAILED"done
echo ""echo "Verification:"for node in $nodes; do echo -n "$node: " ssh "$node" "nodetool getconcurrentviewbuilders"doneMaking Changes Permanent
Section titled “Making Changes Permanent”concurrent_materialized_view_builders: 2Troubleshooting
Section titled “Troubleshooting”View Build Stuck at Same Percentage
Section titled “View Build Stuck at Same Percentage”# Check if build is actually progressingnodetool viewbuildstatus
# Check for errors in logsgrep -i "view\|materialized" /var/log/cassandra/system.log | tail -50
# Check for resource bottlenecksiostat -x 1 3nodetool tpstatsView Build Very Slow
Section titled “View Build Very Slow”# Check current settingnodetool getconcurrentviewbuilders
# Increase if resources availablenodetool setconcurrentviewbuilders 4
# Check disk is not bottleneckiostat -x 1 5View Build Impacting Production
Section titled “View Build Impacting Production”# Reduce builders immediatelynodetool setconcurrentviewbuilders 1
# Check latencies improvingnodetool proxyhistograms
# Consider scheduling builds during off-peakBuild Failed or View Inconsistent
Section titled “Build Failed or View Inconsistent”# Check view statusnodetool viewbuildstatus
# If needed, rebuild the view# Warning: This is disruptiveALTER MATERIALIZED VIEW myks.my_view WITH rebuild = true;Best Practices
Section titled “Best Practices”View Builder Guidelines
- Start with default (1) - Minimize production impact
- Increase during off-peak - Use maintenance windows for faster builds
- Monitor progress - Watch
viewbuildstatusand disk I/O - Restore after completion - Return to default when builds finish
- Consider storage type - SSDs can handle more parallelism than HDDs
- Plan large view creations - Schedule during low-traffic periods
- Make permanent if needed - Update
cassandra.yamlfor consistent behavior
Materialized View Caveats
Materialized views have significant operational overhead:
- Every base table write triggers view updates
- Views can become inconsistent and require repair
- Large views take a long time to build
- Views add latency to write operations
Consider alternatives like secondary indexes or application-side denormalization for simpler use cases.
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| getconcurrentviewbuilders | View current setting |
| viewbuildstatus | Check view build progress |
| tpstats | Thread pool statistics |
| compactionstats | Monitor compaction from view builds |