yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] avoid EPOLL_CTL_DEL calls on rack.hijack
Date: Tue, 17 Mar 2015 09:03:30 +0000	[thread overview]
Message-ID: <1426583010-30250-1-git-send-email-e@80x24.org> (raw)

We will support "un-hijacking", so the repeated ep_insert/ep_remove
sequences in the kernel will get expensive and complicated for our
user-land code, too.
---
 lib/yahns/http_client.rb  | 10 +++++-----
 lib/yahns/queue_epoll.rb  | 11 -----------
 lib/yahns/queue_kqueue.rb |  6 ------
 3 files changed, 5 insertions(+), 22 deletions(-)

diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb
index 235decd..46ea3ec 100644
--- a/lib/yahns/http_client.rb
+++ b/lib/yahns/http_client.rb
@@ -259,12 +259,12 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc:
   end
 
   # allow releasing some memory if rack.hijack is used
+  # n.b. we no longer issue EPOLL_CTL_DEL because it becomes more expensive
+  # (and complicated) as our hijack support will allow "un-hijacking"
+  # the socket.
   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) # EPOLL_CTL_DEL
+    # prevent socket from holding process up
+    Thread.current[:yahns_fdmap].forget(self)
     @input = nil # keep env["rack.input"] accessible, though
     @hs = nil # no need for the HTTP parser anymore
   end
diff --git a/lib/yahns/queue_epoll.rb b/lib/yahns/queue_epoll.rb
index 4a10ce0..da90a95 100644
--- a/lib/yahns/queue_epoll.rb
+++ b/lib/yahns/queue_epoll.rb
@@ -32,17 +32,6 @@ class Yahns::Queue < SleepyPenguin::Epoll::IO # :nodoc:
     Thread.current[:yahns_fdmap] = @fdmap
   end
 
-  # use only before hijacking, once hijacked, io may be unusable to us
-  # It is not safe to call this unless it is an unarmed EPOLLONESHOT
-  # object.
-  def queue_del(io)
-    # order does not really matter here, however Epoll::CTL_DEL
-    # will free up ~200 bytes of unswappable kernel memory,
-    # so we call it first
-    epoll_ctl(Epoll::CTL_DEL, io, 0)
-    @fdmap.forget(io)
-  end
-
   # returns an array of infinitely running threads
   def worker_thread(logger, max_events)
     Thread.new do
diff --git a/lib/yahns/queue_kqueue.rb b/lib/yahns/queue_kqueue.rb
index ce75793..4e5c133 100644
--- a/lib/yahns/queue_kqueue.rb
+++ b/lib/yahns/queue_kqueue.rb
@@ -41,12 +41,6 @@ class Yahns::Queue < SleepyPenguin::Kqueue::IO # :nodoc:
     Thread.current[:yahns_fdmap] = @fdmap
   end
 
-  def queue_del(io)
-    # do not bother with kevent EV_DELETE, it may be tricky to get right,
-    # we only did it in epoll since Eric knows the epoll internals well.
-    @fdmap.forget(io)
-  end
-
   # returns an array of infinitely running threads
   def worker_thread(logger, max_events)
     Thread.new do
-- 
2.3.2.209.gd67f9d5


                 reply	other threads:[~2015-03-17  9:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426583010-30250-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).