loadaboy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ *.beam
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,58 @@
1
+ = loadaboy
2
+
3
+ = Simple Load Test service.
4
+
5
+ = Installation
6
+
7
+ = Synopsis
8
+
9
+ How it works
10
+
11
+ * Write a custom generator in Loadafile.rb
12
+ * run loadaboy domain workers requests-per-worker
13
+
14
+ == Loadafile.rb:
15
+
16
+ class Generator
17
+ AD_SIZES = [{width: 250, height:360}, {width: 300, height:250}, {width: 336, height:280}, {width: 480, height:280}]
18
+
19
+ def random_size
20
+ AD_SIZES[rand(AD_SIZES.length)]
21
+ end
22
+
23
+ def random_string(n = 10)
24
+ (1..n).map{ ('a'..'z').to_a[rand(26)] }.join
25
+ end
26
+
27
+ def random_keywords(n = 20)
28
+ (1..n).map{random_string(5+rand(20))}.join("+")
29
+ end
30
+
31
+ def generate
32
+ size = random_size
33
+ {
34
+ static: "/dynad/static.js",
35
+ ad: "/dynad/ad/load_test_#{rand(3)}/#{size[:width]}/#{size[:height]}?div_id=#{random_string}&keywords=#{random_keywords}&track_url=http://www.zombo.com/"
36
+ }
37
+ end
38
+ end
39
+
40
+
41
+
42
+ == run:
43
+
44
+ loadaboy http://localhost:3000 10 10
45
+
46
+ == Note on Patches/Pull Requests
47
+
48
+ * Fork the project.
49
+ * Make your feature addition or bug fix.
50
+ * Add tests for it. This is important so I don't break it in a
51
+ future version unintentionally.
52
+ * Commit, do not mess with rakefile, version, or history.
53
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
54
+ * Send me a pull request. Bonus points for topic branches.
55
+
56
+ == Copyright
57
+
58
+ Copyright (c) 2010 Jell. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ task :ebuild do
5
+ ERLC_TEST_FLAGS = ""
6
+ ERLC_FLAGS = "-o ../ebin"
7
+ cd "elib"
8
+ sh "erlc #{ERLC_FLAGS} #{ERLC_TEST_FLAGS} #{Dir["**/*.erl"].join(" ")}"
9
+ end
10
+
11
+ begin
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = "loadaboy"
15
+ gem.executables = %W(loadaboy)
16
+ gem.summary = %Q{LoadaBoy - Load Test Gem to the Rescue!}
17
+ gem.description = %Q{LoadaBoy - Load Test Gem to the Rescue!}
18
+ gem.email = "jean-louis@icehouse.se"
19
+ gem.homepage = "http://github.com/Jell/loadaboy"
20
+ gem.authors = ["Jell"]
21
+ gem.files.include(["ext"])
22
+ gem.extensions << 'ext/extconf.rb'
23
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
24
+ gem.add_dependency "erlectricity", "~>1.1.1"
25
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
26
+ end
27
+ Jeweler::GemcutterTasks.new
28
+ rescue LoadError
29
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
30
+ end
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ begin
40
+ require 'rcov/rcovtask'
41
+ Rcov::RcovTask.new do |test|
42
+ test.libs << 'test'
43
+ test.pattern = 'test/**/test_*.rb'
44
+ test.verbose = true
45
+ end
46
+ rescue LoadError
47
+ task :rcov do
48
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
49
+ end
50
+ end
51
+
52
+ task :test => :check_dependencies
53
+
54
+ task :default => :test
55
+
56
+ require 'rake/rdoctask'
57
+ Rake::RDocTask.new do |rdoc|
58
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "loadaboy #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/loadaboy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.join(File.dirname(__FILE__), *%w[.. lib]))
3
+ LOADBOY_ROOT = File.join(File.dirname(__FILE__), *%w[..])
4
+
5
+ system "export LOADABOY_EXEC_DIR=#{Dir.pwd} && cd #{LOADBOY_ROOT}/ebin && ./run_loadaboy #{ARGV.join(' ')}"
data/ebin/run_loadaboy ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env escript
2
+ %% -*- erlang -*-
3
+
4
+ main(String) ->
5
+ try
6
+ error_logger:tty(false),
7
+ [Domain, WorkerCount, RequestCount] = String,
8
+ LoadTest = load_test:new(Domain, list_to_integer(WorkerCount), list_to_integer(RequestCount)),
9
+ LoadTest:start(),
10
+ LoadTest:prepare(),
11
+ LoadTest:run()
12
+ catch
13
+ _:_ ->
14
+ usage()
15
+ end;
16
+
17
+ main(_) ->
18
+ io:format("no header\n"),
19
+ usage().
20
+
21
+ usage() ->
22
+ io:format("usage: loadaboy domain worker-count request-count\n"),
23
+ halt(1).
@@ -0,0 +1,90 @@
1
+ -module(load_test, [Domain, WorkerCount, RequestCount]).
2
+ %-export([start/0, stop/0, run/0, generate_services/1, get_services/0, get_workers/1, get_jobs/2, get_urls/3, set_urls/4]).
3
+ -compile(export_all).
4
+ -record(load_entry, {key, urls}).
5
+
6
+ start() ->
7
+ inets:start(),
8
+ mnesia:start().
9
+
10
+ stop() ->
11
+ mnesia:stop().
12
+
13
+ prepare() ->
14
+ mnesia:delete_table(load_entry),
15
+ mnesia:create_table(load_entry, [{attributes, record_info(fields, load_entry)}]),
16
+ Cmd = "ruby ../lib/erlang_interface.rb",
17
+ Port = open_port({spawn, Cmd}, [{packet, 4}, nouse_stdio, exit_status, binary]),
18
+ Payload = term_to_binary([prepare, [WorkerCount, RequestCount]]),
19
+ port_command(Port, Payload),
20
+ receive
21
+ {Port, {data, Data}} ->
22
+ {result, Text} = binary_to_term(Data),
23
+ [set_urls(test, WorkerName, tuple_to_list(Urls)) || {WorkerName, Urls}<- tuple_to_list(Text)]
24
+ end.
25
+
26
+ run() ->
27
+ {atomic, Services} = get_services(),
28
+ generate_services(lists:usort(Services)),
29
+ wait_for_workers(WorkerCount).
30
+
31
+ generate_services(Services) ->
32
+ case Services of
33
+ [] ->
34
+ done;
35
+ [Service | Remaining] ->
36
+ {atomic, Workers} = get_workers(Service),
37
+ generate_workers(Service, Workers),
38
+ generate_services(Remaining)
39
+ end.
40
+
41
+ generate_workers(Service, Workers) ->
42
+ case Workers of
43
+ [] ->
44
+ done;
45
+ [WorkerName | Remaining] ->
46
+ {atomic, [Urls]} = get_urls(Service, WorkerName),
47
+ Worker = worker:new(self(), WorkerName, Domain, Urls),
48
+ Worker:run(),
49
+ generate_workers(Service, Remaining)
50
+ end.
51
+
52
+ wait_for_workers(RemainingWorkers) ->
53
+ receive
54
+ done ->
55
+ case RemainingWorkers - 1 of
56
+ 0 ->
57
+ done;
58
+ _ ->
59
+ wait_for_workers(RemainingWorkers - 1)
60
+ end
61
+ end.
62
+
63
+ get_services() ->
64
+ F = fun() ->
65
+ LoadEntry = #load_entry{key = {'$1', '_'}, urls = '_'},
66
+ mnesia:select(load_entry, [{LoadEntry, [], ['$1']}])
67
+ end,
68
+ mnesia:transaction(F).
69
+
70
+ get_workers(Service) ->
71
+ F = fun() ->
72
+ LoadEntry = #load_entry{key = {Service, '$1'}, urls = '_'},
73
+ mnesia:select(load_entry, [{LoadEntry, [], ['$1']}])
74
+ end,
75
+ mnesia:transaction(F).
76
+
77
+
78
+ get_urls(Service, Worker) ->
79
+ F = fun() ->
80
+ LoadEntry = #load_entry{key = {Service, Worker}, urls = '$1'},
81
+ mnesia:select(load_entry, [{LoadEntry, [], ['$1']}])
82
+ end,
83
+ mnesia:transaction(F).
84
+
85
+ set_urls(Service, Worker, Urls) ->
86
+ LoadEntry = #load_entry{key = {Service, Worker}, urls = Urls},
87
+ F = fun() ->
88
+ mnesia:write(LoadEntry)
89
+ end,
90
+ mnesia:transaction(F).
data/elib/worker.erl ADDED
@@ -0,0 +1,51 @@
1
+ -module(worker, [Parent, ProfileName, Domain, Urls]).
2
+ -compile(export_all).
3
+
4
+ run() ->
5
+ spawn(
6
+ fun() ->
7
+ inets:start(httpc, [{profile, ProfileName}]),
8
+ fetch_urls(Urls)
9
+ end
10
+ ).
11
+
12
+ fetch_urls(UrlList) ->
13
+ case UrlList of
14
+ [] ->
15
+ Parent!done;
16
+ [Url|Tail] ->
17
+ {Name, Request} = Url,
18
+ [Header, Time] = fetch_url(Domain ++ binary_to_list(Request)),
19
+ io:format("~p ~p ~p~n", [Header, Name, Time]),
20
+ fetch_urls(Tail)
21
+ end.
22
+
23
+ fetch_url(Url) ->
24
+ try
25
+ Tic = erlang:now(),
26
+ Result = get_over_http(Url),
27
+ Tac = erlang:now(),
28
+ Time = time_to_ms(Tac) - time_to_ms(Tic),
29
+ case Result of
30
+ timeout ->
31
+ [timeout, Time];
32
+ {Header, _Params, _Body} ->
33
+ [Header, Time]
34
+ end
35
+ catch
36
+ _:_ ->
37
+ ['FAIL', 0]
38
+ end.
39
+
40
+ time_to_ms({Mega, Sec, Micro})->
41
+ Mega * 1000000000 + Sec * 1000 + Micro / 1000.
42
+
43
+ get_over_http(Url) ->
44
+ {ok, RequestId} = httpc:request(get, {Url, []}, [], [{sync, false}], ProfileName),
45
+ receive
46
+ {http, {RequestId, Result}} ->
47
+ Result
48
+ after
49
+ 3000 ->
50
+ timeout
51
+ end.
data/ext/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ install:
2
+ erlc -o ../ebin ../elib/*.erl
data/ext/extconf.rb ADDED
@@ -0,0 +1 @@
1
+ # Does nothing, Makefile is static
@@ -0,0 +1,15 @@
1
+ LOADABOY_EXEC_DIR = `echo $LOADABOY_EXEC_DIR`.chomp
2
+
3
+ require 'rubygems'
4
+ require 'erlectricity'
5
+ require 'loadaboy'
6
+
7
+ extend LoadaBoy
8
+
9
+ receive do |f|
10
+ f.when([:prepare, Array]) do |array|
11
+ f.send!([:result, generate_requests(array[0], array[1])])
12
+ f.receive_loop
13
+ end
14
+ end
15
+
data/lib/generator.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Generator
2
+ def generate
3
+ { default: "/" }
4
+ end
5
+ end
data/lib/loadaboy.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'generator'
2
+ require "#{LOADABOY_EXEC_DIR}/Loadafile" if File.exist? "#{LOADABOY_EXEC_DIR}/Loadafile.rb"
3
+
4
+ module LoadaBoy
5
+ def generate_requests(workers_count, jobs_count)
6
+ generator = Generator.new
7
+ (1..workers_count).map do |i|
8
+ ["worker#{i}".to_sym, (1..jobs_count).map { generator.generate.to_a }.flatten(1)]
9
+ end
10
+ end
11
+ end
data/loadaboy.gemspec ADDED
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{loadaboy}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jell"]
12
+ s.date = %q{2010-10-19}
13
+ s.default_executable = %q{loadaboy}
14
+ s.description = %q{LoadaBoy - Load Test Gem to the Rescue!}
15
+ s.email = %q{jean-louis@icehouse.se}
16
+ s.executables = ["loadaboy"]
17
+ s.extensions = ["ext/extconf.rb", "ext/extconf.rb"]
18
+ s.extra_rdoc_files = [
19
+ "LICENSE",
20
+ "README.rdoc"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ ".gitignore",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/loadaboy",
30
+ "ebin/run_loadaboy",
31
+ "elib/load_test.erl",
32
+ "elib/worker.erl",
33
+ "ext/Makefile",
34
+ "ext/extconf.rb",
35
+ "lib/erlang_interface.rb",
36
+ "lib/generator.rb",
37
+ "lib/loadaboy.rb",
38
+ "loadaboy.gemspec",
39
+ "test/helper.rb",
40
+ "test/test_loadaboy.rb"
41
+ ]
42
+ s.homepage = %q{http://github.com/Jell/loadaboy}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.7}
46
+ s.summary = %q{LoadaBoy - Load Test Gem to the Rescue!}
47
+ s.test_files = [
48
+ "test/helper.rb",
49
+ "test/test_loadaboy.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ s.add_runtime_dependency(%q<erlectricity>, ["~> 1.1.1"])
59
+ else
60
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
61
+ s.add_dependency(%q<erlectricity>, ["~> 1.1.1"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
65
+ s.add_dependency(%q<erlectricity>, ["~> 1.1.1"])
66
+ end
67
+ end
68
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'loadaboy'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestLoadaboy < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loadaboy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jell
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-19 00:00:00 +02:00
18
+ default_executable: loadaboy
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: erlectricity
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 1
44
+ - 1
45
+ version: 1.1.1
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: LoadaBoy - Load Test Gem to the Rescue!
49
+ email: jean-louis@icehouse.se
50
+ executables:
51
+ - loadaboy
52
+ extensions:
53
+ - ext/extconf.rb
54
+ - ext/extconf.rb
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ files:
59
+ - .document
60
+ - .gitignore
61
+ - LICENSE
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - bin/loadaboy
66
+ - ebin/run_loadaboy
67
+ - elib/load_test.erl
68
+ - elib/worker.erl
69
+ - ext/Makefile
70
+ - ext/extconf.rb
71
+ - lib/erlang_interface.rb
72
+ - lib/generator.rb
73
+ - lib/loadaboy.rb
74
+ - loadaboy.gemspec
75
+ - test/helper.rb
76
+ - test/test_loadaboy.rb
77
+ has_rdoc: true
78
+ homepage: http://github.com/Jell/loadaboy
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options:
83
+ - --charset=UTF-8
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.3.7
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: LoadaBoy - Load Test Gem to the Rescue!
109
+ test_files:
110
+ - test/helper.rb
111
+ - test/test_loadaboy.rb