raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <bofh@yhbt.net>
To: Jean Boussier <jean.boussier@gmail.com>
Cc: raindrops-public@yhbt.net
Subject: [PATCH] middleware: reuse inet_diag netlink socket
Date: Sat, 30 Sep 2023 23:13:20 +0000	[thread overview]
Message-ID: <20230930231320.M781709@dcvr> (raw)
In-Reply-To: <20230926214000.M564322@dcvr>

> Your code (and some of the Ruby code shipped w/ raindrops)
> should probably be reusing sockets given our API allows it.

IOW, something like this (don't think test cases are worth updating):
Subject: [PATCH] middleware: reuse inet_diag netlink socket

No point in constantly allocating and deallocating FDs (and Ruby
IO objects) when reusing them is supported.
 lib/raindrops/middleware.rb | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/raindrops/middleware.rb b/lib/raindrops/middleware.rb
index d5e3927..e0781f2 100644
--- a/lib/raindrops/middleware.rb
+++ b/lib/raindrops/middleware.rb
@@ -97,7 +97,9 @@ def initialize(app, opts = {})
     if tmp.nil? && defined?(Unicorn) && Unicorn.respond_to?(:listener_names)
       tmp = Unicorn.listener_names
-    @tcp = @unix = nil
+    @nl_sock = @tcp = @unix = nil
+    defined?(Raindrops::Linux.tcp_listener_stats) and
+      @nl_sock = Raindrops::InetDiagSocket.new
     if tmp
       @tcp = tmp.grep(/\A.+:\d+\z/)
@@ -129,7 +131,7 @@ def stats_response  # :nodoc:
            "writing: #{@stats.writing}\n"
     if defined?(Raindrops::Linux.tcp_listener_stats)
-      Raindrops::Linux.tcp_listener_stats(@tcp).each do |addr,stats|
+      Raindrops::Linux.tcp_listener_stats(@tcp, @nl_sock).each do |addr,stats|
         body << "#{addr} active: #{stats.active}\n" \
                 "#{addr} queued: #{stats.queued}\n"
       end if @tcp

  reply	other threads:[~2023-09-30 23:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23  9:56 [PATCH] tcp_listener_stats: always eagerly close sockets Jean Boussier
2023-09-26 21:40 ` Eric Wong
2023-09-30 23:13   ` Eric Wong [this message]
2023-09-30 23:35     ` [squash] make reusing inet_diag sock fork+preload safe Eric Wong
2023-12-29 17:44       ` [PATCH v3] middleware: reuse inet_diag netlink socket Eric Wong

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:

  List information: https://yhbt.net/raindrops/

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

  git send-email \
    --in-reply-to=20230930231320.M781709@dcvr \
    --to=bofh@yhbt.net \
    --cc=jean.boussier@gmail.com \
    --cc=raindrops-public@yhbt.net \


* 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


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).