This page describes how to configure the maximum commit (write) delay time to optimize write throughput in Spanner.
Overview
To ensure data consistency, Spanner sends write requests to all voting replicas in the database. This replication process can have computational overhead. For more information, see Replication.
Throughput optimized writes provide the option to amortize these computation costs by executing a group of writes together. To do this, Spanner introduces a small delay and collects a group of writes that need to be sent to the same voting participants. Executing writes in this way can provide substantial throughput improvements at the cost of slightly increased latency.
Default behavior
If you don't set a commit delay time, Spanner might set a small delay for you if it thinks that will amortize the cost of your writes.
Common use cases
You can manually set the delay time of your write requests depending on your application needs. You can also disable commit delays for applications that are highly latency sensitive by setting the maximum commit delay time to 0 ms.
If you have a latency tolerant application and want to optimize throughput, setting a longer commit delay time significantly improves throughput while incurring higher latency for each write. For example, if you are bulk loading a large amount of data and the application doesn't care about how quickly Spanner writes any individual data, then you can set the commit delay time to a longer value like 100 ms. We recommend that you start with a value of 100 ms, and then adjust up and down until the latency and throughput tradeoffs satisfy your needs. For most applications, a value between 20 ms and 100 ms works best.
If you have a latency sensitive application, Spanner's is also latency sensitive by default. If you have a spiky workload, Spanner may set a small delay. You can experiment with setting a value of 0 ms to determine if the reduced latency at the cost of increased throughput is reasonable for your application.
Set mixed commit delay times
You can configure different max commit delay times on subsets of your writes. If you do this, Spanner uses the shortest delay time configured for the set of writes. However, we recommend picking a single value for most use cases as this results in more predictable behavior.
Limitations
You can set a commit delay time between 0 and 500 ms. Setting commit delays higher than 500 ms results in an error.
Set max commit delay on commit requests
The max commit delay parameter is part of the CommitRequest
method. You can access
this method with the RPC API,
REST API,
or using the Cloud Spanner client library.
Go
Node.js
Python
Ruby
Monitor write request latency
You can monitor Spanner CPU utilization and latency using the Google Cloud console. When you set a longer delay time for your write requests, expect to see CPU utilization potentially decrease, while latency increases. To learn about latency in Spanner requests, see Capture and visualize Spanner API request latency.