From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2DAB71FA00 for ; Thu, 22 Dec 2022 09:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yhbt.net; s=selector1; t=1671699732; bh=jgppS/IEmMTkLDNWuZMfHE06afD3qOJidAqxfLtOrF8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=evbMEBvE2TH3ZZs2e47wYglhdq22kIzMm38RWS/mvnix+30oXwIROO7LF7Xw8JxWi UwBkBDCEB1EvmfHaC+qGWnfpRiEKAhbvyRKUi1Gwdf6fNA+fQBjAKhgADZ78wgHM8Y xrwO0O5tXXn4rx4W9FohRqaF8iDmpVIsP4slOcKI= From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH 3/4] standardize on 16384-byte reads Date: Thu, 22 Dec 2022 09:02:10 +0000 Message-Id: <20221222090211.9056-4-bofh@yhbt.net> In-Reply-To: <20221222090211.9056-1-bofh@yhbt.net> References: <20221222090211.9056-1-bofh@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is the size used by Ruby internally for IO.copy_stream. 8192 seems too small nowadays with the higher cost of syscalls. --- lib/yahns/http_client.rb | 2 +- lib/yahns/proxy_http_response.rb | 4 ++-- lib/yahns/req_res.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb index b6b6035..826eb8d 100644 --- a/lib/yahns/http_client.rb +++ b/lib/yahns/http_client.rb @@ -315,7 +315,7 @@ def app_hijacked?(env, res) end def do_pread(io, count, offset) - count = 0x4000 if count > 0x4000 + count = 16384 if count > 16384 buf = Thread.current[:yahns_sfbuf] ||= ''.dup if io.respond_to?(:pread) io.pread(count, offset, buf) diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index d4a3dda..db9c4b7 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -147,7 +147,7 @@ def proxy_res_headers(res, req_res) end def read_len(len) - max = 0x2000 + max = 16384 max = len if len && len < max max end @@ -206,7 +206,7 @@ def proxy_read_trailers(kcar, req_res) wbuf = req_res.resbuf until kcar.trailers(tlr, chunk) - case rv = req_res.kgio_tryread(0x2000, rbuf) + case rv = req_res.kgio_tryread(16384, rbuf) when String chunk << rv when :wait_readable diff --git a/lib/yahns/req_res.rb b/lib/yahns/req_res.rb index 4ad8e5c..283fea8 100644 --- a/lib/yahns/req_res.rb +++ b/lib/yahns/req_res.rb @@ -29,7 +29,7 @@ def yahns_step # yahns event loop entry point case resbuf = @resbuf # where are we at the response? when nil # common case, catch the response header in a single read - case rv = kgio_tryread(0x2000, buf) + case rv = kgio_tryread(16384, buf) when String if res = req.headers(@hdr = [], rv) return c.proxy_response_start(res, rv, req, self) @@ -48,7 +48,7 @@ def yahns_step # yahns event loop entry point when String # continue reading trickled response headers from upstream - case rv = kgio_tryread(0x2000, buf) + case rv = kgio_tryread(16384, buf) when String then res = req.headers(@hdr, resbuf << rv) and break when :wait_readable then return rv when nil @@ -114,7 +114,7 @@ def send_req_body(req) # @rrstate == [ (str|vec), rack.input, chunked? ] # we should not be waiting on a slow network resource when reading # input. However, some weird configs may disable this on LANs # and we may wait indefinitely on input.read here... - while input.read(0x2000, rbuf) + while input.read(16384, rbuf) if chunked buf[0] = "#{rbuf.size.to_s(16)}\r\n".freeze buf[1] = rbuf