This repository contains example code to accompany the Sequence generation in Cloud Spanner solution paper.
The example code includes performance tests of the different types of sequence generators. These tests require a Cloud Spanner database.
-
Create a Cloud Spanner instance (if required). One node is sufficient for these tests.
-
Create a Cloud Spanner database with the following table definition:
CREATE TABLE sequences ( name STRING(64) NOT NULL, next_value INT64 NOT NULL, ) PRIMARY KEY(name)
-
Insert the following single row into the database:
INSERT INTO sequences (name, next_value) VALUES ('my-sequence', 0);
-
Clone the repository from GitHub
git clone https://github.com/GoogleCloudPlatform/solutions-spanner-sequences.git
-
If running on a Compute Engine VM, ensure that the service account being used has access to the Cloud Spanner API and can read/write to the Cloud Spanner Database.
If running on a development machine ensure that your Application Default Credentials are set to an account that can read/write to the Cloud Spanner database.
See Authentication Overview in Google Cloud documentation for more information. -
Compile and run the performance test
Either: compile and execute using Maven:
mvn compile exec:java \ -Dexec.mainClass=com.google.cloud.solutions.spanner.PerformanceTest \ -Dexec.args="INSTANCE_NAME DATABASE_NAME MODE ITERATIONS THREADS"
Or: build a 'fat' deployable JAR containing all dependencies (for easy copying to a remote machine), and execute the JAR:
mvn package java -jar target/sequence-generator-1.0-SNAPSHOT-jar-with-dependencies.jar \ INSTANCE_NAME DATABASE_NAME MODE ITERATIONS THREADS
where:
- INSTANCE_NAME is your Cloud Spanner instance name
- DATABASE_NAME is the name of your database
- MODE is one of the sequence generator modes: simple, sync, async, batch or asyncbatch. (see the solution document for the definition of these modes)
- ITERATIONS - the number of sequence values to generate
- THREADS - the number of simultaneous threads requesting sequence values