stress.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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() map[string]int
  27. // Close releases all of the Stresser's resources.
  28. Close() map[string]int
  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(
  39. "creating stresser",
  40. zap.String("type", stype),
  41. zap.String("endpoint", m.EtcdClientEndpoint),
  42. )
  43. switch stype {
  44. case "KV":
  45. // TODO: Too intensive stressing clients can panic etcd member with
  46. // 'out of memory' error. Put rate limits in server side.
  47. stressers[i] = &keyStresser{
  48. lg: clus.lg,
  49. m: m,
  50. keySize: int(clus.Tester.StressKeySize),
  51. keyLargeSize: int(clus.Tester.StressKeySizeLarge),
  52. keySuffixRange: int(clus.Tester.StressKeySuffixRange),
  53. keyTxnSuffixRange: int(clus.Tester.StressKeySuffixRangeTxn),
  54. keyTxnOps: int(clus.Tester.StressKeyTxnOps),
  55. clientsN: int(clus.Tester.StressClients),
  56. rateLimiter: clus.rateLimiter,
  57. }
  58. case "LEASE":
  59. stressers[i] = &leaseStresser{
  60. lg: clus.lg,
  61. m: m,
  62. numLeases: 10, // TODO: configurable
  63. keysPerLease: 10, // TODO: configurable
  64. rateLimiter: clus.rateLimiter,
  65. }
  66. case "ELECTION_RUNNER":
  67. reqRate := 100
  68. args := []string{
  69. "election",
  70. fmt.Sprintf("%v", time.Now().UnixNano()), // election name as current nano time
  71. "--dial-timeout=10s",
  72. "--endpoints", m.EtcdClientEndpoint,
  73. "--total-client-connections=10",
  74. "--rounds=0", // runs forever
  75. "--req-rate", fmt.Sprintf("%v", reqRate),
  76. }
  77. stressers[i] = newRunnerStresser(
  78. clus.Tester.RunnerExecPath,
  79. args,
  80. clus.rateLimiter,
  81. reqRate,
  82. )
  83. case "WATCH_RUNNER":
  84. reqRate := 100
  85. args := []string{
  86. "watcher",
  87. "--prefix", fmt.Sprintf("%v", time.Now().UnixNano()), // prefix all keys with nano time
  88. "--total-keys=1",
  89. "--total-prefixes=1",
  90. "--watch-per-prefix=1",
  91. "--endpoints", m.EtcdClientEndpoint,
  92. "--rounds=0", // runs forever
  93. "--req-rate", fmt.Sprintf("%v", reqRate),
  94. }
  95. stressers[i] = newRunnerStresser(clus.Tester.RunnerExecPath, args, clus.rateLimiter, reqRate)
  96. case "LOCK_RACER_RUNNER":
  97. reqRate := 100
  98. args := []string{
  99. "lock-racer",
  100. fmt.Sprintf("%v", time.Now().UnixNano()), // locker name as current nano time
  101. "--endpoints", m.EtcdClientEndpoint,
  102. "--total-client-connections=10",
  103. "--rounds=0", // runs forever
  104. "--req-rate", fmt.Sprintf("%v", reqRate),
  105. }
  106. stressers[i] = newRunnerStresser(clus.Tester.RunnerExecPath, args, clus.rateLimiter, reqRate)
  107. case "LEASE_RUNNER":
  108. args := []string{
  109. "lease-renewer",
  110. "--ttl=30",
  111. "--endpoints", m.EtcdClientEndpoint,
  112. }
  113. stressers[i] = newRunnerStresser(clus.Tester.RunnerExecPath, args, clus.rateLimiter, 0)
  114. }
  115. }
  116. return &compositeStresser{stressers}
  117. }