BenchmarkMixedWorkload tests mixed workload with different request patterns
(b *testing.B)
| 387 | |
| 388 | // BenchmarkMixedWorkload tests mixed workload with different request patterns |
| 389 | func BenchmarkMixedWorkload(b *testing.B) { |
| 390 | ctx := context.Background() |
| 391 | checker := &MockChecker{} |
| 392 | |
| 393 | config := BulkCheckerConfig{ |
| 394 | ConcurrencyLimit: 75, |
| 395 | BufferSize: 75000, |
| 396 | } |
| 397 | |
| 398 | callback := func(id, ct string) {} |
| 399 | |
| 400 | b.ResetTimer() |
| 401 | b.ReportAllocs() |
| 402 | |
| 403 | for b.Loop() { |
| 404 | bc, err := NewBulkChecker(ctx, checker, BulkCheckerTypeEntity, callback, config) |
| 405 | if err != nil { |
| 406 | b.Fatal(err) |
| 407 | } |
| 408 | |
| 409 | publisher := NewBulkEntityPublisher(ctx, &base.PermissionLookupEntityRequest{ |
| 410 | TenantId: "test", |
| 411 | Metadata: &base.PermissionLookupEntityRequestMetadata{}, |
| 412 | EntityType: "document", |
| 413 | Permission: "read", |
| 414 | Subject: &base.Subject{Id: "user1"}, |
| 415 | }, bc) |
| 416 | |
| 417 | // Mixed workload: some sequential, some concurrent, some burst |
| 418 | var wg sync.WaitGroup |
| 419 | |
| 420 | // Sequential requests |
| 421 | for j := 0; j < 10000; j++ { |
| 422 | publisher.Publish( |
| 423 | &base.Entity{Id: fmt.Sprintf("seq_%d", j)}, |
| 424 | &base.PermissionCheckRequestMetadata{}, |
| 425 | &base.Context{}, |
| 426 | base.CheckResult_CHECK_RESULT_UNSPECIFIED, |
| 427 | ) |
| 428 | } |
| 429 | |
| 430 | // Concurrent requests |
| 431 | for g := 0; g < 25; g++ { |
| 432 | wg.Add(1) |
| 433 | go func(goroutineID int) { |
| 434 | defer wg.Done() |
| 435 | for j := 0; j < 2000; j++ { |
| 436 | publisher.Publish( |
| 437 | &base.Entity{Id: fmt.Sprintf("concurrent_%d_%d", goroutineID, j)}, |
| 438 | &base.PermissionCheckRequestMetadata{}, |
| 439 | &base.Context{}, |
| 440 | base.CheckResult_CHECK_RESULT_UNSPECIFIED, |
| 441 | ) |
| 442 | } |
| 443 | }(g) |
| 444 | } |
| 445 | |
| 446 | // Burst requests |
nothing calls this directly
no test coverage detected