Benchmark to validate fix for https://github.com/couchbase/sync_gateway/issues/2428
(b *testing.B)
| 464 | |
| 465 | // Benchmark to validate fix for https://github.com/couchbase/sync_gateway/issues/2428 |
| 466 | func 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 |
nothing calls this directly
no test coverage detected