go/main_test.go: adding new test to compare databases performance
This commit is contained in:
parent
a65882529d
commit
a8529c7b49
|
@ -1,9 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
"strconv"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
|
||||
|
@ -20,6 +22,14 @@ var nodeList = []string{
|
|||
|
||||
// If using vscode, go to Preferences > Settings, and edit Go: Test Timeout to at least 60s
|
||||
|
||||
func parseTime(s string) (time.Time) {
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return time.Unix(i, 0)
|
||||
}
|
||||
|
||||
func (s *StoreSuite) TestBasic() {
|
||||
numMsgToSend := 100
|
||||
pubsubTopic := relay.DefaultWakuTopic
|
||||
|
@ -66,3 +76,66 @@ func (s *StoreSuite) TestBasic() {
|
|||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func (s *StoreSuite) TestCompareDatabasesPerformance() {
|
||||
// The next settings might be to be adapted depending on the databases content.
|
||||
// We seek to pick times windows so that the number of returned rows is ~1000.
|
||||
expectedNumMsgs := 966
|
||||
pubsubTopic := "/waku/2/default-waku/proto"
|
||||
startTime := parseTime("1695992040")
|
||||
endTime := parseTime("1695992056")
|
||||
contentTopic := "/waku/2/default-content/proto"
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) // Test shouldnt take more than 60s
|
||||
defer cancel()
|
||||
|
||||
// Connecting to nodes
|
||||
// ================================================================
|
||||
|
||||
log.Info("Connecting to nodes...")
|
||||
|
||||
connectToNodes(ctx, s.node)
|
||||
|
||||
time.Sleep(2 * time.Second) // Required so Identify protocol is executed
|
||||
|
||||
// Store
|
||||
// ================================================================
|
||||
|
||||
timeSpentMap := make(map[string]time.Duration)
|
||||
numUsers := int64(10)
|
||||
|
||||
peers := []string{
|
||||
// Postgres peer
|
||||
"/ip4/127.0.0.1/tcp/30303/p2p/16Uiu2HAmJyLCRhiErTRFcW5GKPrpoMjGbbWdFMx4GCUnnhmxeYhd",
|
||||
// SQLite peer
|
||||
"/ip4/127.0.0.1/tcp/30304/p2p/16Uiu2HAkxj3WzLiqBximSaHc8wV9Co87GyRGRYLVGsHZrzi3TL5W",
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
for _, addr := range peers {
|
||||
for userIndex := 0; userIndex < int(numUsers); userIndex++ {
|
||||
wg.Add(1)
|
||||
go func(addr string) {
|
||||
defer wg.Done()
|
||||
fmt.Println("Querying node", addr)
|
||||
start := time.Now()
|
||||
cnt, err := queryNode(ctx, s.node, addr, pubsubTopic, contentTopic, startTime, endTime)
|
||||
timeSpent := time.Since(start)
|
||||
fmt.Printf("\n%s took %v\n\n", addr, timeSpent)
|
||||
s.NoError(err)
|
||||
s.Equal(expectedNumMsgs, cnt)
|
||||
timeSpentMap[addr] += timeSpent
|
||||
}(addr)
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
timeSpentNanos := timeSpentMap[peers[0]].Nanoseconds() / numUsers
|
||||
fmt.Println("\n\nAverage time spent: ", peers[0], time.Duration(timeSpentNanos))
|
||||
|
||||
timeSpentNanos = timeSpentMap[peers[1]].Nanoseconds() / numUsers
|
||||
fmt.Println("\n\nAverage time spent:", peers[1], time.Duration(timeSpentNanos))
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue