Improve benchmark, fix offset bug
This ensures that setup time does not impact the results of the benchmark since profiling showed that much time was spent setting up the test array of tasks. This also uses `make` to build that slice instead. Also, the tests revealed that there was a bug where offsets were pre-incremented rather than post-incremented, omitting the first 100 results.pull/1886/head
parent
c3be40513d
commit
d560ab020a
|
@ -51,7 +51,6 @@ func (p *PaginatingKapaClient) ListTasks(opts *client.ListTasksOptions) ([]clien
|
|||
}
|
||||
|
||||
for {
|
||||
opts.Offset = p.FetchRate + opts.Offset
|
||||
select {
|
||||
case <-done:
|
||||
close(optChan)
|
||||
|
@ -59,6 +58,7 @@ func (p *PaginatingKapaClient) ListTasks(opts *client.ListTasksOptions) ([]clien
|
|||
case optChan <- *opts:
|
||||
// nop
|
||||
}
|
||||
opts.Offset = p.FetchRate + opts.Offset
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
@ -11,18 +11,20 @@ import (
|
|||
func BenchmarkKapaClient100(b *testing.B) { benchmark_PaginatingKapaClient(100, b) }
|
||||
func BenchmarkKapaClient1000(b *testing.B) { benchmark_PaginatingKapaClient(1000, b) }
|
||||
func BenchmarkKapaClient10000(b *testing.B) { benchmark_PaginatingKapaClient(10000, b) }
|
||||
func BenchmarkKapaClient100000(b *testing.B) { benchmark_PaginatingKapaClient(100000, b) }
|
||||
|
||||
var tasks []client.Task
|
||||
|
||||
func benchmark_PaginatingKapaClient(taskCount int, b *testing.B) {
|
||||
|
||||
b.StopTimer() // eliminate setup time
|
||||
|
||||
// create a mock client that will return a huge response from ListTasks
|
||||
mockClient := &mocks.KapaClient{
|
||||
ListTasksF: func(opts *client.ListTasksOptions) ([]client.Task, error) {
|
||||
// create all the tasks
|
||||
allTasks := []client.Task{}
|
||||
allTasks := make([]client.Task, taskCount)
|
||||
|
||||
// create N tasks from the benchmark runner
|
||||
for i := 0; i < taskCount; i++ {
|
||||
allTasks = append(allTasks, client.Task{})
|
||||
}
|
||||
begin := opts.Offset
|
||||
end := opts.Offset + opts.Limit
|
||||
|
||||
|
@ -42,8 +44,11 @@ func benchmark_PaginatingKapaClient(taskCount int, b *testing.B) {
|
|||
|
||||
opts := &client.ListTasksOptions{}
|
||||
|
||||
b.StartTimer() // eliminate setup time
|
||||
|
||||
// let the benchmark runner run ListTasks until it's satisfied
|
||||
for n := 0; n < b.N; n++ {
|
||||
_, _ = pkap.ListTasks(opts)
|
||||
// assignment is to avoid having the call optimized away
|
||||
tasks, _ = pkap.ListTasks(opts)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ func Test_Kapacitor_PaginatingKapaClient(t *testing.T) {
|
|||
end = len(allTasks)
|
||||
}
|
||||
|
||||
if begin > len(allTasks) {
|
||||
begin = end
|
||||
}
|
||||
|
||||
return allTasks[begin:end], nil
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue