Skip to content
Snippets Groups Projects
Commit 5bd25acc authored by ale's avatar ale
Browse files

properly initialize stats

parent 38dac952
Branches
No related tags found
No related merge requests found
......@@ -13,9 +13,8 @@ import (
)
var (
numConns int
stats = &Stats{}
numConns = flag.Int("n", 3, "number of parallel connections")
stats = NewStats()
retryTime = 2 * time.Second
)
......@@ -26,6 +25,12 @@ type Stats struct {
lock sync.Mutex
}
func NewStats() *Stats {
return &Stats{
HttpStatus: make(map[int]int),
}
}
func (s *Stats) HttpError(resp *http.Response) {
s.lock.Lock()
defer s.lock.Unlock()
......@@ -50,11 +55,6 @@ func (s *Stats) Dump() {
log.Printf("errs=%d http_errs=%d http_status=%v", s.Errors, s.HttpErrors, s.HttpStatus)
}
func init() {
flag.IntVar(&numConns, "n", 3, "number of parallel connections")
flag.IntVar(&numConns, "num-clients", 3, "number of parallel connections")
}
func readstream(id int, streamUrl string) error {
resp, err := http.Get(streamUrl)
if err != nil {
......@@ -135,7 +135,7 @@ func main() {
go dumpStats()
var wg sync.WaitGroup
for i := 0; i < numConns; i++ {
for i := 0; i < *numConns; i++ {
wg.Add(1)
go func(id int) {
worker(id, streamUrl)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment