App running mode to Rails to better gem & dependencies loading..

Hej,

I added a “app running mode” for my rails application… Class “AppRunningMode”

it return an array of bundler_groups witch i add to Bundler.require(*Rails.groups)…

Based on that i can handle bundle dependencies much better… Saved my 17 MB per unicorn instance… & 40MB per resque worker instance.

Would you be interested to get a pull request?

Changes:

Gemfile

source ‘https://rubygems.org

Bundle edge Rails instead: gem ‘rails’, github: ‘rails/rails’

gem ‘rails’, ‘4.2.6’

Use postgresql as the database for Active Record

gem ‘pg’, ‘~> 0.15’

group :assets do

Use SCSS for stylesheets

gem ‘sass-rails’, ‘~> 5.0’

Use Uglifier as compressor for JavaScript assets

gem ‘uglifier’, ‘>= 1.3.0’

Use CoffeeScript for .coffee assets and views

gem ‘coffee-rails’, ‘~> 4.1.0’

See https://github.com/rails/execjs#readme for more supported runtimes

gem ‘therubyracer’, platforms: :ruby

Use jquery as the JavaScript library

gem ‘jquery-rails’

end

group :server do

Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder

gem ‘jbuilder’, ‘~> 2.0’

gem ‘json’, ‘>= 1.8.3’

gem ‘oj’, ‘>= 2.14.0’

gem ‘oj_mimic_json’

end

group :assets, :server do

Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks

gem ‘turbolinks’

end

group :assets, :server, :rake do

gem ‘sprockets-rails’

end

gem ‘unicorn’

gem ‘resque’


group :resque_worker do

gem ‘savon’, ‘~> 2.2’

end

group :rake do

gem ‘net-sftp’, :require => ‘net/sftp’

end

group :server_development do

gem ‘better_errors’

gem ‘binding_of_caller’

gem ‘xray-rails’

gem ‘rails-footnotes’

end

``

AppRunningMode:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

class AppRunningMode

``class << ``self

``def resque_worker?

``( ``ARGV & [``"resque:work"``, ``"resque:worker"``]).any?

``end

``def assets?

``( ``ARGV & [``"assets:precompile"``, ``"rake assets:environment"``]).any? || (server? && !Rails.env.production?)

``end

``def console?

``defined``?(Rails::Console)

``end

``def server?

``defined``?(Rails::Server) || unicorn?

``end

``def executable

``@executable ||= ``$0``.split(``' '``).first.split(``'/'``).last

``end

``def match_executable?(name)

``executable == name.to_s

``end

``def irb?

``match_executable?(``:irb``)

``end

``def unicorn?

``match_executable?(``:unicorn_rails``)

``end

``def spring?

``match_executable?(``:spring``)

``end

``def rake?

``match_executable?(``:rake``)

``end

``def values

``@values ||= []

``@values |= [``:server``] ``if server?

``@values |= [``:assets``] ``if assets?

``@values |= [``:resque_worker``] ``if resque_worker?

``@values |= [``:console``] ``if console?

``@values |= [``:rake``] ``if rake?

``@values |= [``:irb``] ``if irb?

``@values |= [``:spring``] ``if spring?

``@values

``end

``def bundler_groups

``values.collect{|v| [v, ``"#{v}_#{Rails.env}"``.to_sym] }.flatten

``end

``end

end

Code hier eingeben…