Skip to content

Commit

Permalink
tools: api bench (tikv#5706)
Browse files Browse the repository at this point in the history
close tikv#6922

Signed-off-by: Cabinfever_B <[email protected]>
  • Loading branch information
CabinfeverB authored Aug 14, 2023
1 parent 557d72f commit 67a51b7
Show file tree
Hide file tree
Showing 7 changed files with 1,489 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ BUILD_BIN_PATH := $(ROOT_PATH)/bin

build: pd-server pd-ctl pd-recover

tools: pd-tso-bench pd-heartbeat-bench regions-dump stores-dump
tools: pd-tso-bench pd-heartbeat-bench regions-dump stores-dump pd-api-bench

PD_SERVER_DEP :=
ifeq ($(SWAGGER), 1)
Expand All @@ -84,6 +84,8 @@ pd-ctl:
CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/pd-ctl tools/pd-ctl/main.go
pd-tso-bench:
cd tools/pd-tso-bench && CGO_ENABLED=0 go build -o $(BUILD_BIN_PATH)/pd-tso-bench main.go
pd-api-bench:
cd tools/pd-api-bench && CGO_ENABLED=0 go build -o $(BUILD_BIN_PATH)/pd-api-bench main.go
pd-recover:
CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/pd-recover tools/pd-recover/main.go
pd-analysis:
Expand All @@ -97,7 +99,7 @@ regions-dump:
stores-dump:
CGO_ENABLED=0 go build -gcflags '$(GCFLAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_BIN_PATH)/stores-dump tools/stores-dump/main.go

.PHONY: pd-ctl pd-tso-bench pd-recover pd-analysis pd-heartbeat-bench simulator regions-dump stores-dump
.PHONY: pd-ctl pd-tso-bench pd-recover pd-analysis pd-heartbeat-bench simulator regions-dump stores-dump pd-api-bench

#### Docker image ####

Expand Down Expand Up @@ -275,4 +277,4 @@ clean-build:
rm -rf $(BUILD_BIN_PATH)
rm -rf $(GO_TOOLS_BIN_PATH)

.PHONY: clean clean-test clean-build
.PHONY: clean clean-test clean-build
77 changes: 77 additions & 0 deletions tools/pd-api-bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pd-api-bench
========

pd-api-bench is a tool to test PD API.

## Build
1. [Go](https://golang.org/) Version 1.21 or later
2. In the root directory of the [PD project](https://github.com/tikv/pd), use the `make pd-api-bench` command to compile and generate `bin/pd-api-bench`


## Usage

This section describes how to use the `pd-api-bench` tool.

### Cases

The api bench cases we support are as follows:
1. HTTP
+ GetRegionStatus: /pd/api/v1/stats/region
+ GetMinResolvedTS: /pd/api/v1/min-resolved-ts

2. gRPC
+ GetRegion
+ GetStore
+ GetStores
+ ScanRegions

### Flags description

-cacert string
> path of file that contains list of trusted SSL CAs
-cert string
> path of file that contains X509 certificate in PEM format
-key string
> path of file that contains X509 key in PEM format
-client int
> the client number (default 1)
-pd string
> pd address (default "127.0.0.1:2379")
-http-cases
> HTTP api bench cases list. Multiple cases are separated by commas. Such as `-http-cases GetRegionStatus,GetMinResolvedTS`
> You can set qps with '-' and set burst with '+' such as `-http-cases GetRegionStatus-100+1`
-grpc-cases
> gRPC api bench cases list. Multiple cases are separated by commas. Such as `-grpc-cases GetRegion`
> You can set qps with '-' and set burst with '+' such as `-grpc-cases GetRegion-1000000+10`
-qps
> the qps of request (default 1000). It will set qps for all cases except those in which qps is specified separately
-burst
> the burst of request (default 1). It will set burst for all cases except those in which burst is specified separately
-debug
> print the output of api response for debug
You can run shell as follows.
```shell
go run main.go -http-cases GetRegionStatus-1+1,GetMinResolvedTS-1+1 -client 1 -debug
```

### TLS

You can use the following command to generate a certificate for testing TLS:

```shell
mkdir cert
./cert_opt.sh generate cert
go run main.go -http-cases GetRegionStatus-1+1,GetMinResolvedTS-1+1 -client 1 -debug -cacert ./cert/ca.pem -cert ./cert/pd-server.pem -key ./cert/pd-server-key.pem
./cert_opt.sh cleanup cert
rm -rf cert
```
Loading

0 comments on commit 67a51b7

Please sign in to comment.