Register HttpServer's RubyHttpConnection object with the garbage coll… · abonec/evma_httpserver@59e052d · GitHub
Skip to content

Commit 59e052d

Browse files
committed
Register HttpServer's RubyHttpConnection object with the garbage collector
Currently, if a class overrides the 'unbind' method, the RubyHttpConnection object in each connection object will be leaked. Similarly, if no one ever calls 'unbind' on the HttpServer, the RubyHttpConnection will be leaked on garbage collection. For example, the following program has a memory leak: """ require 'rubygems'; require 'eventmachine'; require 'evma_httpserver' class MyServer < EM::Connection include EM::HttpServer def unbind; end end EM.run do EM.start_server '127.0.0.1', 9000, MyServer end """ As does the following: """ require 'rubygems'; require 'eventmachine'; require 'evma_httpserver' class MyServer < EM::Connection include EM::HttpServer end 10000.times { MyServer.new 1 } """ This patch moves destruction of the RubyHttpConnection object from the unbind method to the garbage collector. One may wonder about the performance implications of this patch. As a rough estimate, on my quad-core/16 GB RAM desktop, I ran time for i in $(seq 1 10000); do curl localhost:9000; done with and without this patch against the following server program: """ require 'rubygems'; require 'eventmachine'; require 'evma_httpserver' class MyServer < EM::Connection; include EM::HttpServer; end EM.run { EM.start_server '0.0.0.0', 9000, MyServer } """ Results are shown below. [Without this patch (8e20269)] $ time ( for i in $(seq 1 10000); do curl 127.0.0.1:9000; done >/dev/null 2>/dev/null ) real 0m57.654s user 0m2.770s sys 0m3.230s [With this patch] $ time ( for i in $(seq 1 10000); do curl 127.0.0.1:9000; done >/dev/null 2>/dev/null ) real 0m55.123s user 0m2.550s sys 0m3.240s
1 parent 8e20269 commit 59e052d

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

ext/rubyhttp.cpp

Lines changed: 33 additions & 7 deletions

0 commit comments

Comments
 (0)