diff options
author | Christian Pointner <equinox@spreadspace.org> | 2017-04-22 01:24:40 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2017-04-22 01:24:40 +0200 |
commit | edfa8ee1607681bcf3d6c175c950264de5c8e2d6 (patch) | |
tree | 50f19ad847d23c3cf1abd6055bfaea62e75a12b2 /src | |
parent | make hostname last url element for piwik forwarding (diff) |
added store benchmarking
Diffstat (limited to 'src')
-rw-r--r-- | src/hub/Makefile | 7 | ||||
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store_test.go | 94 |
2 files changed, 97 insertions, 4 deletions
diff --git a/src/hub/Makefile b/src/hub/Makefile index 9868708..26a3fce 100644 --- a/src/hub/Makefile +++ b/src/hub/Makefile @@ -35,8 +35,6 @@ GOCMD := GOPATH=$(curdir) go ifdef GOROOT GOCMD := GOPATH=$(curdir) $(GOROOT)/bin/go endif -#TESTFLAG := -test.v -TESTFLAG := EXECUTEABLE := sfive-hub @@ -79,8 +77,11 @@ build: getlibs test: getlibs @echo "testing: sfive" - @$(GOCMD) test $(TESTFLAG) spreadspace.org/sfive + @$(GOCMD) test spreadspace.org/sfive +bench: getlibs + @echo "testing and benchmarking: sfive" + @$(GOCMD) test -bench=. spreadspace.org/sfive clean: rm -rf pkg/*/spreadspace.org diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go index 72ef930..409bd08 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go @@ -82,10 +82,102 @@ func TestGetUpdatesAfter(t *testing.T) { err = store.Append(dat) if err != nil { - t.Errorf("Failed to append: %v", err) + t.Errorf("Failed to retrieve: %v", err) return } res, err := store.GetUpdatesAfter(2) t.Logf("got updates (err %v):\n%#v", err, res) } + +func generateStatisticsData(n int) (data []StatisticsData) { + hostnames := []string{"streamer1", "streamer2"} + contents := []string{"av", "audio"} + formats := []string{"webm", "flash", "hls"} + qualities := []string{"high", "medium", "low"} + + numcombis := len(hostnames) * len(contents) * len(formats) * len(qualities) + + clients := []ClientData{ + ClientData{"127.0.0.1", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0", 6400}, + ClientData{"10.12.0.1", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/57.0.2987.98 Chrome/57.0.2987.98 Safari/537.36", 6400}, + ClientData{"127.0.0.1", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0", 6400}, + ClientData{"192.168.0.1", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/57.0.2987.98 Chrome/57.0.2987.98 Safari/537.36", 6400}, + ClientData{"172.16.0.2", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/57.0.2987.98 Chrome/57.0.2987.98 Safari/537.36", 6400}} + starttime := time.Now() + duration := int64(15000) + tags := []string{"2017", "elevate", "discourse"} + + for i := 0; i < n; i += numcombis { + for _, hostname := range hostnames { + for _, content := range contents { + for _, format := range formats { + for _, quality := range qualities { + d := StatisticsData{} + d.SourceId.Version = 1 + d.SourceId.Hostname = hostname + d.SourceId.Tags = tags + + d.SourceId.StreamId.ContentId = content + d.SourceId.StreamId.Format = format + d.SourceId.StreamId.Quality = quality + + d.DataUpdate.StartTime = starttime + d.DataUpdate.Duration = duration + d.DataUpdate.Data.ClientCount = uint(len(clients)) + d.DataUpdate.Data.BytesSent = 6400 * uint(len(clients)) + + for _, client := range clients { + c := ClientData{client.Ip, client.UserAgent, client.BytesSent} + d.DataUpdate.Data.Clients = append(d.DataUpdate.Data.Clients, c) + } + data = append(data, d) + } + } + } + } + starttime = starttime.Add(time.Duration(duration) * time.Millisecond) + } + return +} + +func BenchmarkAppendMany(b *testing.B) { + store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared") + if err != nil { + b.Errorf("Failed to initialize: %v", err) + } + defer store.Close() + data := generateStatisticsData(b.N) + + b.ResetTimer() + + if err := store.AppendMany(data); err != nil { + b.Errorf("Failed to append: %v", err) + } +} + +func BenchmarkGetUpdatesAfter(b *testing.B) { + store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared") + if err != nil { + b.Errorf("Failed to initialize: %v", err) + } + defer store.Close() + data := generateStatisticsData(b.N) + if err := store.AppendMany(data); err != nil { + b.Errorf("Failed to append: %v", err) + } + + b.ResetTimer() + + latestId := -1 + for { + updates, err := store.GetUpdatesAfter(latestId) + if err != nil { + b.Errorf("Failed to retrieve: %v", err) + } + if len(updates) == 0 { + break + } + latestId = findMaxId(updates) + } +} |