Alexey Serbin has uploaded a new patch set (#2).

Change subject: [rpc] faster generation of KRPC call ID
......................................................................

[rpc] faster generation of KRPC call ID

Updated the way how the KRPC call identifiers are generated.

To compare, I used the following code (headers are omitted):

old.cc:
-------------------------

int32_t cur_id = 0;
int32_t next_id() {
  if (PREDICT_FALSE(cur_id == std::numeric_limits<int32_t>::max())) {
    cur_id = 0;
  } else {
    ++cur_id;
  }
  return cur_id;
}

int main() {
  srandom(time(nullptr));
  const int u_bound = 800000000 + (random() % 100);
  int n = 0;
  for (int i = 0; i < u_bound; ++i) {
    n = next_id();
  }
  cout << n << endl;
  return 0;
}
-------------------------

new.cc:
-------------------------
int32_t cur_id = 0;
int32_t next_id() {
  ++cur_id;
  return (cur_id & 0x7fffffff);
}

int main() {
  srandom(time(nullptr));
  const int u_bound = 800000000 + (random() % 100);
  int n = 0;
  for (int i = 0; i < u_bound; ++i) {
    n = next_id();
  }
  std::cout << n << std::endl;
  return 0;
}
-------------------------

My ad-hoc measurements show that the new version is faster even if
compiling both with -O3 optimization flag:
  old:
    real  0m0.831s
    user  0m0.822s
    sys   0m0.005s

  new:
    real  0m0.005s
    user  0m0.001s
    sys   0m0.002s

>From the 'perf stat' perspective it looks good as well:

-------------------------
 Performance counter stats for './old' (10 runs):

        790.584545 task-clock                #    1.001 CPUs utilized
                 1 context-switches          #    0.002 K/sec
                 1 cpu-migrations            #    0.001 K/sec
               273 page-faults               #    0.345 K/sec
     2,583,562,591 cycles                    #    3.268 GHz
     2,805,308,074 instructions              #    1.09  insns per cycle
       200,917,139 branches                  #  254.137 M/sec
            13,513 branch-misses             #    0.01% of all branches

       0.790023494 seconds time elapsed
-------------------------

-------------------------
 Performance counter stats for './new' (10 runs):

          0.888215 task-clock                #    0.831 CPUs utilized
                 0 context-switches          #    0.000 K/sec
                 0 cpu-migrations            #    0.000 K/sec
               273 page-faults               #    0.307 M/sec
         2,561,042 cycles                    #    2.883 GHz
         2,804,468 instructions              #    1.10  insns per cycle
           480,394 branches                  #  540.853 M/sec
            11,575 branch-misses             #    2.41% of all branches

       0.001068744 seconds time elapsed
-------------------------

Change-Id: I03726343d222bcd241c2c2a5a1670a672f8e5cb6
---
M src/kudu/rpc/connection.cc
M src/kudu/rpc/connection.h
2 files changed, 9 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/13/7813/2
-- 
To view, visit http://gerrit.cloudera.org:8080/7813
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I03726343d222bcd241c2c2a5a1670a672f8e5cb6
Gerrit-PatchSet: 2
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-Owner: Alexey Serbin <aser...@cloudera.com>
Gerrit-Reviewer: Adar Dembo <a...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins
Gerrit-Reviewer: Todd Lipcon <t...@apache.org>

Reply via email to