Skip to content

Instantly share code, notes, and snippets.

View schneems's full-sized avatar

Richard Schneeman schneems

View GitHub Profile

It's complicated. Probably what they were seeing was that mime-types was directly allocating a chunk of memory, let's say 8mb.

Now what could happen is if they app is on the edge of needing to increase it's own heap size, then the mime-types gem might push it over the edge.

For example. You have an app that needs 99mb to run. The Ruby VM allocates up to 100mb for it to run in. Now mime-types get's allocated and suddenly it needs 107mb to run. So Ruby has to increase the heap, it does this based off of a multiplier, for example 80% so it bumps the heap up to 180mb even though we really only need 107mb.

That might be what's happening and why they're seeing such a huge savings.

@schneems
schneems / .rb
Created November 23, 2015 19:54
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', github: "rails/rails"
gem 'arel', github: "rails/arel"
gem "rack", github: "rack/rack"
gem "sprockets", github: "rails/sprockets"
gem "sprockets-rails", github: "rails/sprockets-rails"
gem 'coffee-rails', github: "rails/coffee-rails"
This file has been truncated, but you can view the full file.
$ bundle exec foreman start
12:46:28 web.1 | started with pid 5807
12:46:28 web.1 | [5807] Puma starting in cluster mode...
12:46:28 web.1 | [5807] * Version 2.11.1 (ruby 2.2.2-p95), codename: Intrepid Squirrel
12:46:28 web.1 | [5807] * Min threads: 8, max threads: 32
12:46:28 web.1 | [5807] * Environment: development
12:46:28 web.1 | [5807] * Process workers: 4
12:46:28 web.1 | [5807] * Preloading application
12:46:28 web.1 | [5807] * Listening on tcp://0.0.0.0:9292
12:46:28 web.1 | [5807] ! WARNING: Detected 1 Thread(s) started in app boot:
@schneems
schneems / gist:e09c95da37a8c50047a8
Created May 12, 2015 18:23
Find 50 most popular Gems that have mime-types as a dependency
require 'net/http'
require 'json'
def rubygems_get(gem_name: "", endpoint: "")
path = File.join("/api/v1/gems/", gem_name, endpoint).chomp("/") + ".json"
JSON.parse(Net::HTTP.get("rubygems.org", path))
end
results = rubygems_get(gem_name: "mime-types", endpoint: "reverse_dependencies")
Thread.new do
begin
while true
sleep
end
ensure
puts "it's a TRAP"
end
end
Process.kill("TERM", Process.pid)

Thanks for being a part of CodeTriage we've got some news to share!

DocsDoctor.org

We're excited to announce the launch of DocsDoctor.org, it's like CodeTriage for docs! Select a project and you'll get documented methods right in your inbox. If you're really adventurous, find gaps by receiving undocumented methods. Get easy commits and make open source a better place by writing docs.

Be a better programmer: Sign up for DocsDoctor today!

Ruby Hero 2015 Voting

source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.0.alpha', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
@schneems
schneems / gist:c07d93d5a4ade679bbc3
Last active May 15, 2018 09:38
Puma Backlog Setting on Heroku

Why not set backlog on Heroku?

First read this: https://mikecoutermarsh.com/adjusting-pumas-backlog-for-heroku/

Now we're on the same page. Heroku will re-route bounced requests from your dynos but it assumes when this happens that your entire app is saturated. https://devcenter.heroku.com/articles/http-routing#dyno-connection-behavior. Each connection gets delayed by 5 seconds, so you're automatically being docked 5 seconds per request.

If you're setting your backlog to a low value (i.e. if you'll ever actually ever hit backlog) then you'll be in for pain. When you get a spike of requests from slashdot/reddit/whatever you're telling your dynos that you would rather they failed then returned slow responses. So this does mean that some requests will be served, but all the others will fail.

If your app ever hits your backlog (no matter what value it is) it is an indicator you don't have enough throughput and you need to scale out to more dynos. If you set this to an arbitrarilly low value, that point comes

TIL attr_* methods are optomized.

class Whatever
  def foo
    @foo
  end

  attr_reader :bar
end