Skip to content

Commit

Permalink
Auto Detect Heroku Dyno Size
Browse files Browse the repository at this point in the history
If you're on Heroku and you're not manually setting your RAM size, we'll now automagically set the RAM value to the right number. This is an experimental feature.
  • Loading branch information
schneems committed Sep 4, 2014
1 parent 08a727a commit 64cef52
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PumaAutoTune.config do |config|
end
```

The default is `512` which matches the amount of ram available on a Heroku dyno. There are a few other advanced config options:
We will attempt to detect your RAM size if you are running on Heroku. If we cannot, the default is `512` mb. There are a few other advanced config options:

```ruby
PumaAutoTune.config do |config|
Expand Down
21 changes: 21 additions & 0 deletions bin/heroku_ulimit_to_ram
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

limit=$(ulimit -u)

case $limit in
256)
ram=512
;;
512)
ram=1024
;;
32768)
ram=8192
;;
*)
echo 'nope';
exit 1;
;;
esac

echo $ram
13 changes: 12 additions & 1 deletion lib/puma_auto_tune.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ module PumaAutoTune

extend self

def self.default_ram
result = `bin/heroku_ulimit_to_ram`
default = if $?.success?
Integer(result)
else
512
end
puts "Default RAM set to #{default}"
default
end

attr_accessor :ram, :max_worker_limit, :frequency, :reap_duration
self.ram = 512 # mb
self.ram = self.default_ram # mb
self.max_worker_limit = INFINITY
self.frequency = 10 # seconds
self.reap_duration = 90 # seconds
Expand Down

0 comments on commit 64cef52

Please sign in to comment.