Distribute data using vnodes
You can use virtual nodes (vnodes) to automatically allocate token ranges to each replica node. Using vnodes simplifies partition distribution within a DataStax Enterprise (DSE) cluster:
-
DSE automatically calculates and assigns tokens to each node.
-
DSE automatically rebalances the cluster when you add, remove, or replace nodes.
When a node joins the cluster, it assumes responsibility for an even portion of data from the other nodes in the cluster. If a node fails, the database rebalances the load across the other nodes in the cluster.
-
DSE rebuilds dead nodes faster because every other node in the cluster participates in the rebuild.
-
DSE can accommodate different proportions of vnodes for each node in a cluster, allowing you to use different hardware for each node in a cluster. For example, you might create some nodes with smaller machine images or less CPU power than other nodes, and then assign fewer vnodes to the smaller nodes.
Comparison with single-token architecture
In single-token architecture clusters, you must calculate and assign a single token to each node in a cluster. Each token determines the node’s position in the cluster, also known as the ring, and the portion of data assigned to the node according to the hash value. With vnodes, each node owns many small partition ranges distributed throughout the cluster. Partition ranges are based on the partitioner.
Virtual nodes use consistent hashing to distribute data without requiring new token generation and assignment each time you add, remove, or replace a node.
With a single-token architecture, you assign each node a single token that represents a location in the ring. A node owns exactly one contiguous partition range in the ring space. Each node stores the data mapped from the partition key to a token value within a range spanning from the previous node to the current node’s assigned value. Each node also contains copies of each row from other nodes in the cluster. For example, if the replication factor is 3, each range replicates to three nodes on the ring.
In contrast, when the ring has vnodes, the database randomly selects vnodes within the cluster, which makes the partition ranges non-contiguous. The hash of the partition key determines the placement of a row within many smaller partition ranges belonging to each node.
Performance considerations for vnodes
Make sure the number of vnodes is appropriate for your cluster and workloads; more vnodes doesn’t always mean better performance.
While vnodes provide considerable operational benefits, be aware that the number of vnodes you assign to any one node can impact cluster-wide operations. For example, when you increase the number of vnodes, you also increase the number of repairs that run during a repair cycle, which increases the duration of full cluster repairs.
For most workloads, DataStax recommends 8 or 16 vnodes. In performance tests, 8 vnodes distributed token ranges between nodes with approximately 10 percent variance and minimal impact on performance.
| Replication factor | Approximate variance at 4 vnodes | Approximate variance at 8 vnodes | Approximate variance at 64 vnodes | Approximate variance at 128 vnodes |
|---|---|---|---|---|
2 |
17.5% |
12.5% |
3% |
1% |
3 |
14% |
10% |
2% |
1% |
5 |
11% |
7% |
1% |
1% |