From 3c56a143fe2ef00716b89dd2f115cf8ea24a7d8c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 18 Jul 2014 00:18:50 +0000 Subject: http_client: clear some internal ivars on rack.hijack We should no longer need HTTP parser or input body upon hijacking. Remove references to it so the GC can clean those up. This relies on the Rack application deleting "rack.input" from the Rack env, too. --- lib/yahns/http_client.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb index 849095e..a294511 100644 --- a/lib/yahns/http_client.rb +++ b/lib/yahns/http_client.rb @@ -224,9 +224,10 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc: http_response_write(status, headers, body) end + # this is the env["rack.hijack"] callback exposed to the Rack app def hijack_proc(env) proc do - self.class.queue.queue_del(self) # EPOLL_CTL_DEL + hijack_cleanup env[RACK_HIJACK_IO] = self end end @@ -253,12 +254,19 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc: end while true end - def response_hijacked(fn) + # allow releasing some memory if rack.hijack is used + def hijack_cleanup # we must issue EPOLL_CTL_DEL before hijacking (if we issue it at all), # because the hijacker may close use before we get back to the epoll worker # loop. EPOLL_CTL_DEL saves about 200 bytes of unswappable kernel memory, # so it can matter if we have lots of hijacked sockets. - self.class.queue.queue_del(self) + self.class.queue.queue_del(self) # EPOLL_CTL_DEL + @input = @input.close if @input + @hs = nil # no need for the HTTP parser anymore + end + + def response_hijacked(fn) + hijack_cleanup fn.call(self) :ignore end -- cgit v1.2.3-24-ge0c7