Permalink
Browse files

Upgraded to Ruby 2.1.1.

  • Loading branch information...
1 parent b74c9de commit ebf98e2880ed73ee287649d26243bcbcca3930b0 @benubois benubois committed Mar 19, 2014
Showing with 11 additions and 126 deletions.
  1. +3 −2 Gemfile
  2. +4 −2 Gemfile.lock
  3. +4 −0 config.ru
  4. +0 −2 config/initializers/unicorn.rb
  5. +0 −120 lib/unicorn_oobgc.rb
View
@@ -1,5 +1,5 @@
source 'https://rubygems.org'
-ruby '2.0.0'
+ruby '2.1.1'
gem 'rails', '~>4.0.0'
@@ -20,7 +20,7 @@ gem 'unicorn'
gem 'opml_saw', github: 'feedbin/opml_saw', ref: '61d8c2d'
gem 'feedzirra', github: 'feedbin/feedzirra', ref: '6d57e27'
-gem 'html-pipeline', github: 'benubois/html-pipeline', ref: '13aaf6d'
+gem 'html-pipeline', github: 'benubois/html-pipeline', ref: 'f367d91'
gem 'grocer-pushpackager', github: 'feedbin/grocer-pushpackager', ref: 'e190796', require: 'grocer/pushpackager'
gem 'html_diff', github: 'feedbin/html_diff', ref: 'c7c15ce'
@@ -55,6 +55,7 @@ gem 'lograge'
gem 'tire'
gem 'grocer'
gem 'cocoon'
+gem 'gctools', require: false
# Sidekiq
gem 'sidekiq'
View
@@ -1,7 +1,7 @@
GIT
remote: git://github.com/benubois/html-pipeline.git
- revision: 13aaf6d17148b519879d7d97c1b92e97dadfad7c
- ref: 13aaf6d
+ revision: f367d912a01fad495402a2597a5a1cabb8529d42
+ ref: f367d91
specs:
html-pipeline (1.1.0)
activesupport (>= 2)
@@ -156,6 +156,7 @@ GEM
dotenv (>= 0.7)
thor (>= 0.13.6)
formatador (0.2.4)
+ gctools (0.2.3)
grocer (0.5.0)
hashie (1.2.0)
hashr (0.0.22)
@@ -340,6 +341,7 @@ DEPENDENCIES
feedzirra!
fog
foreman
+ gctools
grocer
grocer-pushpackager!
honeybadger
View
@@ -1,4 +1,8 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
+require 'gctools/oobgc'
+if defined?(Unicorn::HttpRequest)
+ use GC::OOB::UnicornMiddleware
+end
run Feedbin::Application
@@ -1,2 +0,0 @@
-require 'unicorn_oobgc'
-Middleware::UnicornOobgc.init
View
@@ -1,120 +0,0 @@
-# THIS FILE IS TO BE EXTRACTED FROM DISCOURSE IT IS LICENSED UNDER THE MIT LICENSE
-#
-# The MIT License (MIT)
-#
-# Copyright (c) 2013 Discourse
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-# Hook into unicorn, unicorn middleware, not rack middleware
-#
-# Since we need no knowledge about the request we can simply
-# hook unicorn
-module Middleware
- module UnicornOobgc
-
- MIN_REQUESTS_PER_OOBGC = 3
-
- # TUNE ME, for Discourse this number is good
- MIN_FREE_SLOTS = 50_000
-
- def verbose(msg=nil)
- @verbose ||= ENV["OOBGC_VERBOSE"] == "1" ? :true : :false
- if @verbose == :true
- if(msg)
- puts msg
- end
-
- true
- end
- end
-
- def self.init
- # hook up HttpServer intercept
- ObjectSpace.each_object(Unicorn::HttpServer) do |s|
- s.extend(self)
- end
- rescue
- puts "Attempted to patch Unicorn but it is not loaded"
- end
-
- # the closer this is to the GC run the more accurate it is
- def estimate_live_num_at_gc(stat)
- stat[:heap_live_num] + stat[:heap_free_num]
- end
-
- def process_client(client)
- stat = GC.stat
-
- @num_requests ||= 0
- @num_requests += 1
-
- gc_count = stat[:count]
- live_num = stat[:heap_live_num]
-
- @expect_gc_at ||= estimate_live_num_at_gc(stat)
-
- super(client) # Unicorn::HttpServer#process_client
-
- # at this point client is serviced
- stat = GC.stat
- new_gc_count = stat[:count]
- new_live_num = stat[:heap_live_num]
-
- # no GC happened during the request
- if new_gc_count == gc_count
- delta = new_live_num - live_num
-
- @max_delta ||= delta
-
- if delta > @max_delta
- new_delta = (delta * 1.5).to_i
- @max_delta = [new_delta, delta].min
- else
- # this may seem like a very tiny decay rate, but some apps using caching
- # can really mess stuff up, if our delta is too low the algorithm fails
- new_delta = (delta * 0.995).to_i
- @max_delta = [new_delta, delta].max
- end
-
- if @max_delta < MIN_FREE_SLOTS
- @max_delta = MIN_FREE_SLOTS
- end
-
- if @num_requests > MIN_REQUESTS_PER_OOBGC && @max_delta * 2 + new_live_num > @expect_gc_at
- t = Time.now
- GC.start
- stat = GC.stat
- @expect_gc_at = estimate_live_num_at_gc(stat)
- verbose "OobGC hit pid: #{Process.pid} req: #{@num_requests} max delta: #{@max_delta} expect at: #{@expect_gc_at} #{((Time.now - t) * 1000).to_i}ms saved"
- @num_requests = 0
- end
- else
-
- verbose "OobGC miss pid: #{Process.pid} reqs: #{@num_requests} max delta: #{@max_delta}"
-
- @num_requests = 0
- @expect_gc_at = estimate_live_num_at_gc(stat)
-
- end
-
- end
-
- end
-end

0 comments on commit ebf98e2

Please sign in to comment.