mvcc.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2015 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 cmd
  15. import (
  16. "os"
  17. "time"
  18. "go.uber.org/zap"
  19. "go.etcd.io/etcd/lease"
  20. "go.etcd.io/etcd/mvcc"
  21. "go.etcd.io/etcd/mvcc/backend"
  22. "github.com/spf13/cobra"
  23. )
  24. var (
  25. batchInterval int
  26. batchLimit int
  27. s mvcc.KV
  28. )
  29. func initMVCC() {
  30. bcfg := backend.DefaultBackendConfig()
  31. bcfg.Path, bcfg.BatchInterval, bcfg.BatchLimit = "mvcc-bench", time.Duration(batchInterval)*time.Millisecond, batchLimit
  32. be := backend.New(bcfg)
  33. s = mvcc.NewStore(zap.NewExample(), be, &lease.FakeLessor{}, nil, mvcc.StoreConfig{})
  34. os.Remove("mvcc-bench") // boltDB has an opened fd, so removing the file is ok
  35. }
  36. // mvccCmd represents the MVCC storage benchmarking tools
  37. var mvccCmd = &cobra.Command{
  38. Use: "mvcc",
  39. Short: "Benchmark mvcc",
  40. Long: `storage subcommand is a set of various benchmark tools for MVCC storage subsystem of etcd.
  41. Actual benchmarks are implemented as its subcommands.`,
  42. PersistentPreRun: mvccPreRun,
  43. }
  44. func init() {
  45. RootCmd.AddCommand(mvccCmd)
  46. mvccCmd.PersistentFlags().IntVar(&batchInterval, "batch-interval", 100, "Interval of batching (milliseconds)")
  47. mvccCmd.PersistentFlags().IntVar(&batchLimit, "batch-limit", 10000, "A limit of batched transaction")
  48. }
  49. func mvccPreRun(cmd *cobra.Command, args []string) {
  50. initMVCC()
  51. }