Add benchmark scenarios for concurrent inserts
This commit is contained in:
parent
bc42d15625
commit
ffc3e644c5
@ -14,8 +14,6 @@ var (
|
|||||||
secondCondition = core.Condition("[RESPONSE_TIME] < 500")
|
secondCondition = core.Condition("[RESPONSE_TIME] < 500")
|
||||||
thirdCondition = core.Condition("[CERTIFICATE_EXPIRATION] < 72h")
|
thirdCondition = core.Condition("[CERTIFICATE_EXPIRATION] < 72h")
|
||||||
|
|
||||||
timestamp = time.Now()
|
|
||||||
|
|
||||||
testService = core.Service{
|
testService = core.Service{
|
||||||
Name: "name",
|
Name: "name",
|
||||||
Group: "group",
|
Group: "group",
|
||||||
@ -36,7 +34,6 @@ var (
|
|||||||
Errors: nil,
|
Errors: nil,
|
||||||
Connected: true,
|
Connected: true,
|
||||||
Success: true,
|
Success: true,
|
||||||
Timestamp: timestamp,
|
|
||||||
Duration: 150 * time.Millisecond,
|
Duration: 150 * time.Millisecond,
|
||||||
CertificateExpiration: 10 * time.Hour,
|
CertificateExpiration: 10 * time.Hour,
|
||||||
ConditionResults: []*core.ConditionResult{
|
ConditionResults: []*core.ConditionResult{
|
||||||
@ -61,7 +58,6 @@ var (
|
|||||||
Errors: []string{"error-1", "error-2"},
|
Errors: []string{"error-1", "error-2"},
|
||||||
Connected: true,
|
Connected: true,
|
||||||
Success: false,
|
Success: false,
|
||||||
Timestamp: timestamp,
|
|
||||||
Duration: 750 * time.Millisecond,
|
Duration: 750 * time.Millisecond,
|
||||||
CertificateExpiration: 10 * time.Hour,
|
CertificateExpiration: 10 * time.Hour,
|
||||||
ConditionResults: []*core.ConditionResult{
|
ConditionResults: []*core.ConditionResult{
|
||||||
@ -119,29 +115,64 @@ func BenchmarkStore_Insert(b *testing.B) {
|
|||||||
}
|
}
|
||||||
defer databaseStore.Close()
|
defer databaseStore.Close()
|
||||||
type Scenario struct {
|
type Scenario struct {
|
||||||
Name string
|
Name string
|
||||||
Store Store
|
Store Store
|
||||||
|
Parallel bool
|
||||||
}
|
}
|
||||||
scenarios := []Scenario{
|
scenarios := []Scenario{
|
||||||
{
|
{
|
||||||
Name: "memory",
|
Name: "memory",
|
||||||
Store: memoryStore,
|
Store: memoryStore,
|
||||||
|
Parallel: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "database",
|
Name: "memory-parallel",
|
||||||
Store: databaseStore,
|
Store: memoryStore,
|
||||||
|
Parallel: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "database",
|
||||||
|
Store: databaseStore,
|
||||||
|
Parallel: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "database-parallel",
|
||||||
|
Store: databaseStore,
|
||||||
|
Parallel: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, scenario := range scenarios {
|
for _, scenario := range scenarios {
|
||||||
b.Run(scenario.Name, func(b *testing.B) {
|
b.Run(scenario.Name, func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
if scenario.Parallel {
|
||||||
if n%100 == 0 {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
scenario.Store.Insert(&testService, &testUnsuccessfulResult)
|
n := 0
|
||||||
} else {
|
for pb.Next() {
|
||||||
scenario.Store.Insert(&testService, &testSuccessfulResult)
|
var result core.Result
|
||||||
|
if n%10 == 0 {
|
||||||
|
result = testUnsuccessfulResult
|
||||||
|
} else {
|
||||||
|
result = testSuccessfulResult
|
||||||
|
}
|
||||||
|
result.Timestamp = time.Now()
|
||||||
|
scenario.Store.Insert(&testService, &result)
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
var result core.Result
|
||||||
|
if n%10 == 0 {
|
||||||
|
result = testUnsuccessfulResult
|
||||||
|
} else {
|
||||||
|
result = testSuccessfulResult
|
||||||
|
}
|
||||||
|
result.Timestamp = time.Now()
|
||||||
|
scenario.Store.Insert(&testService, &result)
|
||||||
|
//wat := scenario.Store.GetServiceStatusByKey(testService.Key())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
scenario.Store.Clear()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user