MCPcopy Create free account
hub / github.com/Permify/permify / BenchmarkMixedWorkload

Function BenchmarkMixedWorkload

internal/engines/bulk_benchmark_test.go:389–468  ·  view source on GitHub ↗

BenchmarkMixedWorkload tests mixed workload with different request patterns

(b *testing.B)

Source from the content-addressed store, hash-verified

387
388// BenchmarkMixedWorkload tests mixed workload with different request patterns
389func 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

Callers

nothing calls this directly

Calls 7

PublishMethod · 0.95
CloseMethod · 0.95
NewBulkCheckerFunction · 0.85
NewBulkEntityPublisherFunction · 0.85
WaitMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected