assign_file_id_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package operation
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "google.golang.org/grpc"
  7. "testing"
  8. "time"
  9. )
  10. func BenchmarkWithConcurrency(b *testing.B) {
  11. concurrencyLevels := []int{1, 10, 100, 1000}
  12. ap, _ := NewAssignProxy(func(_ context.Context) pb.ServerAddress {
  13. return pb.ServerAddress("localhost:9333")
  14. }, grpc.WithInsecure(), 16)
  15. for _, concurrency := range concurrencyLevels {
  16. b.Run(
  17. fmt.Sprintf("Concurrency-%d", concurrency),
  18. func(b *testing.B) {
  19. for i := 0; i < b.N; i++ {
  20. done := make(chan struct{})
  21. startTime := time.Now()
  22. for j := 0; j < concurrency; j++ {
  23. go func() {
  24. ap.Assign(&VolumeAssignRequest{
  25. Count: 1,
  26. })
  27. done <- struct{}{}
  28. }()
  29. }
  30. for j := 0; j < concurrency; j++ {
  31. <-done
  32. }
  33. duration := time.Since(startTime)
  34. b.Logf("Concurrency: %d, Duration: %v", concurrency, duration)
  35. }
  36. },
  37. )
  38. }
  39. }
  40. func BenchmarkStreamAssign(b *testing.B) {
  41. ap, _ := NewAssignProxy(func(_ context.Context) pb.ServerAddress {
  42. return pb.ServerAddress("localhost:9333")
  43. }, grpc.WithInsecure(), 16)
  44. for i := 0; i < b.N; i++ {
  45. ap.Assign(&VolumeAssignRequest{
  46. Count: 1,
  47. })
  48. }
  49. }
  50. func BenchmarkUnaryAssign(b *testing.B) {
  51. for i := 0; i < b.N; i++ {
  52. Assign(func(_ context.Context) pb.ServerAddress {
  53. return pb.ServerAddress("localhost:9333")
  54. }, grpc.WithInsecure(), &VolumeAssignRequest{
  55. Count: 1,
  56. })
  57. }
  58. }