initial benchmarks. warning: /0 bug

This commit is contained in:
Jimmy Zelinskie 2016-08-11 18:15:47 -04:00
parent c3137508d0
commit 651ed50957
2 changed files with 313 additions and 135 deletions

View file

@ -1,142 +1,32 @@
// Copyright 2016 The Chihaya Authors. All rights reserved.
// Use of this source code is governed by the BSD 2-Clause license,
// which can be found in the LICENSE file.
package memory
import (
"testing"
"github.com/chihaya/chihaya/server/store"
s "github.com/jzelinskie/trakr/storage"
)
var (
peerStoreTester = store.PreparePeerStoreTester(&peerStoreDriver{})
peerStoreBenchmarker = store.PreparePeerStoreBenchmarker(&peerStoreDriver{})
peerStoreTestConfig = &store.DriverConfig{}
)
func init() {
unmarshalledConfig := struct {
Shards int
}{
1,
}
peerStoreTestConfig.Config = unmarshalledConfig
}
func TestPeerStore(t *testing.T) {
peerStoreTester.TestPeerStore(t, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutSeeder(b *testing.B) {
peerStoreBenchmarker.PutSeeder(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutSeeder1KInfohash(b *testing.B) {
peerStoreBenchmarker.PutSeeder1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutSeeder1KSeeders(b *testing.B) {
peerStoreBenchmarker.PutSeeder1KSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutSeeder1KInfohash1KSeeders(b *testing.B) {
peerStoreBenchmarker.PutSeeder1KInfohash1KSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutDeleteSeeder(b *testing.B) {
peerStoreBenchmarker.PutDeleteSeeder(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutDeleteSeeder1KInfohash(b *testing.B) {
peerStoreBenchmarker.PutDeleteSeeder1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutDeleteSeeder1KSeeders(b *testing.B) {
peerStoreBenchmarker.PutDeleteSeeder1KSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutDeleteSeeder1KInfohash1KSeeders(b *testing.B) {
peerStoreBenchmarker.PutDeleteSeeder1KInfohash1KSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_DeleteSeederNonExist(b *testing.B) {
peerStoreBenchmarker.DeleteSeederNonExist(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_DeleteSeederNonExist1KInfohash(b *testing.B) {
peerStoreBenchmarker.DeleteSeederNonExist1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_DeleteSeederNonExist1KSeeders(b *testing.B) {
peerStoreBenchmarker.DeleteSeederNonExist1KSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_DeleteSeederNonExist1KInfohash1KSeeders(b *testing.B) {
peerStoreBenchmarker.DeleteSeederNonExist1KInfohash1KSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutGraduateDeleteLeecher(b *testing.B) {
peerStoreBenchmarker.PutGraduateDeleteLeecher(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutGraduateDeleteLeecher1KInfohash(b *testing.B) {
peerStoreBenchmarker.PutGraduateDeleteLeecher1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutGraduateDeleteLeecher1KSeeders(b *testing.B) {
peerStoreBenchmarker.PutGraduateDeleteLeecher1KLeechers(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_PutGraduateDeleteLeecher1KInfohash1KSeeders(b *testing.B) {
peerStoreBenchmarker.PutGraduateDeleteLeecher1KInfohash1KLeechers(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_GraduateLeecherNonExist(b *testing.B) {
peerStoreBenchmarker.GraduateLeecherNonExist(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_GraduateLeecherNonExist1KInfohash(b *testing.B) {
peerStoreBenchmarker.GraduateLeecherNonExist1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_GraduateLeecherNonExist1KSeeders(b *testing.B) {
peerStoreBenchmarker.GraduateLeecherNonExist1KLeechers(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_GraduateLeecherNonExist1KInfohash1KSeeders(b *testing.B) {
peerStoreBenchmarker.GraduateLeecherNonExist1KInfohash1KLeechers(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_AnnouncePeers(b *testing.B) {
peerStoreBenchmarker.AnnouncePeers(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_AnnouncePeers1KInfohash(b *testing.B) {
peerStoreBenchmarker.AnnouncePeers1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_AnnouncePeersSeeder(b *testing.B) {
peerStoreBenchmarker.AnnouncePeersSeeder(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_AnnouncePeersSeeder1KInfohash(b *testing.B) {
peerStoreBenchmarker.AnnouncePeersSeeder1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_GetSeeders(b *testing.B) {
peerStoreBenchmarker.GetSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_GetSeeders1KInfohash(b *testing.B) {
peerStoreBenchmarker.GetSeeders1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_NumSeeders(b *testing.B) {
peerStoreBenchmarker.NumSeeders(b, peerStoreTestConfig)
}
func BenchmarkPeerStore_NumSeeders1KInfohash(b *testing.B) {
peerStoreBenchmarker.NumSeeders1KInfohash(b, peerStoreTestConfig)
}
func BenchmarkPut(b *testing.B) { s.Put(b, &peerStore{}) }
func BenchmarkPut1k(b *testing.B) { s.Put1k(b, &peerStore{}) }
func BenchmarkPut1kInfohash(b *testing.B) { s.Put1kInfohash(b, &peerStore{}) }
func BenchmarkPut1kInfohash1k(b *testing.B) { s.Put1kInfohash1k(b, &peerStore{}) }
func BenchmarkPutDelete(b *testing.B) { s.PutDelete(b, &peerStore{}) }
func BenchmarkPutDelete1k(b *testing.B) { s.PutDelete1k(b, &peerStore{}) }
func BenchmarkPutDelete1kInfohash(b *testing.B) { s.PutDelete1kInfohash(b, &peerStore{}) }
func BenchmarkPutDelete1kInfohash1k(b *testing.B) { s.PutDelete1kInfohash1k(b, &peerStore{}) }
func BenchmarkDeleteNonexist(b *testing.B) { s.DeleteNonexist(b, &peerStore{}) }
func BenchmarkDeleteNonexist1k(b *testing.B) { s.DeleteNonexist1k(b, &peerStore{}) }
func BenchmarkDeleteNonexist1kInfohash(b *testing.B) { s.DeleteNonexist1kInfohash(b, &peerStore{}) }
func BenchmarkDeleteNonexist1kInfohash1k(b *testing.B) { s.DeleteNonexist1kInfohash1k(b, &peerStore{}) }
func BenchmarkGradDelete(b *testing.B) { s.GradDelete(b, &peerStore{}) }
func BenchmarkGradDelete1k(b *testing.B) { s.GradDelete1k(b, &peerStore{}) }
func BenchmarkGradDelete1kInfohash(b *testing.B) { s.GradDelete1kInfohash(b, &peerStore{}) }
func BenchmarkGradDelete1kInfohash1k(b *testing.B) { s.GradDelete1kInfohash1k(b, &peerStore{}) }
func BenchmarkGradNonexist(b *testing.B) { s.GradNonexist(b, &peerStore{}) }
func BenchmarkGradNonexist1k(b *testing.B) { s.GradNonexist1k(b, &peerStore{}) }
func BenchmarkGradNonexist1kInfohash(b *testing.B) { s.GradNonexist1kInfohash(b, &peerStore{}) }
func BenchmarkGradNonexist1kInfohash1k(b *testing.B) { s.GradNonexist1kInfohash1k(b, &peerStore{}) }
func BenchmarkAnnounceLeecher(b *testing.B) { s.AnnounceLeecher(b, &peerStore{}) }
func BenchmarkAnnounceLeecher1kInfohash(b *testing.B) { s.AnnounceLeecher1kInfohash(b, &peerStore{}) }
func BenchmarkAnnounceSeeder(b *testing.B) { s.AnnounceSeeder(b, &peerStore{}) }
func BenchmarkAnnounceSeeder1kInfohash(b *testing.B) { s.AnnounceSeeder1kInfohash(b, &peerStore{}) }

288
storage/storage_bench.go Normal file
View file

@ -0,0 +1,288 @@
package storage
import (
"fmt"
"net"
"testing"
"github.com/jzelinskie/trakr/bittorrent"
)
type benchData struct {
infohashes [1000]bittorrent.InfoHash
peers [1000]bittorrent.Peer
}
func generateInfohashes() (a [1000]bittorrent.InfoHash) {
b := make([]byte, 2)
for i := range a {
b[0] = byte(i)
b[1] = byte(i >> 8)
a[i] = bittorrent.InfoHash([20]byte{b[0], b[1]})
}
return
}
func generatePeers() (a [1000]bittorrent.Peer) {
b := make([]byte, 2)
for i := range a {
b[0] = byte(i)
b[1] = byte(i >> 8)
a[i] = bittorrent.Peer{
ID: bittorrent.PeerID([20]byte{b[0], b[1]}),
IP: net.ParseIP(fmt.Sprintf("64.%d.%d.64", b[0], b[1])),
Port: uint16(i),
}
}
return
}
type executionFunc func(int, PeerStore, *benchData) error
type setupFunc func(PeerStore, *benchData) error
func runBenchmark(b *testing.B, ps PeerStore, sf setupFunc, ef executionFunc) {
bd := &benchData{generateInfohashes(), generatePeers()}
if sf != nil {
err := sf(ps, bd)
if err != nil {
b.Fatal(err)
}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := ef(i, ps, bd)
if err != nil {
b.Fatal(err)
}
}
b.StopTimer()
}
func Put(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.PutSeeder(bd.infohashes[0], bd.peers[0])
})
}
func Put1k(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.PutSeeder(bd.infohashes[0], bd.peers[i%1000])
})
}
func Put1kInfohash(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.PutSeeder(bd.infohashes[i%1000], bd.peers[0])
})
}
func Put1kInfohash1k(b *testing.B, ps PeerStore) {
j := 0
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutSeeder(bd.infohashes[i%1000], bd.peers[j%1000])
j += 3
return err
})
}
func PutDelete(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutSeeder(bd.infohashes[0], bd.peers[0])
if err != nil {
return err
}
return ps.DeleteSeeder(bd.infohashes[0], bd.peers[0])
})
}
func PutDelete1k(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutSeeder(bd.infohashes[0], bd.peers[i%1000])
if err != nil {
return err
}
return ps.DeleteSeeder(bd.infohashes[0], bd.peers[i%1000])
})
}
func PutDelete1kInfohash(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutSeeder(bd.infohashes[i%1000], bd.peers[0])
if err != nil {
}
return ps.DeleteSeeder(bd.infohashes[i%1000], bd.peers[0])
})
}
func PutDelete1kInfohash1k(b *testing.B, ps PeerStore) {
j := 0
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutSeeder(bd.infohashes[i%1000], bd.peers[j%1000])
if err != nil {
return err
}
err = ps.DeleteSeeder(bd.infohashes[i%1000], bd.peers[j%1000])
j += 3
return err
})
}
func DeleteNonexist(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.DeleteSeeder(bd.infohashes[0], bd.peers[0])
})
}
func DeleteNonexist1k(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.DeleteSeeder(bd.infohashes[0], bd.peers[i%1000])
})
}
func DeleteNonexist1kInfohash(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.DeleteSeeder(bd.infohashes[i%1000], bd.peers[0])
})
}
func DeleteNonexist1kInfohash1k(b *testing.B, ps PeerStore) {
j := 0
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.DeleteSeeder(bd.infohashes[i%1000], bd.peers[j%1000])
j += 3
return err
})
}
func GradNonexist(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.GraduateLeecher(bd.infohashes[0], bd.peers[0])
})
}
func GradNonexist1k(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.GraduateLeecher(bd.infohashes[0], bd.peers[i%1000])
})
}
func GradNonexist1kInfohash(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
return ps.GraduateLeecher(bd.infohashes[i%1000], bd.peers[0])
})
}
func GradNonexist1kInfohash1k(b *testing.B, ps PeerStore) {
j := 0
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.GraduateLeecher(bd.infohashes[i%1000], bd.peers[j%1000])
j += 3
return err
})
}
func GradDelete(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutLeecher(bd.infohashes[0], bd.peers[0])
if err != nil {
return err
}
err = ps.GraduateLeecher(bd.infohashes[0], bd.peers[0])
if err != nil {
return err
}
return ps.DeleteSeeder(bd.infohashes[0], bd.peers[0])
})
}
func GradDelete1k(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutLeecher(bd.infohashes[0], bd.peers[i%1000])
if err != nil {
return err
}
err = ps.GraduateLeecher(bd.infohashes[0], bd.peers[i%1000])
if err != nil {
return err
}
return ps.DeleteSeeder(bd.infohashes[0], bd.peers[i%1000])
})
}
func GradDelete1kInfohash(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutLeecher(bd.infohashes[i%1000], bd.peers[0])
if err != nil {
return err
}
err = ps.GraduateLeecher(bd.infohashes[i%1000], bd.peers[0])
if err != nil {
return err
}
return ps.DeleteSeeder(bd.infohashes[i%1000], bd.peers[0])
})
}
func GradDelete1kInfohash1k(b *testing.B, ps PeerStore) {
j := 0
runBenchmark(b, ps, nil, func(i int, ps PeerStore, bd *benchData) error {
err := ps.PutLeecher(bd.infohashes[i%1000], bd.peers[j%1000])
if err != nil {
return err
}
err = ps.GraduateLeecher(bd.infohashes[i%1000], bd.peers[j%1000])
if err != nil {
return err
}
err = ps.DeleteSeeder(bd.infohashes[i%1000], bd.peers[j%1000])
j += 3
return err
})
}
func generateAnnounceData(ps PeerStore, bd *benchData) error {
for i := 0; i < 1000; i++ {
for j := 0; j < 1000; j++ {
var err error
if j < 1000/2 {
err = ps.PutLeecher(bd.infohashes[i], bd.peers[j])
} else {
err = ps.PutSeeder(bd.infohashes[i], bd.peers[j])
}
if err != nil {
return err
}
}
}
return nil
}
func AnnounceLeecher(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, generateAnnounceData, func(i int, ps PeerStore, bd *benchData) error {
_, err := ps.AnnouncePeers(bd.infohashes[0], false, 50, bd.peers[0])
return err
})
}
func AnnounceLeecher1kInfohash(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, generateAnnounceData, func(i int, ps PeerStore, bd *benchData) error {
_, err := ps.AnnouncePeers(bd.infohashes[i%1000], false, 50, bd.peers[0])
return err
})
}
func AnnounceSeeder(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, generateAnnounceData, func(i int, ps PeerStore, bd *benchData) error {
_, err := ps.AnnouncePeers(bd.infohashes[0], true, 50, bd.peers[0])
return err
})
}
func AnnounceSeeder1kInfohash(b *testing.B, ps PeerStore) {
runBenchmark(b, ps, generateAnnounceData, func(i int, ps PeerStore, bd *benchData) error {
_, err := ps.AnnouncePeers(bd.infohashes[i%1000], true, 50, bd.peers[0])
return err
})
}