MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / BenchmarkChangesFeedDocUnmarshalling

Function BenchmarkChangesFeedDocUnmarshalling

db/changes_test.go:466–549  ·  view source on GitHub ↗

Benchmark to validate fix for https://github.com/couchbase/sync_gateway/issues/2428

(b *testing.B)

Source from the content-addressed store, hash-verified

464
465// Benchmark to validate fix for https://github.com/couchbase/sync_gateway/issues/2428
466func BenchmarkChangesFeedDocUnmarshalling(b *testing.B) {
467 base.SetUpBenchmarkLogging(b, base.LevelWarn, base.KeyHTTP)
468
469 db, ctx := setupTestDB(b)
470 defer db.Close(ctx)
471 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, b, db)
472
473 fieldVal := func(valSizeBytes int) string {
474 buffer := bytes.Buffer{}
475 for i := 0; i < valSizeBytes; i++ {
476 buffer.WriteString("a")
477 }
478 return buffer.String()
479 }
480
481 createDoc := func(numKeys, valSizeBytes int) Body {
482 doc := Body{}
483 for keyNum := 0; keyNum < numKeys; keyNum++ {
484 doc[fmt.Sprintf("%v", keyNum)] = fieldVal(valSizeBytes)
485 }
486 return doc
487 }
488
489 numDocs := 400
490 numKeys := 200
491 valSizeBytes := 1024
492
493 // Create 2k docs of size 50k, 1000 keys with branches, 1 parent + 2 child branches -- doesn't matter which API .. bucket api
494 for docNum := 0; docNum < numDocs; docNum++ {
495
496 // Create the parent rev
497 docid, err := base.GenerateRandomID()
498 require.NoError(b, err)
499 docBody := createDoc(numKeys, valSizeBytes)
500 revId, _, err := collection.Put(ctx, docid, docBody)
501 if err != nil {
502 b.Fatalf("Error creating doc: %v", err)
503 }
504
505 // Create child rev 1
506 docBody["child"] = "A"
507 _, _, err = collection.PutExistingRevWithBody(ctx, docid, docBody, []string{"2-A", revId}, false, ExistingVersionWithUpdateToHLV)
508 if err != nil {
509 b.Fatalf("Error creating child1 rev: %v", err)
510 }
511
512 // Create child rev 2
513 docBody["child"] = "B"
514 _, _, err = collection.PutExistingRevWithBody(ctx, docid, docBody, []string{"2-B", revId}, false, ExistingVersionWithUpdateToHLV)
515 if err != nil {
516 b.Fatalf("Error creating child2 rev: %v", err)
517 }
518
519 }
520
521 // Start changes feed
522 var options ChangesOptions
523 options.Conflicts = true // style=all_docs

Callers

nothing calls this directly

Calls 13

SetUpBenchmarkLoggingFunction · 0.92
GenerateRandomIDFunction · 0.92
TestCtxFunction · 0.92
SetOfFunction · 0.92
setupTestDBFunction · 0.85
createDocFunction · 0.85
MultiChangesFeedMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65
PutMethod · 0.65

Tested by

no test coverage detected