raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [ANN] raindrops 0.18.0 - real-time stats for preforking Rack servers
@ 2017-03-23  2:48  5% Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2017-03-23  2:48 UTC (permalink / raw)
  To: ruby-talk, raindrops-public; +Cc: unicorn-public, Simon Eskildsen, Jeremy Evans

raindrops is a real-time stats toolkit to show statistics for Rack HTTP
servers.  It is designed for preforking servers such as unicorn, but
should support any Rack HTTP server on platforms supporting POSIX shared
memory.  It may also be used as a generic scoreboard for sharing atomic
counters across multiple processes.

* https://bogomips.org/raindrops/
* No subscription necessary, no HTML mail:
  raindrops-public@bogomips.org
* mail archives: https://bogomips.org/raindrops-public/
  http://ou63pmih66umazou.onion/raindrops-public/
  nntp://news.public-inbox.org/inbox.comp.lang.ruby.raindrops
  nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.raindrops
* git clone git://bogomips.org/raindrops.git
* https://bogomips.org/raindrops/NEWS.atom.xml
* Demo site: https://raindrops-demo.bogomips.org:8443/

Changes:

    raindrops 0.18.0
    
    The most notable feature of this release is the addition of
    FreeBSD and OpenBSD TCP_INFO support.  This includes the
    Raindrops::TCP for portably mapping TCP state names to
    platform-dependent numeric values:
    
      https://bogomips.org/raindrops/Raindrops.html#TCP
    
    Thanks to Jeremy Evans and Simon Eskildsen on the
    unicorn-public@bogomips.org mailing list for inspiring
    these changes to raindrops.
    
    There's also a few internal cleanups, and documentation
    improvements, including some fixes to the largely-forgotten
    Raindrops::Aggreage::PMQ class:
    
      https://bogomips.org/raindrops/Raindrops/Aggregate/PMQ.html
    
    20 changes since 0.17.0:
    
          test_inet_diag_socket: fix Fixnum deprecation warning
          TODO: add item for IPv6 breakage
          ext: fix documentation for C ext-defined classes
          TCP_Info: custom documentation for #get!
          TypedData C-API conversion
          test_watcher: disable test correctly when aggregate is missing
          tcp_info: support this struct under FreeBSD
          define Raindrops::TCP hash for TCP states
          linux_inet_diag: reduce stack usage and simplify
          avoid reading errno repeatedly
          aggregate/pmq: avoid false sharing of lock buffers
          aggregate/pmq: remove io-extra requirement
          aggregate/pmq: avoid File#stat allocation
          Merge remote-tracking branch 'origin/freebsd'
          Merge remote-tracking branch 'origin/aggregate-pmq'
          doc: remove private email support address
          doc: update location of TCP_INFO-related stuff
          build: avoid olddoc for building the RubyGem
          doc: document Raindrops::TCP hash
          aggregate/pmq: update version numbers for Ruby and Linux

^ permalink raw reply	[relevance 5%]

* [PATCH] linux_inet_diag: reduce stack usage and simplify
@ 2017-03-17 23:55  7% Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2017-03-17 23:55 UTC (permalink / raw)
  To: raindrops-public

getnameinfo is overkill for NI_NUMERICHOST + NI_NUMERICSERV usage,
and has a more complex and error-prone API than using inet_ntop
and snprintf.
---
 ext/raindrops/linux_inet_diag.c | 79 ++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 44 deletions(-)

diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c
index 8ad436b..f2db6a5 100644
--- a/ext/raindrops/linux_inet_diag.c
+++ b/ext/raindrops/linux_inet_diag.c
@@ -233,80 +233,70 @@ static void bug_warn_nogvl(const char *fmt, ...)
 
 static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r)
 {
-	char *key, *port, *old_key;
+	char *host, *key, *port, *old_key;
 	size_t alloca_len;
 	struct listen_stats *stats;
-	socklen_t keylen;
+	socklen_t hostlen;
 	socklen_t portlen = (socklen_t)sizeof("65535");
-	union any_addr sa;
-	socklen_t len = sizeof(struct sockaddr_storage);
-	int rc;
-	int flags = NI_NUMERICHOST | NI_NUMERICSERV;
+	int n;
+	const void *src = r->id.idiag_src;
 
-	switch ((sa.ss.ss_family = r->idiag_family)) {
+	switch (r->idiag_family) {
 	case AF_INET: {
-		sa.in.sin_port = r->id.idiag_sport;
-		sa.in.sin_addr.s_addr = r->id.idiag_src[0];
-		keylen = INET_ADDRSTRLEN;
-		alloca_len = keylen + 1 + portlen;
-		key = alloca(alloca_len);
-		key[keylen] = 0; /* will be ':' later */
-		port = key + keylen + 1;
-		rc = getnameinfo(&sa.sa, len,
-				 key, keylen, port, portlen, flags);
+		hostlen = INET_ADDRSTRLEN;
+		alloca_len = hostlen + portlen;
+		host = key = alloca(alloca_len);
 		break;
 		}
 	case AF_INET6: {
-		sa.in6.sin6_port = r->id.idiag_sport;
-		memcpy(&sa.in6.sin6_addr, &r->id.idiag_src, sizeof(__be32[4]));
-		keylen = INET6_ADDRSTRLEN;
-		          /* [            ] */
-		alloca_len = 1 + keylen + 1 + 1 + portlen;
+		hostlen = INET6_ADDRSTRLEN;
+		alloca_len = 1 + hostlen + 1 + portlen;
 		key = alloca(alloca_len);
-		*key = '[';
-		key[1 + keylen + 1] = 0; /* will be ':' later */
-		port = 1 + key + keylen + 1 + 1;
-		rc = getnameinfo(&sa.sa, len,
-				 key + 1, keylen, port, portlen, flags);
+		host = key + 1;
 		break;
 		}
 	default:
 		assert(0 && "unsupported address family, could that be IPv7?!");
 	}
-	if (rc != 0) {
-		bug_warn_nogvl("BUG: getnameinfo: %s\n", gai_strerror(rc));
-		*key = 0;
+	if (!inet_ntop(r->idiag_family, src, host, hostlen)) {
+		bug_warn_nogvl("BUG: inet_ntop: %s\n", strerror(errno));
+		*key = '\0';
+		*host = '\0';
 	}
-
-	keylen = (socklen_t)strlen(key);
-	portlen = (socklen_t)strlen(port);
-
-	switch (sa.ss.ss_family) {
+	hostlen = (socklen_t)strlen(host);
+	switch (r->idiag_family) {
 	case AF_INET:
-		key[keylen] = ':';
-		memmove(key + keylen + 1, port, portlen + 1);
+		host[hostlen] = ':';
+		port = host + hostlen + 1;
 		break;
 	case AF_INET6:
-		key[keylen] = ']';
-		key[keylen + 1] = ':';
-		memmove(key + keylen + 2, port, portlen + 1);
-		keylen++;
+		key[0] = '[';
+		host[hostlen] = ']';
+		host[hostlen + 1] = ':';
+		port = host + hostlen + 2;
 		break;
 	default:
 		assert(0 && "unsupported address family, could that be IPv7?!");
 	}
 
+	n = snprintf(port, portlen, "%u", ntohs(r->id.idiag_sport));
+	if (n <= 0) {
+		bug_warn_nogvl("BUG: snprintf port: %d\n", n);
+		*key = '\0';
+	}
+
 	if (st_lookup(table, (st_data_t)key, (st_data_t *)&stats))
 		return stats;
 
 	old_key = key;
 
 	if (r->idiag_state == TCP_ESTABLISHED) {
-		int n = snprintf(key, alloca_len, "%s:%u",
-				 addr_any(sa.ss.ss_family),
+		n = snprintf(key, alloca_len, "%s:%u",
+				 addr_any(r->idiag_family),
 				 ntohs(r->id.idiag_sport));
 		if (n <= 0) {
 			bug_warn_nogvl("BUG: snprintf: %d\n", n);
+			*key = '\0';
 		}
 		if (st_lookup(table, (st_data_t)key, (st_data_t *)&stats))
 			return stats;
@@ -319,8 +309,9 @@ static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r)
 			memcpy(key, old_key, n + 1);
 		}
 	} else {
-		key = xmalloc(keylen + 1 + portlen + 1);
-		memcpy(key, old_key, keylen + 1 + portlen + 1);
+		size_t old_len = strlen(old_key) + 1;
+		key = xmalloc(old_len);
+		memcpy(key, old_key, old_len);
 	}
 	stats = xcalloc(1, sizeof(struct listen_stats));
 	st_insert(table, (st_data_t)key, (st_data_t)stats);
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2017-03-17 23:55  7% [PATCH] linux_inet_diag: reduce stack usage and simplify Eric Wong
2017-03-23  2:48  5% [ANN] raindrops 0.18.0 - real-time stats for preforking Rack servers Eric Wong

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

	https://yhbt.net/raindrops.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).