You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/05/11 07:28:35 UTC

[4/4] incubator-kudu git commit: sockaddr: improve hash function for better reactor load balancing

sockaddr: improve hash function for better reactor load balancing

While watching 'top -H' on previous RPC benchmarks, I noticed that
the workload was not evenly distributed across reactor threads. That
made me suspect that the connection hash function was poor. This
switches to a better hash which seems to spread the work more evenly
among threads.

The results are often much better (depending how unlucky the bad
hash function was). In a typical run, this gets about 33% improvement
for sync and 130% improvement for async.

Original:
  Mode:            Sync
  Client threads:   24
  Worker threads:   40
  Server reactors:  24
  ----------------------------------
  Reqs/sec:         278730
  User CPU per req: 19.8051us
  Sys CPU per req:  21.9387us
  Ctx Sw. per req:  4.04089

  Mode:            Async
  Client reactors:  24
  Call concurrency: 100
  Worker threads:   40
  Server reactors:  24
  ----------------------------------
  Reqs/sec:         336000
  User CPU per req: 11.0189us
  Sys CPU per req:  13.6012us
  Ctx Sw. per req:  1.48036

With change:
  Mode:            Sync
  Client threads:   24
  Worker threads:   40
  Server reactors:  24
  ----------------------------------
  Reqs/sec:         373224
  User CPU per req: 27.2511us
  Sys CPU per req:  35.9059us
  Ctx Sw. per req:  5.50983

  Mode:            Async
  Client reactors:  24
  Call concurrency: 100
  Worker threads:   40
  Server reactors:  24
  ----------------------------------
  Reqs/sec:         768135
  User CPU per req: 21.6902us
  Sys CPU per req:  25.3586us
  Ctx Sw. per req:  1.34386

Change-Id: I650738cc628bb6ad67348c40753d777c9b566d61
Reviewed-on: http://gerrit.cloudera.org:8080/2939
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/f9708338
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/f9708338
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/f9708338

Branch: refs/heads/master
Commit: f9708338a1bfa8efcaf829c897fc745e7d7b744f
Parents: 07d3507
Author: Todd Lipcon <to...@cloudera.com>
Authored: Tue May 3 10:11:29 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Wed May 11 07:16:30 2016 +0000

----------------------------------------------------------------------
 src/kudu/util/net/sockaddr.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/f9708338/src/kudu/util/net/sockaddr.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/net/sockaddr.cc b/src/kudu/util/net/sockaddr.cc
index 3385e8c..ed249c7 100644
--- a/src/kudu/util/net/sockaddr.cc
+++ b/src/kudu/util/net/sockaddr.cc
@@ -25,6 +25,7 @@
 #include <string>
 
 #include "kudu/gutil/endian.h"
+#include "kudu/gutil/hash/builtin_type_hash.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/stringprintf.h"
 #include "kudu/gutil/strings/substitute.h"
@@ -73,9 +74,9 @@ bool Sockaddr::operator<(const Sockaddr &rhs) const {
 }
 
 uint32_t Sockaddr::HashCode() const {
-  uint32_t ret = addr_.sin_addr.s_addr;
-  ret ^= (addr_.sin_port * 7919);
-  return ret;
+  uint32_t hash = Hash32NumWithSeed(addr_.sin_addr.s_addr, 0);
+  hash = Hash32NumWithSeed(addr_.sin_port, hash);
+  return hash;
 }
 
 void Sockaddr::set_port(int port) {