yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
* [PATCH] http_client: clear some internal ivars on rack.hijack
@ 2014-07-18  0:33 Eric Wong
  2014-07-18  0:45 ` Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2014-07-18  0:33 UTC (permalink / raw)
  To: yahns-public

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] http_client: clear some internal ivars on rack.hijack
  2014-07-18  0:33 [PATCH] http_client: clear some internal ivars on rack.hijack Eric Wong
@ 2014-07-18  0:45 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2014-07-18  0:45 UTC (permalink / raw)
  To: yahns-public

Eric Wong <e@80x24.org> wrote:
> 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.

Also, in the future I hope to make the HTTP parser + env thread-local
in the common case like the current read buffer.  This should save
some memory for idle clients and only use more memory with slow
clients.

That's more work, though.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-07-18  0:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-18  0:33 [PATCH] http_client: clear some internal ivars on rack.hijack Eric Wong
2014-07-18  0:45 ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).