Skip to content

Commit e4237db

Browse files
authored
add configurable retry and batch size options for benchmarking (#20)
- add query-retries flag to control query retry behavior (defaults to 0 for client defaults) - add namespace-setup-batch-size flag for configuring batch size during setup (default 250k) - add namespace-setup-concurrency-max flag to cap total concurrent goroutines across namespaces - make query retries conditional: only apply WithMaxRetries when query-retries is non-zero - use new batch size flag in upsert operations instead of hardcoded value
1 parent d1cc4d7 commit e4237db

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

flags.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,19 @@ var logNormalSigma = flag.Float64(
9191
var namespaceSetupConcurrency = flag.Int(
9292
"namespace-setup-concurrency",
9393
4,
94-
"the number of concurrent goroutines to use for namespace setup",
94+
"the number of concurrent goroutines to use for namespace setup (concurrency per namespace)",
95+
)
96+
97+
var namespaceSetupConcurrencyMax = flag.Int(
98+
"namespace-setup-concurrency-max",
99+
64,
100+
"maximum number of concurrent goroutines to use for namespace setup (total across all namespaces)",
101+
)
102+
103+
var namespaceSetupBatchSize = flag.Int(
104+
"namespace-setup-batch-size",
105+
250_000,
106+
"the number of documents to process in each batch during namespace setup",
95107
)
96108

97109
// Benchmark settings
@@ -174,6 +186,12 @@ var benchmarkDuration = flag.Duration(
174186
"duration of the benchmark. if 0, will run indefinitely",
175187
)
176188

189+
var benchmarkQueryRetries = flag.Int(
190+
"query-retries",
191+
0,
192+
"number of times to retry failed queries (default 0 = default tpuf client retries)",
193+
)
194+
177195
var outputDir = flag.String(
178196
"output-dir",
179197
defaultOutputDir(),

namespace.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ func (n *Namespace) Query(ctx context.Context) (*turbopuffer.QueryPerformance, t
227227

228228
url := fmt.Sprintf("/v2/namespaces/%s/query", n.ID())
229229
var response turbopuffer.NamespaceQueryResponse
230-
if err := n.client.Post(ctx, url, buf.Bytes(), &response); err != nil {
230+
231+
var opts []option.RequestOption
232+
if *benchmarkQueryRetries != 0 {
233+
opts = append(opts, option.WithMaxRetries(*benchmarkQueryRetries))
234+
}
235+
236+
if err := n.client.Post(ctx, url, buf.Bytes(), &response, opts...); err != nil {
231237
var apiErr *turbopuffer.Error
232238
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound {
233239
return nil, 0, nil

upsert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func UpsertDocumentsToNamespaces(
5959
totalUpserts += int64(size)
6060
}
6161

62-
concurrentRequests := min(max(1, (*namespaceSetupConcurrency)*len(namespaces)), 64)
62+
concurrentRequests := min(max(1, (*namespaceSetupConcurrency)*len(namespaces)), *namespaceSetupConcurrencyMax)
6363
log.Printf("upserting documents with %d concurrent batches\n", concurrentRequests)
6464
pb := progressbar.Default(totalUpserts, "upserting documents")
6565

@@ -122,7 +122,7 @@ func makeProgressOn(
122122

123123
var (
124124
largest = upserts[len(upserts)-1].Pending
125-
batch = min(largest, 250_000)
125+
batch = min(largest, *namespaceSetupBatchSize)
126126
)
127127
if batch == 0 {
128128
return nil, errors.New("batch size is zero")

0 commit comments

Comments
 (0)