Giter VIP home page Giter VIP logo

zaplab's Introduction

Lab 5: Processing channel zaps

Table of Contents

Installation notes
######Tasks
a
b
c
d
e
f
g

### Installation notes Navigate to the directory you want to install zaplab, and follow these instructions: ``` bash export GOPATH=`pwd` go get github.com/sandves/zaplab go install github.com/sandves/zaplab/zapserver go install github.com/sandves/zaplab/zapclient ``` Run each task using the task flag: ``` bash cd bin #this is where the compiled program is located ./zapserver -task=a # task must be a-f ``` For task f and g: ``` bash # run server in background ./zapserver -task=f & # or ./zapserver -task=g & # then you can start the client ./zapclient ``` If you want to write a memory profile, use the `-memprofile` flag, and specify a file name: ``` bash # the memory profile will be written when you terminate the server by pressing `Ctrl + c` ./zapserver -memprofile=mem.prof ``` a) The number will sometimes be negative, but that is because we do not initially know how many viewers the channel has when we start listening for zaps.
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.

d)
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

zaplab's People

Contributors

sandves avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.