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.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 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 0180C633875 for ; Tue, 17 Mar 2015 09:03:30 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] avoid EPOLL_CTL_DEL calls on rack.hijack Date: Tue, 17 Mar 2015 09:03:30 +0000 Message-Id: <1426583010-30250-1-git-send-email-e@80x24.org> List-Id: 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