Skip conservative tail probes in batching · Entire
Skip conservative tail probes in batching
e933b9a→main·
Soph·3mo ago·2 files·+62 added/-3 removed
Sessions
26d96c05aedfView transcript
Changes
2
internal/strategy/bootstrap
Mbootstrap.go+14/-1
- Mbootstrap_test.go+48/-2
399 unmodified lines
400
401
402
403
403
404
405
406
407
408
70 unmodified lines
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
399 unmodified lines
bestIdx := -1
remaining := len(chain) - 1 - prevIdx
if shouldProbeTipFirst(p.BatchMaxPack, prevMeasuredBytes, prevSpan, remaining) {
if shouldSelectTipWithoutProbe(p.BatchMaxPack, prevMeasuredBytes, prevSpan, remaining) {
bestIdx = len(chain) - 1
} else if shouldProbeTipFirst(p.BatchMaxPack, prevMeasuredBytes, prevSpan, remaining) {
tipIdx := len(chain) - 1
tooLarge, err := probe(tipIdx)
if err != nil {
70 unmodified lines
return estimated <= (limit*9)/10
}
func shouldSelectTipWithoutProbe(limit int64, measuredBytes int, measuredSpan int, remaining int) bool {
if limit <= 0 || measuredBytes <= 0 || measuredSpan <= 0 || remaining <= 0 {
return false
}
if remaining <= measuredSpan {
return int64(measuredBytes) <= limit/2
}
estimated := (int64(measuredBytes) * int64(remaining)) / int64(measuredSpan)
return estimated <= limit/2
}
func fetchPackForProbe(ctx context.Context, p Params, ref planner.DesiredRef, want, have plumbing.Hash, limit int64) ([]byte, bool, error) {
desired := singleGP(ref.SourceRef, ref.TargetRef, want)
haves := planner.SingleHaveMap(have)
Minternal/strategy/bootstrap/bootstrap.go+14/-1
243 unmodified lines
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
2 unmodified lines
298
299
300
255
301
302
303
258
304
305
306
307
243 unmodified lines
}
}
func TestShouldSelectTipWithoutProbe(t *testing.T) {
tests := []struct {
name string
limit int64
measured int
measuredSpan int
remaining int
want bool
}{
{
name: "selects tip when estimate is far below limit",
limit: 1000,
measured: 150,
measuredSpan: 4,
remaining: 10,
want: true,
},
{
name: "does not select tip when estimate is only moderately below limit",
limit: 1000,
measured: 220,
measuredSpan: 4,
remaining: 10,
want: false,
},
{
name: "does not select tip without measurements",
limit: 1000,
measured: 0,
measuredSpan: 4,
remaining: 10,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := shouldSelectTipWithoutProbe(tt.limit, tt.measured, tt.measuredSpan, tt.remaining)
if got != tt.want {
t.Fatalf("shouldSelectTipWithoutProbe(%d, %d, %d, %d) = %v, want %v",
tt.limit, tt.measured, tt.measuredSpan, tt.remaining, got, tt.want)
}
})
}
}
func TestPlanCheckpointsProbeCountVisibility(t *testing.T) {
tests := []struct {
name string
2 unmodified lines
wantProbes int
}{
{
name: "small early sample jumps directly to tip",
name: "small early sample selects tip without a second probe",
batchLimit: 20_000,
spanSizes: map[int]int{1: 1_000, 2: 2_000, 3: 3_000, 4: 4_000, 5: 5_000, 6: 6_000, 7: 7_000, 8: 8_000, 9: 9_000, 10: 10_000},
wantProbes: 2,
wantProbes: 1,
},
{
name: "mid-sized spans require repeated exact probes,