unicorn Ruby/Rack server 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] unicorn 5.5.0.pre1 - Rack HTTP server for fast clients and Unix
@ 2018-12-20 22:28  4% Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2018-12-20 22:28 UTC (permalink / raw)
  To: ruby-talk, unicorn-public; +Cc: Jeremy Evans

unicorn is an HTTP server for Rack applications designed to only serve
fast clients on low-latency, high-bandwidth connections and take
advantage of features in Unix/Unix-like kernels.  Slow clients should
only be served by placing a reverse proxy capable of fully buffering
both the the request and response in between unicorn and slow clients.

Disclaimer:

Due to its ability to tolerate crashes and isolate clients, unicorn
is unfortunately known to prolong the existence of bugs in applications
and libraries which run on top of it.

* https://bogomips.org/unicorn/
* public list: unicorn-public@bogomips.org
* mail archives: https://bogomips.org/unicorn-public/
* git clone https://bogomips.org/unicorn.git
* https://bogomips.org/unicorn/NEWS.atom.xml
* nntp://news.public-inbox.org/inbox.comp.lang.ruby.unicorn

This is a pre-release RubyGem intended for testing.

Changes:

unicorn 5.5.0.pre1

Jeremy Evans contributed the "default_middleware" configuration option:

  https://bogomips.org/unicorn-public/20180913192055.GD48926@jeremyevans.local/

Jeremy also contributed the ability to use separate groups for the process
and log files:

  https://bogomips.org/unicorn-public/20180913192449.GE48926@jeremyevans.local/

There's also a couple of uninteresting minor optimizations and
documentation additions.

Eric Wong (10):
      remove random seed reset atfork
      use IO#wait instead of kgio_wait_readable
      Merge branch '5.4-stable'
      shrink pipes under Linux
      socket_helper: add hint for FreeBSD users for accf_http(9)
      tests: ensure -N/--no-default-middleware not supported in config.ru
      doc: update more URLs to use HTTPS and avoid redirects
      deduplicate strings VM-wide in Ruby 2.5+
      doc/ISSUES: add links to git clone-able mail archives of our dependencies
      README: minor updates and additional disclaimer

Jeremy Evans (2):
      Make Worker#user support different process primary group and log file group
      Support default_middleware configuration option
-- 

^ permalink raw reply	[relevance 4%]

* Re: [RFC] deduplicate strings VM-wide in Ruby 2.5+
  2018-12-06 23:44  4% [RFC] deduplicate strings VM-wide in Ruby 2.5+ Eric Wong
@ 2018-12-07  4:56  7% ` Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2018-12-07  4:56 UTC (permalink / raw)
  To: unicorn-public

Since 'mkmf' is already in the fstring table as that exists in
the source; so I'll at least have to squash this on top for
Ruby <=2.5:

diff --git a/ext/unicorn_http/extconf.rb b/ext/unicorn_http/extconf.rb
index 5b7a8ca..d5f81fb 100644
--- a/ext/unicorn_http/extconf.rb
+++ b/ext/unicorn_http/extconf.rb
@@ -26,8 +26,11 @@
 
 message('checking if Hash#[]= (rb_hash_aset) dedupes... ')
 h = {}
-h[%w(m k m f).join('')] = :foo
-if 'mkmf'.freeze.equal?(h.keys[0])
+x = {}
+r = rand.to_s
+h[%W(#{r}).join('')] = :foo
+x[%W(#{r}).join('')] = :foo
+if x.keys[0].equal?(h.keys[0])
   $CPPFLAGS += ' -DHASH_ASET_DEDUPE=1 '
   message("yes\n")
 else

^ permalink raw reply related	[relevance 7%]

* [RFC] deduplicate strings VM-wide in Ruby 2.5+
@ 2018-12-06 23:44  4% Eric Wong
  2018-12-07  4:56  7% ` Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2018-12-06 23:44 UTC (permalink / raw)
  To: unicorn-public

String#-@ deduplicates strings starting with Ruby 2.5.0
Hash#[]= deduplicates strings starting in Ruby 2.6.0-rc1

This allows us to save a small amount of memory by sharing
objects with other parts of the stack (e.g. Rack).
---
   RFC because I've only lightly-tested this and only with Ruby 2.6rc1.
   Will get around to testing later (because more hardware problems,
   trying new SATA cables...)

 ext/unicorn_http/common_field_optimization.h | 26 ++++++++++++++++---
 ext/unicorn_http/extconf.rb                  | 27 ++++++++++++++++++++
 test/unit/test_http_parser.rb                | 16 ++++++++++++
 3 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/ext/unicorn_http/common_field_optimization.h b/ext/unicorn_http/common_field_optimization.h
