Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

go - Golang: Testing several times using gobench

I'm working with gobench, wich help us to test a request and have several measures about the performance.

I did a modification for send the url that I need test in each call. But I found that it's not posible call the function twice or more times.

func GobenchMain(currectRoute *string) {
    startTime := time.Now()

    var done sync.WaitGroup
    results := make(map[int]*Result)
...
}

After that I realize that the problem on gobench file is on this part:

signalChannel := make(chan os.Signal, 2)
    signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
    go func() {
        _ = <-signalChannel
        printResults(results, startTime)
        os.Exit(0)
    }()

Finally this is the way that I expect to do the call, and with this make more that one request.

package main

import (
    "fmt"
    "gobench"
)

var searchRoutes = []string{
    "http:www.myurl.com/request1",
    "http:www.myurl.com/request2",
    "http:www.myurl.com/request3",
    "http:www.myurl.com/request4",
}

func main() {
    for i := 0; i < len(searchRoutes); i++ {
        gobench.GobenchMain(&searchRoutes[i])
    }
...
}

How can I call more that one time my GobeachMain? ;Currently with the code like that It's only possible call once, because after gobench get the result goes on os.exit(0), and if I remove this line, the program just goes to stand by

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...