storage.go 1.7 KB

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