rebar 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Paul Rosania
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Rebar
2
+
3
+ ![Rebar](http://upload.wikimedia.org/wikipedia/commons/thumb/6/62/Trebar.jpg/220px-Trebar.jpg)
4
+
5
+ A simple stress testing tool for Redis.
6
+
7
+ * Are sorted sets fast enough with 1,000,000 items?
8
+ * How big a dataset will fit in a 512 MB Redis instance?
9
+ * Should I use a thousand hashes with a thousand keys, or a million strings?
10
+
11
+ Rebar makes it easy to fill a Redis instance with sample data, so you can test
12
+ performance under different database designs. Check memory usage and database
13
+ creation time, or prepare a test dataset for a benchmarking exercise.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'rebar'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install rebar
28
+
29
+ ## Usage
30
+
31
+ More documentation to follow. For now, here's some sample code.
32
+
33
+ require 'rubygems'
34
+ require 'rebar'
35
+ require 'redis'
36
+
37
+ Rebar.build(Redis.new) do
38
+ # Build 10 sets with 100 members each
39
+ sets(10) do
40
+ members 100
41
+ end
42
+
43
+ # Build 10 sorted sets with 100 members each
44
+ sorted_sets(10) do
45
+ members 100
46
+ end
47
+
48
+ # Build 10 hashes with 100 keys each
49
+ hashes(10) do
50
+ keys 100
51
+ end
52
+
53
+ # Build 10 lists with 100 elements each
54
+ lists(10) do
55
+ elements 100
56
+ end
57
+
58
+ # Build 10 random key-value pairs
59
+ strings(10)
60
+ end
61
+
62
+ By default, Rebar cleans the `rebar` namespace before it builds a dataset. To
63
+ disable this behavior, pass `:clean => false` when you call `Rebar.build`.
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/rebar.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "rebar/version"
2
+ require "rebar/builder"
3
+ require "rebar/random"
4
+ require "rebar/dsl"
5
+
6
+ module Rebar
7
+ def self.build(connection, options = {}, &block)
8
+ builder = Rebar::Builder.new(connection)
9
+ builder.clean! unless options[:clean] == false
10
+ builder.build(&block)
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Rebar
2
+ class Builder
3
+ def initialize(connection)
4
+ @connection = connection
5
+ end
6
+
7
+ attr_reader :connection
8
+
9
+ def build(&block)
10
+ Rebar::DSL::Database.new(connection).instance_eval(&block)
11
+ end
12
+
13
+ def clean!
14
+ connection.keys('rebar:*').each do |key|
15
+ connection.del(key)
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/rebar/dsl.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "rebar/dsl/database"
2
+ require "rebar/dsl/hash"
3
+ require "rebar/dsl/list"
4
+ require "rebar/dsl/set"
5
+ require "rebar/dsl/sorted_set"
@@ -0,0 +1,48 @@
1
+ module Rebar
2
+ module DSL
3
+ class Database
4
+ def initialize(connection)
5
+ @connection = connection
6
+ @max_ids = ::Hash.new(0)
7
+ end
8
+
9
+ attr_reader :connection
10
+
11
+ def strings(count)
12
+ count.times do
13
+ connection.set("rebar:string:#{next_id(:string)}", Rebar::Random.string)
14
+ end
15
+ end
16
+
17
+ def hashes(count, &block)
18
+ count.times do
19
+ Rebar::DSL::Hash.new(connection, "rebar:hash:#{next_id(:hash)}").instance_eval(&block)
20
+ end
21
+ end
22
+
23
+ def lists(count, &block)
24
+ count.times do
25
+ Rebar::DSL::List.new(connection, "rebar:list:#{next_id(:list)}").instance_eval(&block)
26
+ end
27
+ end
28
+
29
+ def sets(count, &block)
30
+ count.times do
31
+ Rebar::DSL::Set.new(connection, "rebar:set:#{next_id(:set)}").instance_eval(&block)
32
+ end
33
+ end
34
+
35
+ def sorted_sets(count, &block)
36
+ count.times do
37
+ Rebar::DSL::SortedSet.new(connection, "rebar:sorted_set:#{next_id(:sorted_set)}").instance_eval(&block)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def next_id(type)
44
+ @max_ids[type] += 1
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ module Rebar
2
+ module DSL
3
+ class Hash
4
+ def initialize(connection, key)
5
+ @connection = connection
6
+ @key = key
7
+ end
8
+
9
+ attr_reader :connection
10
+ attr_reader :key
11
+
12
+ def keys(count)
13
+ count.times do
14
+ connection.hset(key, Rebar::Random.string, Rebar::Random.string)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Rebar
2
+ module DSL
3
+ class List
4
+ def initialize(connection, key)
5
+ @connection = connection
6
+ @key = key
7
+ end
8
+
9
+ attr_reader :connection
10
+ attr_reader :key
11
+
12
+ def elements(count)
13
+ count.times do
14
+ connection.rpush(key, Rebar::Random.string)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Rebar
2
+ module DSL
3
+ class Set
4
+ def initialize(connection, key)
5
+ @connection = connection
6
+ @key = key
7
+ end
8
+
9
+ attr_reader :connection
10
+ attr_reader :key
11
+
12
+ def members(count)
13
+ count.times do
14
+ connection.sadd(key, Rebar::Random.string)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Rebar
2
+ module DSL
3
+ class SortedSet
4
+ def initialize(connection, key)
5
+ @connection = connection
6
+ @key = key
7
+ end
8
+
9
+ attr_reader :connection
10
+ attr_reader :key
11
+
12
+ def members(count)
13
+ count.times do
14
+ connection.zadd(key, Rebar::Random.score, Rebar::Random.string)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'digest'
2
+
3
+ module Rebar
4
+ module Random
5
+ def self.score
6
+ rand * 1_000_000_000
7
+ end
8
+
9
+ def self.string
10
+ Digest::SHA256.hexdigest(Time.now.to_s + rand.to_s)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Rebar
2
+ VERSION = "0.2.0"
3
+ end
data/rebar.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rebar/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.platform = Gem::Platform::RUBY
6
+ s.name = 'rebar'
7
+ s.version = Rebar::VERSION
8
+ s.summary = 'A simple stress testing tool for Redis'
9
+ s.description = ''
10
+ s.license = 'MIT'
11
+
12
+ s.required_ruby_version = '>= 1.9.2'
13
+
14
+ s.author = 'Paul Rosania'
15
+ s.email = 'paul.rosania@gmail.com'
16
+ s.homepage = "https://github.com/paulrosania/rebar"
17
+
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.require_path = 'lib'
22
+
23
+ s.add_runtime_dependency('redis', '>= 2.2')
24
+ s.add_runtime_dependency('redis-namespace', '>= 1.1')
25
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rebar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Rosania
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: &70350297747800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70350297747800
25
+ - !ruby/object:Gem::Dependency
26
+ name: redis-namespace
27
+ requirement: &70350297746520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '1.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70350297746520
36
+ description: ''
37
+ email: paul.rosania@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - .gitignore
43
+ - Gemfile
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - lib/rebar.rb
48
+ - lib/rebar/builder.rb
49
+ - lib/rebar/dsl.rb
50
+ - lib/rebar/dsl/database.rb
51
+ - lib/rebar/dsl/hash.rb
52
+ - lib/rebar/dsl/list.rb
53
+ - lib/rebar/dsl/set.rb
54
+ - lib/rebar/dsl/sorted_set.rb
55
+ - lib/rebar/random.rb
56
+ - lib/rebar/version.rb
57
+ - rebar.gemspec
58
+ homepage: https://github.com/paulrosania/rebar
59
+ licenses:
60
+ - MIT
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.9.2
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.11
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: A simple stress testing tool for Redis
83
+ test_files: []