Skip to content
Snippets Groups Projects
Commit 74f9f047 authored by ale's avatar ale
Browse files

Run the read benchmarks with many IPs

Reduce the effect of caches within the database layer.
parent 633fc781
Branches
No related tags found
No related merge requests found
......@@ -20,6 +20,14 @@ func randomIP() string {
return fmt.Sprintf("%d.%d.%d.%d", 1+rand.Intn(253), 1+rand.Intn(253), 1+rand.Intn(253), 1+rand.Intn(253))
}
func randomIPs(n int) []string {
out := make([]string, n)
for i := 0; i < n; i++ {
out[i] = randomIP()
}
return out
}
func randomType() string {
return "detection"
}
......@@ -174,12 +182,17 @@ func runReadBenchmark(b *testing.B, driver string, eventsPerIP int) {
n := manyEvents
db.AddAggregate(randomEvents(n))
refIP := "1.2.3.4"
a := new(ippb.Aggregate)
for i := 0; i < eventsPerIP; i++ {
a.AddEvent(&ippb.Event{Type: "test", Ip: refIP, Count: 1})
// For a bunch of random IPs, add a known (possibly large)
// number of events.
numIPs := 100
refIPs := randomIPs(numIPs)
for _, ip := range refIPs {
a := new(ippb.Aggregate)
for i := 0; i < eventsPerIP; i++ {
a.AddEvent(&ippb.Event{Type: "test", Ip: ip, Count: 1})
}
db.AddAggregate(a)
}
db.AddAggregate(a)
// Compact the database if it's LevelDB.
if ldb, ok := db.(*leveldb.DB); ok {
......@@ -189,7 +202,13 @@ func runReadBenchmark(b *testing.B, driver string, eventsPerIP int) {
deadline := time.Now().Add(-1 * time.Hour)
b.ResetTimer()
ipCount := 0
for i := 0; i < b.N; i++ {
refIP := refIPs[ipCount]
ipCount++
if ipCount >= len(refIPs) {
ipCount = 0
}
m, err := db.ScanIP(deadline, refIP)
if err != nil {
b.Fatalf("ScanIP(%d): %v", i, err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment