storage.go 1.8 KB

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