index 251e734..4b9f062 100644
--- a/ext/unicorn_http/common_field_optimization.h
+++ b/ext/unicorn_http/common_field_optimization.h
@@ -58,6 +58,23 @@ static struct common_field common_http_fields[] = {
 
 #define HTTP_PREFIX "HTTP_"
 #define HTTP_PREFIX_LEN (sizeof(HTTP_PREFIX) - 1)
+static ID id_uminus;
+
+/* this dedupes under Ruby 2.5+ (December 2017) */
+static VALUE str_dd_freeze(VALUE str)
+{
+  if (STR_UMINUS_DEDUPE)
+    return rb_funcall(str, id_uminus, 0);
+
+  /* freeze,since it speeds up older MRI slightly */
+  OBJ_FREEZE(str);
+  return str;
+}
+
+static VALUE str_new_dd_freeze(const char *ptr, long len)
+{
+  return str_dd_freeze(rb_str_new(ptr, len));
+}
 
 /* this function is not performance-critical, called only at load time */
 static void init_common_fields(VALUE mark_ary)
@@ -65,18 +82,19 @@ static void init_common_fields(VALUE mark_ary)
   int i;
   struct common_field *cf = common_http_fields;
   char tmp[64];
+
+  id_uminus = rb_intern("-@");
   memcpy(tmp, HTTP_PREFIX, HTTP_PREFIX_LEN);
 
   for(i = ARRAY_SIZE(common_http_fields); --i >= 0; cf++) {
     /* Rack doesn't like certain headers prefixed with "HTTP_" */
     if (!strcmp("CONTENT_LENGTH", cf->name) ||
         !strcmp("CONTENT_TYPE", cf->name)) {
-      cf->value = rb_str_new(cf->name, cf->len);
+      cf->value = str_new_dd_freeze(cf->name, cf->len);
     } else {
       memcpy(tmp + HTTP_PREFIX_LEN, cf->name, cf->len + 1);
-      cf->value = rb_str_new(tmp, HTTP_PREFIX_LEN + cf->len);
+      cf->value = str_new_dd_freeze(tmp, HTTP_PREFIX_LEN + cf->len);
     }
-    cf->value = rb_obj_freeze(cf->value);
     rb_ary_push(mark_ary, cf->value);
   }
 }
@@ -105,7 +123,7 @@ static VALUE uncommon_field(const char *field, size_t flen)
   memcpy(RSTRING_PTR(f) + HTTP_PREFIX_LEN, field, flen);
   assert(*(RSTRING_PTR(f) + RSTRING_LEN(f)) == '\0' &&
          "string didn't end with \\0"); /* paranoia */
-  return rb_obj_freeze(f);
+  return HASH_ASET_DEDUPE ? f : str_dd_freeze(f);
 }
 
 #endif /* common_field_optimization_h */
diff --git a/ext/unicorn_http/extconf.rb b/ext/unicorn_http/extconf.rb
index 2fc60fe..5b7a8ca 100644
--- a/ext/unicorn_http/extconf.rb
+++ b/ext/unicorn_http/extconf.rb
@@ -8,4 +8,31 @@
 have_func("rb_hash_clear", "ruby.h") # Ruby 2.0+
 have_func("gmtime_r", "time.h")
 
+message('checking if String#-@ (str_uminus) dedupes... ')
+begin
+  a = -(%w(t e s t).join)
+  b = -(%w(t e s t).join)
+  if a.equal?(b)
+    $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=1 '
+    message("yes\n")
+  else
+    $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=0 '
+    message("no, needs Ruby 2.5+\n")
+  end
+rescue NoMethodError
+  $CPPFLAGS += ' -DSTR_UMINUS_DEDUPE=0 '
+  message("no, String#-@ not available\n")
+end
+
+message('checking if Hash#[]= (rb_hash_aset) dedupes... ')
+h = {}
+h[%w(m k m f).join('')] = :foo
+if 'mkmf'.freeze.equal?(h.keys[0])
+  $CPPFLAGS += ' -DHASH_ASET_DEDUPE=1 '
+  message("yes\n")
+else
+  $CPPFLAGS += ' -DHASH_ASET_DEDUPE=0 '
+  message("no, needs Ruby 2.6+\n")
+end
+
 create_makefile("unicorn_http")
diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb
index 31e6f71..697af44 100644
--- a/test/unit/test_http_parser.rb
+++ b/test/unit/test_http_parser.rb
@@ -865,4 +865,20 @@ def test_memsize
   rescue LoadError
     # not all Ruby implementations have objspace
   end
+
+  def test_dedupe
+    parser = HttpParser.new
+    # n.b. String#freeze optimization doesn't work under modern test-unit
+    exp = -'HTTP_HOST'
+    get = "GET / HTTP/1.1\r\nHost: example.com\r\nHavpbea-fhpxf: true\r\n\r\n"
+    assert parser.add_parse(get)
+    key = parser.env.keys.detect { |k| k == exp }
+    assert_same exp, key
+
+    if RUBY_VERSION.to_r >= 2.6 # 2.6.0-rc1+
+      exp = -'HTTP_HAVPBEA_FHPXF'
+      key = parser.env.keys.detect { |k| k == exp }
+      assert_same exp, key
+    end
+  end if RUBY_VERSION.to_r >= 2.5 && RUBY_ENGINE == 'ruby'
 end

^ permalink raw reply related	[relevance 4%]

Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2018-12-06 23:44  4% [RFC] deduplicate strings VM-wide in Ruby 2.5+ Eric Wong
2018-12-07  4:56  7% ` Eric Wong
2018-12-20 22:28  4% [ANN] unicorn 5.5.0.pre1 - Rack HTTP server for fast clients and Unix Eric Wong

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

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