sprockets-rails-parallel 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Shopify Inc
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.md ADDED
@@ -0,0 +1,13 @@
1
+ # sprockets-rails-parallel
2
+
3
+ sprockets-rails-parallel is a dirty monkeypatchy hack to make `sprockets-rails` use many processes when precompiling assets. It uses zmq, so you'll need that.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your gemfile and then in your `config/application.rb` or one of your environment files, add the following lines:
8
+
9
+ ```ruby
10
+ config.assets.parallel_precompile = true
11
+ config.assets.precompile_workers = Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1 # or something like this
12
+ ```
13
+
@@ -0,0 +1,81 @@
1
+ require 'ffi-rzmq'
2
+
3
+ module Sprockets
4
+ module Rails
5
+ class StaticCompiler
6
+ KILL_MESSAGE = "die die die!!!!"
7
+
8
+ def compile_with_workers
9
+ unless ::Rails.application.config.assets.parallel_compile
10
+ return compile_without_workers
11
+ end
12
+
13
+ worker_count = (Rails.application.config.assets.compile_workers || 4).to_i
14
+
15
+ paths = env.each_logical_path.reject {|logical_path| !compile_path?(logical_path)}
16
+ total_count = paths.length
17
+ manifest = {}
18
+
19
+ begin
20
+ workers = 1.upto(worker_count).map do
21
+ fork do
22
+ child_context = ZMQ::Context.new(1)
23
+ child_receiver = child_context.socket(ZMQ::PULL)
24
+ child_sender = child_context.socket(ZMQ::PUSH)
25
+ child_receiver.connect("tcp://127.0.0.1:55546")
26
+ child_sender.connect("tcp://127.0.0.1:55547")
27
+
28
+ # Send synchronization string
29
+ child_sender.send_string(Process.pid.to_s)
30
+
31
+ loop do
32
+ # Allocate, 0mq requires it. (lol)
33
+ begin
34
+ child_receiver.recv_string(logical_path = "")
35
+ rescue Interrupt
36
+ exit
37
+ end
38
+ if logical_path == KILL_MESSAGE
39
+ exit
40
+ elsif asset = env.find_asset(logical_path)
41
+ child_sender.send_string(Marshal.dump(Hash[logical_path, write_asset(asset)]))
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ context = ZMQ::Context.new(1)
48
+ sender = context.socket(ZMQ::PUSH)
49
+ receiver = context.socket(ZMQ::PULL)
50
+ sender.bind("tcp://127.0.0.1:55546")
51
+ receiver.bind("tcp://127.0.0.1:55547")
52
+
53
+ # Sync workers by blocking on a recieve from each one
54
+ worker_count.times do
55
+ pid = ''
56
+ receiver.recv_string(pid)
57
+ end
58
+
59
+ paths.each do |path|
60
+ sender.send_string(path)
61
+ end
62
+
63
+ total_count.times do |x|
64
+ receiver.recv_string(string = "")
65
+ result = Marshal.load(string)
66
+ manifest.update result
67
+ end
68
+
69
+ ensure
70
+ if workers
71
+ workers.each {|pid| sender.send_string(KILL_MESSAGE) }
72
+ end
73
+ end
74
+
75
+ manifest
76
+ end
77
+
78
+ alias_method_chain :compile, :workers
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ require 'sprockets'
2
+ require 'sprockets-rails'
3
+ require 'sprockets/rails/static_compiler_extensions.rb'
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-rails-parallel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Harry Brundage
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sprockets
16
+ requirement: &70315233391340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70315233391340
25
+ - !ruby/object:Gem::Dependency
26
+ name: ffi-rzmq
27
+ requirement: &70315233390860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.3
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70315233390860
36
+ - !ruby/object:Gem::Dependency
37
+ name: sprockets-rails
38
+ requirement: &70315233390480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70315233390480
47
+ description: ''
48
+ email: harry.brundage@jadedpixel.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/sprockets/rails/static_compiler_extensions.rb
54
+ - lib/sprockets-rails-parallel.rb
55
+ - LICENSE
56
+ - README.md
57
+ homepage: https://github.com/hornairs/sprockets-rails-parallel
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.11
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Precompile them assets with the power of modern computing!
81
+ test_files: []