Warm up the database before application launch

Before launching an application, we recommend that you warm up your database using test data loads to take advantage of Spanner's parallelization features.

Spanner is a distributed database, which means that as your database grows, Spanner divides the key space of your data into chunks called splits. Each split is a range of rows that contains a subset of your table. As Spanner splits data based on load and size, it dynamically moves individual splits independently of each other and assigns the splits to different server resources to balance the overall load on the database.

When you initially insert data into an empty database, Spanner writes the data to a single split. The database is still in a "cold" state. As you insert more data, Spanner starts to split that data to rebalance the load across other available server resources. Now Spanner is in a "warm" state with splits across available server resources to maximize parallelism and improve performance.

As a best practice, we recommend that you launch your application when Spanner is in a warm state with splits already created and balanced across server resources. In order to warm up your database and prepare your test data loads, follow these steps:

  1. Make sure that the primary keys you generate for your test data loads are in the same key space and have the same distribution properties as the keys you are using for production traffic.
  2. Run a load test no more than two days before your launch. Run the load test for at least one hour at the expected peak load. The load test causes Spanner to create more splits due to load-based splitting.
  3. After the load test is complete, you can delete the rows generated by your load test from your tables, but don't delete the tables themselves. This keeps the splits available for your launch window.