mrtuner 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8305815fcc0e41633ebd95f3c88069302dda829e
4
+ data.tar.gz: 6f45b0ae8d08448d6ef06155784d98272153daa4
5
+ SHA512:
6
+ metadata.gz: e1e2b000cebb3440ea1a41ec1d263ee19d189098d66664afc17cd414f00a3ea072a4b51dad936334e3ff473478952ef6de821374b575ffc1398b7bc59ff88cb7
7
+ data.tar.gz: 3f17ff8eeb446c7cfbd44fa4f7f965cb9625852bf5cc3d2bb636965c17f76bbca99e861798b27936a1766df968a2b4135cc3593819d4d4b4e6bd616a187afc0b
data/bin/mrtuner ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mrtuner'
4
+ require 'trollop'
5
+
6
+ p = Trollop::Parser.new do
7
+ opt :type, "Type of Database Server (Web/DW/Mixed/Desktop)", :type => :string, :default => 'web'
8
+ opt :memory, "Amount of Memory on the Server (GiB)", :type => :float
9
+ opt :connections, "Specify the Target Max Connections", :type => :integer
10
+ end
11
+
12
+ opts = Trollop::with_standard_exception_handling p do
13
+ o = p.parse ARGV
14
+ if o[:memory] == nil or o[:connections] == nil
15
+ raise Trollop::HelpNeeded
16
+ end
17
+ o
18
+ end
19
+
20
+ tune = MrTuner.new opts[:type], opts[:memory], { 'connections' => opts[:connections] }
21
+ puts tune.get_config
22
+ tune.display_config
data/contributors.txt ADDED
@@ -0,0 +1 @@
1
+ David Kerr
data/lib/mrtuner.rb ADDED
@@ -0,0 +1,123 @@
1
+ class MrTuner
2
+
3
+ require 'util.rb'
4
+
5
+ def initialize(type, memory, config = {})
6
+ @type = type.downcase
7
+ @memory = memory * 1073741824
8
+ @connections = config['connections']
9
+ @block_size = config.key?("block_size") ? config['block_size'] : 8192
10
+ @wal_block_size = config.key?("wal_block_size") ? config['block_size'] : 8192
11
+ @max_locks_per_transaction = config.key?("max_locks_per_transaction") ? config['max_locks_per_transaction'] : 64
12
+ @autovacuum_max_workers = config.key?("autovacuum_max_workers") ? config['autovacuum_max_workers'] : 3
13
+ @max_prepared_transactions = config.key?("max_prepared_transactions") ? config['max_prepared_transactions'] : 0
14
+ @page_size = config.key?("page_size") ? config['page_size'] : 4096
15
+ end
16
+
17
+ def get_config
18
+ {
19
+ :max_connections => max_connections,
20
+ :maintenance_work_mem => make_round_number(maintenance_work_mem),
21
+ :work_mem => make_round_number(work_mem.round),
22
+ :checkpoint_completion_target => checkpoint_completion_target,
23
+ :shared_buffers => make_round_number(shared_buffers),
24
+ :effective_cache_size => make_round_number(effective_cache_size),
25
+ :checkpoint_segments => checkpoint_segments
26
+ }
27
+ end
28
+
29
+ def display_config
30
+ get_config.each do |k,v|
31
+ case k
32
+ when :maintenance_work_mem,:work_mem,:shared_buffers,:effective_cache_size
33
+ puts "#{k} = #{as_size(v)}"
34
+ else
35
+ puts "#{k} = #{v}"
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+ def max_connections
42
+ return @connections if @connections
43
+ case @type
44
+ when 'oltp'
45
+ @connections = 300
46
+ when 'dw'
47
+ @connections = 20
48
+ when 'mixed'
49
+ @connections = 80
50
+ when 'desktop'
51
+ @connections = 5
52
+ else
53
+ @connections = 200
54
+ end
55
+ end
56
+
57
+ def shared_buffers
58
+ case @type
59
+ when 'oltp','dw','web','mixed'
60
+ @memory / 4
61
+ else
62
+ @memory / 16
63
+ end
64
+ end
65
+
66
+ def effective_cache_size
67
+ # return 134217728 if @memory < 268435456
68
+ # return 2147483648 if @memory < 2147483648
69
+ case @type
70
+ when 'oltp','dw','web','mixed'
71
+ @memory * 0.75
72
+ else
73
+ @memory / 4
74
+ end
75
+ end
76
+
77
+ def work_mem
78
+ case @type
79
+ when 'web', 'oltp'
80
+ @memory / @connections
81
+ when 'dw', 'mixed'
82
+ @memory / @connections / 2
83
+ when 'desktop'
84
+ @memory / @connections / 6
85
+ end
86
+ end
87
+
88
+ def maintenance_work_mem
89
+ case @type
90
+ when 'web', 'oltp', 'mixed', 'desktop'
91
+ mwm = @memory / 16
92
+ when 'dw'
93
+ mwm = @memory / 8
94
+ end
95
+ mwm > 1073741824 ? 1073741824 : mwm
96
+ end
97
+
98
+ def checkpoint_segments
99
+ case @type
100
+ when 'web'
101
+ return 8
102
+ when 'oltp','mixed'
103
+ return 16
104
+ when 'dw'
105
+ return 64
106
+ when 'desktop'
107
+ return 3
108
+ end
109
+ end
110
+
111
+ def checkpoint_completion_target
112
+ case @type
113
+ when 'web'
114
+ 0.7
115
+ when 'oltp', 'dw', 'mixed'
116
+ 0.9
117
+ when 'desktop'
118
+ 0.5
119
+ end
120
+ end
121
+
122
+
123
+ end
data/lib/util.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'filesize'
2
+
3
+ def as_size( s )
4
+ prefix = %W(TB GB MB Kb B).freeze
5
+
6
+ s = s.to_f
7
+ i = prefix.length - 1
8
+ while s > 512 && i > 0
9
+ i -= 1
10
+ s /= 1024
11
+ end
12
+ ((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s).to_f.round.to_s +
13
+ (prefix[i] == 'B' ? '' : prefix[i] )
14
+ end
15
+
16
+ def make_round_number( s )
17
+ #
18
+ # So yeah, this sucks. but PG uses 'GB' nomenclature meaning 'GiB'
19
+ #
20
+ s = as_size(s)
21
+ s.gsub!('TB','TiB')
22
+ s.gsub!('GB','GiB')
23
+ s.gsub!('MB','MiB')
24
+ s.gsub!('KB','KiB')
25
+ Filesize.from(s).to_f('B')
26
+ end
data/license.txt ADDED
@@ -0,0 +1,14 @@
1
+ License
2
+
3
+ mrtuner is licensed under a standard 3-clause BSD license.
4
+ Copyright (c) 2014, David Kerr All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
+
8
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+
10
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mrtuner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - David Kerr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trollop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: filesize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Generates a useful base configuration for PostgreSQL
42
+ email: dave@davidmerr.com
43
+ executables:
44
+ - mrtuner
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/mrtuner
49
+ - contributors.txt
50
+ - lib/mrtuner.rb
51
+ - lib/util.rb
52
+ - license.txt
53
+ homepage: https://bitbucket.org/davidkerr/mrtuner
54
+ licenses:
55
+ - BSD
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.2.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Tunes PostgreSQL Instances
77
+ test_files: []