From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7BF94208AE; Fri, 18 Jul 2014 00:33:20 +0000 (UTC) Date: Fri, 18 Jul 2014 00:33:20 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] http_client: clear some internal ivars on rack.hijack Message-ID: <20140718003320.GA14749@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: 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. --- Just pushed this out to git://yhbt.net/yahns (commit 3c56a143fe2ef00716b89dd2f115cf8ea24a7d8c) Disclaimer: I haven't tested hijack outside of the included test cases, I only use the normal HTTP stuff lynx and curl can handle :) lib/yahns/http_client.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 -- EW