我正在通过编写一个简单的Redis克隆来练习Golang.
I am practicing my Golang by writing a simple Redis clone.
我该如何编写一个基准脚本,以C并发级别每秒建立X个连接,以处理服务器协议并测量每秒操作数?
How do i write a benchmark script that would establish X connections per second at C concurrency level to deal with my server's protocol and measure how many ops/sec?
我可以简单地编写一个可以实际执行此操作的脚本:
I can simply write a script that would actually do this:
for i := range(1000) { // Open connection // Perform command // Close connection }但是我想知道每秒分发每个并发级别的连接数的概念.
But i want to know the concept behind distributing the number of connections per concurrency level per second.
推荐答案最好由内置的 testing.Benchmark 系统.例如,像这样的测试用例:
This is best handled by the built-in testing.Benchmark system. For example, a test case like:
func BenchmarkHello(b *testing.B) { for i := 0; i < b.N; i++ { fmt.Sprintf("hello") } }将自动计算此功能的时序计算.有关设置的更多详细信息,请参见软件包文档,但是如果您之前编写过Go测试用例,应该会非常熟悉.
will automatically work out timing calculations for this function. See the package documentation for more details on setting it up, but it should be very familiar if you've written Go test cases before.
对于有关并发基准测试的问题,请参见RunParallel帮助器,该帮助器专门用于此目的.
To your question about concurrency benchmarking, see the RunParallel helper, which is specifically to assist in this.
更多推荐
如何在Go中编写基准测试脚本以衡量运营/秒
发布评论