skynet 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +65 -0
  4. data/README.txt +100 -0
  5. data/Rakefile +4 -0
  6. data/app_generators/skynet_install/USAGE +5 -0
  7. data/app_generators/skynet_install/skynet_install_generator.rb +84 -0
  8. data/app_generators/skynet_install/templates/migration.rb +60 -0
  9. data/app_generators/skynet_install/templates/skynet +33 -0
  10. data/app_generators/skynet_install/templates/skynet_console +16 -0
  11. data/bin/skynet +20 -0
  12. data/bin/skynet_console +9 -0
  13. data/bin/skynet_install +12 -0
  14. data/bin/skynet_tuplespace_server +53 -0
  15. data/config/hoe.rb +74 -0
  16. data/config/requirements.rb +17 -0
  17. data/lib/skynet.rb +34 -0
  18. data/lib/skynet/mapreduce_test.rb +25 -0
  19. data/lib/skynet/message_queue_adapters/message_queue_adapter.rb +70 -0
  20. data/lib/skynet/message_queue_adapters/mysql.rb +573 -0
  21. data/lib/skynet/message_queue_adapters/tuple_space.rb +327 -0
  22. data/lib/skynet/skynet_active_record_extensions.rb +237 -0
  23. data/lib/skynet/skynet_config.rb +59 -0
  24. data/lib/skynet/skynet_console.rb +34 -0
  25. data/lib/skynet/skynet_console_helper.rb +59 -0
  26. data/lib/skynet/skynet_debugger.rb +84 -0
  27. data/lib/skynet/skynet_guid_generator.rb +68 -0
  28. data/lib/skynet/skynet_job.rb +607 -0
  29. data/lib/skynet/skynet_launcher.rb +10 -0
  30. data/lib/skynet/skynet_logger.rb +52 -0
  31. data/lib/skynet/skynet_manager.rb +486 -0
  32. data/lib/skynet/skynet_message.rb +366 -0
  33. data/lib/skynet/skynet_message_queue.rb +100 -0
  34. data/lib/skynet/skynet_ruby_extensions.rb +36 -0
  35. data/lib/skynet/skynet_task.rb +76 -0
  36. data/lib/skynet/skynet_tuplespace_server.rb +82 -0
  37. data/lib/skynet/skynet_worker.rb +395 -0
  38. data/lib/skynet/version.rb +9 -0
  39. data/log/debug.log +0 -0
  40. data/log/skynet.log +29 -0
  41. data/log/skynet_tuplespace_server.log +7 -0
  42. data/log/skynet_worker.pid +1 -0
  43. data/script/destroy +14 -0
  44. data/script/generate +14 -0
  45. data/script/txt2html +74 -0
  46. data/setup.rb +1585 -0
  47. data/sometest.rb +23 -0
  48. data/tasks/deployment.rake +34 -0
  49. data/tasks/environment.rake +7 -0
  50. data/tasks/website.rake +17 -0
  51. data/test/all_models_test.rb +139 -0
  52. data/test/mysql_message_queue_adaptor_test.rb +199 -0
  53. data/test/skynet_manager_test.rb +107 -0
  54. data/test/skynet_message_test.rb +42 -0
  55. data/test/test_generator_helper.rb +20 -0
  56. data/test/test_helper.rb +2 -0
  57. data/test/test_skynet.rb +11 -0
  58. data/test/test_skynet_install_generator.rb +53 -0
  59. data/test/tuplespace_message_queue_test.rb +179 -0
  60. data/tmtags +1242 -0
  61. data/website/index.html +93 -0
  62. data/website/index.txt +39 -0
  63. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  64. data/website/stylesheets/screen.css +138 -0
  65. data/website/template.rhtml +48 -0
  66. metadata +129 -0
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2007-12-16
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Adam Pisoni, Geni.com
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.
@@ -0,0 +1,65 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ app_generators/skynet_install/USAGE
7
+ app_generators/skynet_install/skynet_install_generator.rb
8
+ app_generators/skynet_install/templates/migration.rb
9
+ app_generators/skynet_install/templates/skynet
10
+ app_generators/skynet_install/templates/skynet_console
11
+ bin/skynet
12
+ bin/skynet_console
13
+ bin/skynet_install
14
+ bin/skynet_tuplespace_server
15
+ config/hoe.rb
16
+ config/requirements.rb
17
+ lib/skynet.rb
18
+ lib/skynet/mapreduce_test.rb
19
+ lib/skynet/message_queue_adapters/message_queue_adapter.rb
20
+ lib/skynet/message_queue_adapters/mysql.rb
21
+ lib/skynet/message_queue_adapters/tuple_space.rb
22
+ lib/skynet/skynet_active_record_extensions.rb
23
+ lib/skynet/skynet_config.rb
24
+ lib/skynet/skynet_console.rb
25
+ lib/skynet/skynet_console_helper.rb
26
+ lib/skynet/skynet_debugger.rb
27
+ lib/skynet/skynet_guid_generator.rb
28
+ lib/skynet/skynet_job.rb
29
+ lib/skynet/skynet_launcher.rb
30
+ lib/skynet/skynet_logger.rb
31
+ lib/skynet/skynet_manager.rb
32
+ lib/skynet/skynet_message.rb
33
+ lib/skynet/skynet_message_queue.rb
34
+ lib/skynet/skynet_ruby_extensions.rb
35
+ lib/skynet/skynet_task.rb
36
+ lib/skynet/skynet_tuplespace_server.rb
37
+ lib/skynet/skynet_worker.rb
38
+ lib/skynet/version.rb
39
+ log/debug.log
40
+ log/skynet.log
41
+ log/skynet_tuplespace_server.log
42
+ log/skynet_worker.pid
43
+ script/destroy
44
+ script/generate
45
+ script/txt2html
46
+ setup.rb
47
+ sometest.rb
48
+ tasks/deployment.rake
49
+ tasks/environment.rake
50
+ tasks/website.rake
51
+ test/all_models_test.rb
52
+ test/mysql_message_queue_adaptor_test.rb
53
+ test/skynet_manager_test.rb
54
+ test/skynet_message_test.rb
55
+ test/test_generator_helper.rb
56
+ test/test_helper.rb
57
+ test/test_skynet.rb
58
+ test/test_skynet_install_generator.rb
59
+ test/tuplespace_message_queue_test.rb
60
+ tmtags
61
+ website/index.html
62
+ website/index.txt
63
+ website/javascripts/rounded_corners_lite.inc.js
64
+ website/stylesheets/screen.css
65
+ website/template.rhtml
@@ -0,0 +1,100 @@
1
+ Skynet
2
+ http://skynet.rubyforge.org/
3
+ by Adam Pisoni
4
+
5
+ == DESCRIPTION:
6
+
7
+ Skynet is an open source Ruby implementation of Google's Map/Reduce framework, created at Geni. With Skynet, one can easily convert a time-consuming serial task, such as a computationally expensive Rails migration, into a distributed program running on many computers.
8
+
9
+ Skynet is an adaptive, self-upgrading, fault-tolerant, and fully distributed system with no single point of failure. It uses a "peer recovery" system where workers watch out for each other. If a worker dies or fails for any reason, another worker will notice and pick up that task. Skynet also has no special 'master' servers, only workers which can act as a master for any task at any time. Even these master tasks can fail and will be picked up by other workers.
10
+
11
+ == INSTALLATION:
12
+
13
+ Skynet can be installed via RubyGems:
14
+
15
+ $ sudo gem install skynet
16
+
17
+ == GETTING STARTED
18
+ Skynet works by putting "tasks" on a message queue which are picked up by skynet workers, who execute the tasks, then put their results back on the message queue. Skynet works best when it runs with your code. For example, you might have a rails app and want some code you've already written to run asynchronously or in a distributed way. Skynet can run within your code by installing a skynet launcher into your app. Running this skynet launcher within your app guarantees all skynet workers will have access to your code. This will be covered later.
19
+
20
+ Skynet currently supports 2 message queue systems, TupleSpace and Mysql. By default, the TupleSpace queue is used as it is the easiest to set up, though it is less powerful and less scaleable for large installations.
21
+
22
+ == RUNING SKYNET FOR THE FIRST TIME
23
+ Since Skynet is a distributed system, it requires you have a skynet message queue as well as any number of skynet workers running. To start a skynet message queue and a small number of workers:
24
+
25
+ $ skynet
26
+
27
+ This starts a skynet tuple space message queue and 4 workers. You can now run the Skynet Console to play with skynet a little.
28
+
29
+ $ skynet_console
30
+
31
+ Here are some commands you can run.
32
+ > stats
33
+ > manager.worker_pids
34
+ > [1,2,3,1,1,4].mapreduce(Skynet::MapreduceTest)
35
+
36
+ That last command actually took whatever array you gave it and counted the number of times each element appeared in the array. It's not a very useful task, but it shows how easy it is to use.
37
+
38
+ == RUNING SKYNET IN YOUR APPLICATION
39
+
40
+ To be really useful, you'll want to run skynet in your own application. To do that run:
41
+
42
+ $ skynet_install [--rails] YOUR_APP_DIRECTORY
43
+
44
+ If you pass --rails it will assume it is installing in a rails app. Once it is installed in your application, you can run skynet with
45
+
46
+ $ ./script/skynet
47
+ $ ./script/skynet_console
48
+
49
+ == USAGE:
50
+
51
+ Skynet was designed to make doing easy things easy and hard things possible. The easiest way to use skynet is to create a new class with a self.map class method. You can optionally include self.reduce, self.reduce_partitioner, self.map_partitioner as well. Each of those methods should expect a single array (regardless of what data you pass). Then, simple create an array and call mapreduce on it passing your class name. Skynet will figure out which methods your class supports and use them accordingly.
52
+
53
+ == USING SKYNET IN RAILS
54
+
55
+ Skynet includes an addition to ActiveRecord that is very powerful.
56
+
57
+ === distributed_find
58
+ $ YourModel.distributed_find(:all).each(YourClass)
59
+ or
60
+ $ YourModel.distributed_find(:all).each(:somemethod)
61
+
62
+ In the first example, a find is 'virtually' run with your model class, and the results are distributed to the skynet workers. If you've implemented a self.map method in YourClass, the retrieved objects will be passed (as arrays) on all the workers.
63
+
64
+ In the second example, once the objects of YourModel are distributed, each worker merely calls :somemethod against each object.
65
+
66
+ === send_later
67
+
68
+ $ model_object.send_later(:method,options,:save)
69
+
70
+ Sometimes you have a method you want to call on a model asynchronously. Using :send_later you can call a method, pass it options, and decide whether you want Skynet to save that model or not once its done calling your method.
71
+
72
+ == EXAMPLES:
73
+
74
+ == LIMITATIONS:
75
+
76
+
77
+ == LICENSE:
78
+
79
+ (The MIT License)
80
+
81
+ Copyright (c) 2007 Adam Pisoni, Geni.com
82
+
83
+ Permission is hereby granted, free of charge, to any person obtaining
84
+ a copy of this software and associated documentation files (the
85
+ "Software"), to deal in the Software without restriction, including
86
+ without limitation the rights to use, copy, modify, merge, publish,
87
+ distribute, sublicense, and/or sell copies of the Software, and to
88
+ permit persons to whom the Software is furnished to do so, subject to
89
+ the following conditions:
90
+
91
+ The above copyright notice and this permission notice shall be
92
+ included in all copies or substantial portions of the Software.
93
+
94
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
95
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
96
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
97
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
98
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
99
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
100
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,84 @@
1
+ class SkynetInstallGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :author => nil
7
+ default_options :in_rails => nil
8
+ default_options :include_migration => false
9
+
10
+ attr_reader :name
11
+ attr_reader :in_rails
12
+ attr_reader :include_migration
13
+
14
+ def initialize(runtime_args, runtime_options = {})
15
+ super
16
+ usage if args.empty?
17
+ @destination_root = File.expand_path(args.shift)
18
+ @name = base_name
19
+ extract_options
20
+ end
21
+
22
+ def manifest
23
+ record do |m|
24
+ # Ensure appropriate folder(s) exists
25
+ m.directory 'script'
26
+ BASEDIRS.each { |path| m.directory path }
27
+
28
+ # Create stubs
29
+ # m.template "template.rb", "some_file_after_erb.rb"
30
+ m.template "skynet", "script/skynet", :assigns => {:rails => @rails}, :collision => :ask, :chmod => 0755, :shebang => options[:shebang]
31
+ m.template "skynet_console", "script/skynet_console", :assigns => {:rails => @rails}, :collision => :ask, :chmod => 0755, :shebang => options[:shebang]
32
+ if include_migration
33
+ m.directory 'db/migrate'
34
+ m.migration_template "migration.rb", "db/migrate", :collision => :skip, :assigns => {
35
+ :migration_name => "CreateSkynetTables"
36
+ }, :migration_file_name => "create_skynet_tables"
37
+ end
38
+ # m.dependency "install_rubigen_scripts", [destination_root, 'skynet_install'],
39
+ # :shebang => options[:shebang], :collision => :force
40
+ end
41
+ end
42
+
43
+ protected
44
+ def banner
45
+ <<-EOS
46
+ Creates a ...
47
+
48
+ USAGE: #{spec.name} [--rails] directory (can be '.' for current)"
49
+ EOS
50
+ end
51
+
52
+ def add_options!(opts)
53
+ opts.separator ''
54
+ opts.separator 'Options:'
55
+ # For each option below, place the default
56
+ # at the top of the file next to "default_options"
57
+ # opts.on("-a", "--author=\"Your Name\"", String,
58
+ # "Some comment about this option",
59
+ # "Default: none") { |options[:author]| }
60
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
61
+ opts.on("--include-migration",
62
+ "Include mysql migration if you want to use mysql as your message queue") { |options[:include_migration]| }
63
+ opts.on("-r", "--rails",
64
+ "Install into rails app",
65
+ "Default: false") { |options[:rails]| }
66
+ end
67
+
68
+ def extract_options
69
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
70
+ # Templates can access these value via the attr_reader-generated methods, but not the
71
+ # raw instance variable value.
72
+ # @author = options[:author]
73
+ @in_rails = options[:rails]
74
+ @include_migration = options[:include_migration]
75
+ end
76
+
77
+ # Installation skeleton. Intermediate directories are automatically
78
+ # created so don't sweat their absence here.
79
+ BASEDIRS = %w(
80
+ log
81
+ script
82
+ db/migrate
83
+ )
84
+ end
@@ -0,0 +1,60 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :skynet_worker_queues do |t|
4
+ t.column :id, "bigint unsigned primary key"
5
+ t.column :created_on, :timestamp
6
+ t.column :updated_on, :timestamp
7
+ t.column :tasktype, :string
8
+ t.column :tasksubtype, :string
9
+ t.column :worker_id, 'bigint unsigned'
10
+ t.column :hostname, :string
11
+ t.column :process_id, :integer
12
+ t.column :job_id, 'bigint unsigned'
13
+ t.column :task_id, 'bigint unsigned'
14
+ t.column :iteration, :integer
15
+ t.column :name, :string
16
+ t.column :map_or_reduce, :string
17
+ t.column :started_at, "decimal(16,4)"
18
+ t.column :version, :integer
19
+ t.column :processed, :integer
20
+ t.column :timeout, "decimal(16,4)"
21
+ end
22
+ create_table :skynet_message_queues do |t|
23
+ t.column :id, "bigint unsigned primary key"
24
+ t.column :created_on, :timestamp
25
+ t.column :updated_on, :timestamp
26
+ t.column :tasktype, :string
27
+ t.column :task_id, 'bigint unsigned'
28
+ t.column :job_id, 'bigint unsigned'
29
+ t.column :raw_payload, :text
30
+ t.column :payload_type, :string
31
+ t.column :name, :string
32
+ t.column :expiry, :integer
33
+ t.column :expire_time, "decimal(16,4)"
34
+ t.column :iteration, :integer
35
+ t.column :version, :integer
36
+ t.column :timeout, "decimal(16,4)"
37
+ end
38
+ create_table :skynet_queue_temperature do |t|
39
+ t.column :id, "bigint unsigned primary key"
40
+ t.column :updated_on, :timestamp
41
+ t.column :count, :integer, :default => 0
42
+ t.column :temperature, "decimal(6,4) default 1"
43
+ t.column :type, :string
44
+ end
45
+ add_index :skynet_message_queues, [:job_id]
46
+ add_index :skynet_message_queues, :task_id
47
+ add_index :skynet_message_queues, [:tasktype,:payload_type,:expire_time], :name => "index_skynet_mqueue_for_take"
48
+ add_index :skynet_worker_queues, [:hostname, :process_id]
49
+ add_index :skynet_worker_queues, :worker_id, :unique=> true
50
+ execute "insert into skynet_queue_temperature (type) values ('master')"
51
+ execute "insert into skynet_queue_temperature (type) values ('any')"
52
+ execute "insert into skynet_queue_temperature (type) values ('task')"
53
+ end
54
+
55
+ def self.down
56
+ drop_table :skynet_worker_queues
57
+ drop_table :skynet_queue_temperature
58
+ drop_table :skynet_message_queues
59
+ end
60
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ <% if in_rails %>
4
+ require File.dirname(__FILE__) + '/../config/boot'
5
+ require File.expand_path(File.dirname(__FILE__)) + '/../config/environment'
6
+ <% end %>
7
+
8
+ require 'skynet'
9
+
10
+ Skynet::CONFIG[:LAUNCHER_PATH] = File.expand_path(__FILE__)
11
+ Skynet::CONFIG[:SKYNET_LOG_FILE] = Logger::ERROR
12
+ Skynet::CONFIG[:SKYNET_LOG_LEVEL] = Logger::ERROR
13
+ <% if in_rails %>
14
+ Skynet::CONFIG[:SKYNET_PIDS_FILE] = File.expand_path("../log/skynet.pid"),
15
+ Skynet::CONFIG[:SKYNET_LOG_FILE] = File.expand_path("../log/skynet.log"),
16
+ <% else %>
17
+ Skynet::CONFIG[:SKYNET_PIDS_FILE] = File.expand_path("#{RAILS_ROOT}/log/skynet_#{RAILS_ENV}.pid"),
18
+ Skynet::CONFIG[:SKYNET_LOG_FILE] = File.expand_path("#{RAILS_ROOT}/log/skynet_#{RAILS_ENV}.log"),
19
+ <% end %>
20
+
21
+ begin
22
+ mq = Skynet::MessageQueue.new
23
+ rescue Skynet::ConnectionError
24
+ if Skynet::MessageQueue.adapter == :tuplespace
25
+ pid = fork do
26
+ exec("skynet_tuplespace_server start")
27
+ end
28
+ sleep 3
29
+ end
30
+ end
31
+
32
+
33
+ Skynet.new
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ files_to_require = []
4
+ <% if in_rails %>
5
+ files_to_require << File.dirname(__FILE__) + '/../config/boot'
6
+ files_to_require << File.expand_path(File.dirname(__FILE__)) + '/../config/environment'
7
+ files_to_require.each { |file| require file }
8
+ <% end %>
9
+
10
+ require 'rubygems'
11
+ require 'skynet'
12
+
13
+ Skynet::CONFIG[:LAUNCHER_PATH] = File.expand_path(__FILE__)
14
+ Skynet::CONFIG[:SKYNET_LOG_LEVEL] = Logger::ERROR
15
+
16
+ Skynet::Console.start(files_to_require)
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__)) + '/../lib/skynet.rb'
4
+
5
+ Skynet::CONFIG[:WORKER_CHECK_DELAY] = 4
6
+ Skynet::CONFIG[:LAUNCHER_PATH] = File.expand_path(__FILE__)
7
+
8
+ begin
9
+ mq = Skynet::MessageQueue.new
10
+ rescue Skynet::ConnectionError
11
+ if Skynet::MessageQueue.adapter == :tuplespace
12
+ pid = fork do
13
+ exec("skynet_tuplespace_server start")
14
+ end
15
+ sleep 3
16
+ end
17
+ end
18
+
19
+
20
+ Skynet.new
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require File.expand_path(File.dirname(__FILE__)) + '/../lib/skynet.rb'
5
+
6
+ Skynet::CONFIG[:LAUNCHER_PATH] = File.expand_path(__FILE__)
7
+ Skynet::CONFIG[:SKYNET_LOG_LEVEL] = Logger::ERROR
8
+
9
+ Skynet::Console.start
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rubigen'
3
+
4
+ if %w(-v --version).include? ARGV.first
5
+ require 'skynet_install/version'
6
+ puts "#{File.basename($0)} #{SkynetInstall::VERSION::STRING}"
7
+ exit(0)
8
+ end
9
+
10
+ require 'rubigen/scripts/generate'
11
+ RubiGen::Base.use_application_sources! :skynet_install
12
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'skynet_install')