You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.4 KiB

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