Skip to content

Commit

Permalink
bug find in the histogram and checked out for vivx/hist instead
Browse files Browse the repository at this point in the history
  • Loading branch information
lza@arthur committed Jun 13, 2017
1 parent 17afaa8 commit f9ed1dc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Config struct {

//NewConfig gen the config
func newConfig(options ...Options) Config {
c := Config{10, 4, 0, false, 1, 6553500, 15, 1.4, 1000000, 1000}
c := Config{10, 4, 0, false, 1, 6553500, 15, 1.4, 1000000, 1000000}
for _, o := range options {
o(&c)
}
Expand Down
Binary file removed demo/demo
Binary file not shown.
1 change: 1 addition & 0 deletions demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
func main() {

perfm := perfm.New(perfm.WithBinsNumber(15), perfm.WithMinValue(0), perfm.WithGrowthFactor(0.4), perfm.WithBaseBucketSize(20), perfm.WithParallel(5))
//perfm := perfm.New(perfm.WithBinsNumber(15), perfm.WithParallel(5), perfm.WithNumber(100))

perfm.Registe(func() error {
_, err := http.Get("http://www.baidu.com")
Expand Down
41 changes: 21 additions & 20 deletions perfm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"sync/atomic"
"time"

hist "github.com/shafreeck/fperf/stats"
hist "github.com/VividCortex/gohistogram"
//hist "github.com/shafreeck/fperf/stats"
)

//PerfMonitor define the atcion about perfmonitor
Expand Down Expand Up @@ -35,7 +36,7 @@ type perfmonitor struct {
localCount int //count for the number in the sampling times
localTimeCount time.Duration //count for the sampling time total costs
buffer chan int64 //buffer the test time for latter add to the historgam
histogram *hist.Histogram //used to print the histogram
histogram hist.Histogram //used to print the histogram
wg sync.WaitGroup //wait group to block the stop and sync the work thread
job func() error //job for benchmark, requect will be collected if an error occoured, job must be parallel safe
}
Expand All @@ -44,12 +45,12 @@ type perfmonitor struct {
func New(options ...Options) PerfMonitor {
conf := newConfig(options...)

histopt := hist.HistogramOptions{
NumBuckets: conf.BinsNumber,
GrowthFactor: conf.GrowthFactor,
BaseBucketSize: conf.BaseBucketSize,
MinValue: conf.MinValue,
}
//histopt := hist.HistogramOptions{
// NumBuckets: conf.BinsNumber,
// GrowthFactor: conf.GrowthFactor,
// BaseBucketSize: conf.BaseBucketSize,
// MinValue: conf.MinValue,
//}

var p *perfmonitor = &perfmonitor{
done: make(chan int, 0),
Expand All @@ -60,10 +61,11 @@ func New(options ...Options) PerfMonitor {
timer: time.Tick(time.Second * time.Duration(conf.Frequency)),
collector: make(chan time.Duration, conf.BufferSize),
errCollector: make(chan error, conf.BufferSize),
histogram: hist.NewHistogram(histopt),
buffer: make(chan int64, 100000000),
noPrint: conf.NoPrint,
wg: sync.WaitGroup{},
//histogram: hist.NewHistogram(histopt),
histogram: hist.NewHistogram(conf.BinsNumber),
buffer: make(chan int64, 100000000),
noPrint: conf.NoPrint,
wg: sync.WaitGroup{},
}
return p
}
Expand Down Expand Up @@ -99,6 +101,7 @@ func (p *perfmonitor) Start() {
p.localTimeCount = 0
case <-p.done:
localwg.Wait()
fmt.Println("DBG wati for workers")
for {
cost = <-p.collector
p.buffer <- int64(cost)
Expand Down Expand Up @@ -153,6 +156,7 @@ func (p *perfmonitor) Start() {
} else {
// in test duration module
go func() {
fmt.Println("DBG in duration stoper")
p.wg.Done()
time.Sleep(time.Second * time.Duration(p.duration))
close(p.done)
Expand All @@ -167,18 +171,15 @@ func (p *perfmonitor) Wait() {
fmt.Println("DBG BEFORE DRAW", len(p.buffer), p.Total)
for i = 0; i < p.Total; i++ {
d = <-p.buffer
fmt.Println("DBG add", d)
err := p.histogram.Add(d)
if err != nil {
panic(err)
}
//fmt.Println("DBG add", d)
p.histogram.Add(float64(d))
p.Sum += d
sum2 += d * d
}
fmt.Println("DBG after caculate")

fmt.Println("DBG hist", p.histogram.Sum, p.histogram.Count)
p.Sum = p.histogram.Sum
p.Avg = p.Sum / p.Total
p.Stdev = math.Sqrt(float64(sum2) - 2*float64(p.Avg*p.histogram.Sum) + float64(p.histogram.Count*p.Avg*p.Avg)/float64(p.histogram.Count))
p.Stdev = math.Sqrt(float64(sum2) - 2*float64(p.Avg*p.Sum) + float64(p.Total*p.Avg*p.Avg)/float64(p.Total))

// here show the histogram
if !p.noPrint {
Expand Down

0 comments on commit f9ed1dc

Please sign in to comment.