內部程序是CPU密集型計算,因此編寫了 Benchmark 測試算子的性能,並且希望在此基礎上,將 Benchmark 在各服務器上執行,驗證服務器性能情況。
Benchmark 編譯
go test -c -test.bench=".*" ./filter/
執行後將在本地生成 filter.test
Benchmark 運行
首先在目標服務器上將編譯好的二進制文件拉取到本地。
./teleport.benchmark-v1 -test.bench=".*" -test.cpu=1 -test.count 5
Golang test 參數詳解
Usage of ./filter.test:
-test.bench regexp
run only benchmarks matching regexp
-test.benchmem
print memory allocations for benchmarks
-test.benchtime d
run each benchmark for duration d (default 1s)
-test.blockprofile file
write a goroutine blocking profile to file
-test.blockprofilerate rate
set blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
-test.count n
run tests and benchmarks n times (default 1)
-test.coverprofile file
write a coverage profile to file
-test.cpu list
comma-separated list of cpu counts to run each test with
-test.cpuprofile file
write a cpu profile to file
-test.failfast
do not start new tests after the first test failure
-test.list regexp
list tests, examples, and benchmarks matching regexp then exit
-test.memprofile file
write an allocation profile to file
-test.memprofilerate rate
set memory allocation profiling rate (see runtime.MemProfileRate)
-test.mutexprofile string
write a mutex contention profile to the named file after execution
-test.mutexprofilefraction int
if >= 0, calls runtime.SetMutexProfileFraction() (default 1)
-test.outputdir dir
write profiles to dir
-test.parallel n
run at most n tests in parallel (default 40)
-test.run regexp
run only tests and examples matching regexp
-test.short
run smaller test suite to save time
-test.testlogfile file
write test action log to file (for use only by cmd/go)
-test.timeout d
panic test binary after duration d (default 0, timeout disabled)
-test.trace file
write an execution trace to file
-test.v
verbose: print additional output
參數 | 說明 | 使用案例 |
---|---|---|
test.bench | 指定需要執行的 Benchmark 方法 | -test.bench=“BenchmarkSplit*” |
test.benchmem | Benchchmark 輸出是否包含內存信息 | -test.benchmem |
test.benchtime | 每個 Benchmark 執行的時間 | -test.benchtime=2s |
test.blockprofile | ||
test.blockprofilerate | ||
test.count | 每個 Benchmark 執行的次數 | -test.count=2 |
test.coverprofile | ||
test.cpu | 執行 Benchmark 的CPU個數 | -test.cpu=1 |
test.cpuprofile | 是否輸出cpu性能分析文件 | |
test.failfast | ||
test.list | 列出所有符合條件的測試用例 | |
test.memprofile | 是否輸出內存性能分析文件 | |
test.memprofilerate | ||
test.mutexprofile | ||
test.mutexprofilefraction | ||
test.outputdir | ||
test.parallel | ||
test.run | ||
test.short | ||
test.testlogfile | ||
test.timeout | 測試用例超時時間 | |
test.trace | ||
test.v |