mvcc.go 1.7 KB

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