# Benchmark Demo
This demo helps you setup a TiDB cluster and do benchmark tests. You will be able to spin up a TiDB cluster with one command, with the spec you define, and then run benchmark tests such as sysbench, tpcc and tpch.

# Instructions
## 1. Spin up TiDB cluster
Follow the commands below to spin up test cluster
```bash
# go to the tiup tool directory
cd tisample/tidb-demo-aws/tiup
# init terraform
terraform init
# run terraform commands to spin up AWS resources
terraform apply -var "jump_instance_type=c5.9xlarge" \
-var "pd_instance_type=m5.xlarge" \
-var "pd_instance_number=3" \
-var "tidb_instance_type=c5.4xlarge" \
-var "tidb_instance_number=3" \
-var "tikv_instance_type=r5.4xlarge" \
-var "tikv_instance_number=3" \
-var "tikv_instance_disk_size=500" \
-var "tikv_ebs_iops=4000" \
-var "tikv_ebs_throughput=800" \
-var "tiup_config_path=demos/benchmark/files/deploy-5.1.yml.template" \
-var "region=ap-southeast-1"
```
You are able to config tiup resrouces such as instance type, number of instances etc. when running `terraform apply`, for more details, please go to [advanced configuration](../../tiup/README.md#Advanced-configurations)


## 2. SSH to the jump server
You should see similar results as below after successfully applied the terraform
```bash
Apply complete! Resources: 127 added, 0 changed, 0 destroyed.

Outputs:

jump_ssh_login = "ssh -i ~/.ssh/tidb_demo centos@54.254.7.252"
mysql_command = "mysql -h tidb-lb-d38b8b313db96d5f.elb.ap-southeast-1.amazonaws.com -P 4000 -u root"
tidb_dashboard_url = "http://ec2-13-229-130-6.ap-southeast-1.compute.amazonaws.com:2379/dashboard"
tidb_grafana_url = "http://ec2-13-229-130-6.ap-southeast-1.compute.amazonaws.com:3000"
```
Use jump_ssh_login to SSH to the jump server 
```bash
# login to jump server
ssh -i ~/.ssh/tidb_demo centos@54.254.7.252
```

## 3. Run tests
### 3.1 TPCC (Optional)
1. Run script
```bash
cd
screen bash -c ". demos/benchmark/files/tpcc.sh"
```
- Note1: Feel free to tweak tpcc.sh, otherwise you can explore the commands manually. 
- Note2: If you use the default settings, it will take around 1 hour to load the test data, and another 30 mins to run the benchmark.

2. Check test result
```bash
cat tpcc_result
```


### 3.2 Sysbench (Optional)
1. Run script
```bash
cd
screen bash -c ". demos/benchmark/files/sysbench.sh"
```
- Note1: Feel free to tweak sysbench.sh, otherwise you can explore the commands manually. 
- Note2: If you use the default settings, it will take around 1.5 hours to load the test data, and another 1.5 hours to run the benchmark.

2. Check test result
```bash
cat sysbench_result
```

## 4. Cleanup
```bash
# go back to the local machine and cd to tiup(tisample/tidb-demo-aws/tiup) dir
terraform destroy
```
