storage.go 1.6 KB

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