英文:
Benchmarking my Golang webserver
问题
我正在寻找一些工具或Go测试包,以在不同的服务器上运行一些基准测试。你有什么好的方法可以在控制台上获得漂亮的分析输出吗?是否可以模拟多个用户访问服务器?
这是你的测试代码,但没有输出:
package tests
import (
"testing"
)
func BenchmarkMyFunc(b *testing.B) {
for i := 0; i < b.N; i++ {
testplus()
}
}
func testplus() int {
x := 1
return x + 1
}
谢谢。
英文:
I am looking for some tools or the Go tests package to run some benchmarks on different servers. Any idea how i get some nice profiling output in my console. Is it possible to simulate multiple users visiting the server?
getting no output at from this testing code
package tests
import(
"testing"
)
func BenchmarkMyFunc(b *testing.B) {
for i := 0; i < b.N; i++ {
testplus()
}
}
func testplus() int {
x := 1
return x + 1
}
thank you
答案1
得分: 6
使用Go语言内置的性能分析工具,或者使用方便的包装工具:http://dave.cheney.net/2013/07/07/introducing-profile-super-simple-profiling-for-go-programs
...然后使用一个良好的HTTP负载测试工具对应用程序进行压力测试以生成负载:https://github.com/wg/wrk
请注意:
- 性能分析将向您展示实际需要优化的内容,但不要过度优化。
- HTTP负载测试结果仅适用于您的应用程序和机器组合。
- 在许多情况下,您可能会受到网络堆栈配置的限制。
您还可以在测试代码中包含基准测试,注意这些基准测试通常用于算法性能测试/比较方法,而不是整个应用程序的性能。
英文:
Use Go's built-in profiling tools, or convenience wrappers around them: http://dave.cheney.net/2013/07/07/introducing-profile-super-simple-profiling-for-go-programs
... and then hit the application with a decent HTTP load testing tool to generate load: https://github.com/wg/wrk
Note that:
- Profiling will show you what to actually optimize, but don't go overboard.
- HTTP load testing results are only applicable to your application and machine combination
- In many cases, you may be restricted by your networking stack configuration.
You can also include benchmarks in your test code, noting that these are typically useful for benchmarking algorithms/comparing approaches rather than whole-of-application performance.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论