stress.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2018 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package tester
  15. import (
  16. "fmt"
  17. "time"
  18. "github.com/coreos/etcd/tools/functional-tester/rpcpb"
  19. "go.uber.org/zap"
  20. )
  21. // Stresser defines stressing client operations.
  22. type Stresser interface {
  23. // Stress starts to stress the etcd cluster
  24. Stress() error
  25. // Pause stops the stresser from sending requests to etcd. Resume by calling Stress.
  26. Pause()
  27. // Close releases all of the Stresser's resources.
  28. Close()
  29. // ModifiedKeys reports the number of keys created and deleted by stresser
  30. ModifiedKeys() int64
  31. // Checker returns an invariant checker for after the stresser is canceled.
  32. Checker() Checker
  33. }
  34. // newStresser creates stresser from a comma separated list of stresser types.
  35. func newStresser(clus *Cluster, m *rpcpb.Member) Stresser {
  36. stressers := make([]Stresser, len(clus.Tester.StressTypes))
  37. for i, stype := range clus.Tester.StressTypes {
  38. clus.lg.Info("creating stresser", zap.String("type", stype))
  39. switch stype {
  40. case "KV":
  41. // TODO: Too intensive stressing clients can panic etcd member with
  42. // 'out of memory' error. Put rate limits in server side.
  43. stressers[i] = &keyStresser{
  44. lg: clus.lg,
  45. m: m,
  46. keySize: int(clus.Tester.StressKeySize),
  47. keyLargeSize: int(clus.Tester.StressKeySizeLarge),
  48. keySuffixRange: int(clus.Tester.StressKeySuffixRange),
  49. keyTxnSuffixRange: int(clus.Tester.StressKeySuffixRangeTxn),
  50. keyTxnOps: int(clus.Tester.StressKeyTxnOps),
  51. clientsN: int(clus.Tester.StressClients),
  52. rateLimiter: clus.rateLimiter,
  53. }
  54. case "LEASE":
  55. stressers[i] = &leaseStresser{
  56. lg: clus.lg,
  57. m: m,
  58. numLeases: 10, // TODO: configurable
  59. keysPerLease: 10, // TODO: configurable
  60. rateLimiter: clus.rateLimiter,
  61. }
  62. case "ELECTION_RUNNER":
  63. reqRate := 100
  64. args := []string{
  65. "election",
  66. fmt.Sprintf("%v", time.Now().UnixNano()), // election name as current nano time
  67. "--dial-timeout=10s",
  68. "--endpoints", m.EtcdClientEndpoint,
  69. "--total-client-connections=10",
  70. "--rounds=0", // runs forever
  71. "--req-rate", fmt.Sprintf("%v", reqRate),
  72. }
  73. stressers[i] = newRunnerStresser(
  74. clus.Tester.RunnerExecPath,
  75. args,
  76. clus.rateLimiter,
  77. reqRate,
  78. )
  79. case "WATCH_RUNNER":
  80. reqRate := 100
  81. args := []string{
  82. "watcher",
  83. "--prefix", fmt.Sprintf("%v", time.Now().UnixNano()), // prefix all keys with nano time
  84. "--total-keys=1",
  85. "--total-prefixes=1",
  86. "--watch-per-prefix=1",
  87. "--endpoints", m.EtcdClientEndpoint,
  88. "--rounds=0", // runs forever
  89. "--req-rate", fmt.Sprintf("%v", reqRate),
  90. }
  91. stressers[i] = newRunnerStresser(clus.Tester.RunnerExecPath, args, clus.rateLimiter, reqRate)
  92. case "LOCK_RACER_RUNNER":
  93. reqRate := 100
  94. args := []string{
  95. "lock-racer",
  96. fmt.Sprintf("%v", time.Now().UnixNano()), // locker name as current nano time
  97. "--endpoints", m.EtcdClientEndpoint,
  98. "--total-client-connections=10",
  99. "--rounds=0", // runs forever
  100. "--req-rate", fmt.Sprintf("%v", reqRate),
  101. }
  102. stressers[i] = newRunnerStresser(clus.Tester.RunnerExecPath, args, clus.rateLimiter, reqRate)
  103. case "LEASE_RUNNER":
  104. args := []string{
  105. "lease-renewer",
  106. "--ttl=30",
  107. "--endpoints", m.EtcdClientEndpoint,
  108. }
  109. stressers[i] = newRunnerStresser(clus.Tester.RunnerExecPath, args, clus.rateLimiter, 0)
  110. }
  111. }
  112. return &compositeStresser{stressers}
  113. }