Installation notes
######Tasks
a
b
c
d
e
f
g
b) It varies from time to time, but sometimes I see that when NRK gets more viewers, TV 2 gets less viewers and vice versa.
c)
1. ``` go go computeViewers("NRK1", ztorage.Zapper(sliceZaps)) ``` 2. ``` go go computeViewers("TV2 Norge", ztorage.Zapper(sliceZaps)) ```
func computeViewers(chName string, z ztorage.Zapper) {
for _ = range time.Tick(1 * time.Second) {
numberOfViewers := z.ComputeViewers(chName)
fmt.Printf("%s: %d\n", chName, numberOfViewers)
}
}
In slize.go
func (zs *SliceZaps) ComputeZaps() int {
return len(*zs)
}
In zapserver.go
func computeZaps(z ztorage.Zapper) {
for _ = range time.Tick(5 * time.Second) {
fmt.Printf("Total number of zaps: %d\n", z.ComputeZaps())
}
}
4.
(pprof) top10 - Total amount 15.3 MB
We have allocated over 15 MB of memory in 10 minutes. This will grow
indefinetely until our application will crash.
10.8 | 70.5% | 70.5% | 10.8 | 70.5% | cnew |
4.0 | 26.2% | 96.7% | 14.8 | 96.7% | main.handleClient |
0.5 | 3.3% | 100% | 0.5 | 3.3% | unicode.init |
0.0 | 0.0% | 100% | 0.5 | 3.3% | bytes.init |
0.0 | 0.0% | 100% | 1.0 | 6.6% | github.com/zaplab/chzap.NewChZap |
0.0 | 0.0% | 100% | 15.3 | 100% | gosched() |
0.0 | 0.0% | 100% | 0.5 | 3.3% | main.init |
0.0 | 0.0% | 100% | 1.0 | 6.6% | net.ParseIP |
5.
The slice based storage will never stop growing. We should consider using
another data structure to keep control of zap events.
You can find the Top10 function in ztorage/ztoragesort.go ``` go func (zs *SliceZaps) TopTenChannels() []string { top10 := make(map[string]int)
for _, v := range *zs {
if _, ok := top10[v.ToChan]; !ok {
top10[v.ToChan] = zs.ComputeViewers(v.ToChan)
}
}
return Top10(top10)
}
<a name="e"/>
e) [ztorage.go](https://github.com/sandves/zaplab/blob/master/ztorage/ztorage.go) <br>
<a name="f"/>
f) [zapserver.go](https://github.com/sandves/zaplab/blob/master/zapserver/zapserver.go) <br>
1. I would say that the access pattern is write-heavy because we constanly write zap events. We also perform reads, but this occurs less frequently. Consequences of a write-heavy access pattern is a greater chance of reading incorrect values from the data structure. <br>
2. We could protect the zap map with a lock to avoid returning incorrect statistics. <br>
<a name="g"/>
g) <br>
``` go
func (zs Zaps) AverageZapDuration() time.Duration {
if totalZapEvents != 0 {
return (totalZapDuration) / (time.Duration(totalZapEvents))
} else {
return time.Duration(0)
}
}
See details in
ztorage.go