Skip to content

Commit

Permalink
Attempt at demonstrating the memory leak in ruby-grape#2102 with remo…
Browse files Browse the repository at this point in the history
…unting.
  • Loading branch information
dblock committed Sep 16, 2020
1 parent d40d697 commit 5197abf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ end
group :development do
gem 'appraisal'
gem 'benchmark-ips'
gem 'benchmark-memory'
gem 'guard'
gem 'guard-rspec'
gem 'guard-rubocop'
Expand Down
53 changes: 53 additions & 0 deletions benchmark/remounting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'grape'
require 'benchmark/memory'

class VotingApi < Grape::API
logger Logger.new(STDOUT)

helpers do
def logger
VotingApi.logger
end
end

namespace 'votes' do
get do
logger
end
end
end

class PostApi < Grape::API
mount VotingApi
end

class CommentAPI < Grape::API
mount VotingApi
end

env = Rack::MockRequest.env_for('/votes', method: 'GET')

PostApi.call(env)
CommentAPI.call(env)

calls = 1000

Benchmark.memory do |api|
api.report('remounting first') do
calls.times { PostApi.call(env) }
end

api.report('remounting second') do
calls.times { CommentAPI.call(env) }
end

api.report('remounting both') do
calls.times do
PostApi.call(env)
CommentAPI.call(env)
end
end

api.compare!
end

0 comments on commit 5197abf

Please sign in to comment.