This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit fb59235e2099e1ffacd9cf91b7e605f8d53f24cc
Author: Alexey Serbin <[email protected]>
AuthorDate: Fri Sep 11 22:51:19 2020 -0700

    [rpc] simplify Connection::GetNextCallId()
    
    This changelist simplifies the code to compute next call identifier.
    Synthetic performance results look good, no performance degradation
    is observed.
    
    Before:
      Performance counter stats for './bin/rpc-bench 
--gtest_filter=*BenchmarkCallsAsync' (10 runs):
    
            9264.974859 task-clock                #    9.045 CPUs utilized      
      ( +-  0.69% )
                 87,544 context-switches          #    0.009 M/sec              
      ( +-  1.28% )
                  1,452 cpu-migrations            #    0.157 K/sec              
      ( +- 20.67% )
                  3,216 page-faults               #    0.347 K/sec              
      ( +-  1.05% )
         26,213,352,542 cycles                    #    2.829 GHz                
      ( +-  0.73% )
         27,520,087,657 instructions              #    1.05  insns per cycle    
      ( +-  1.27% )
          4,375,784,153 branches                  #  472.293 M/sec              
      ( +-  1.25% )
             22,713,237 branch-misses             #    0.52% of all branches    
      ( +-  1.20% )
    
            1.024363805 seconds time elapsed                                    
      ( +-  0.05% )
    
    After:
      Performance counter stats for './bin/rpc-bench 
--gtest_filter=*BenchmarkCallsAsync' (10 runs):
    
            8744.870402 task-clock                #    8.540 CPUs utilized      
      ( +-  3.32% )
                 86,214 context-switches          #    0.010 M/sec              
      ( +-  2.94% )
                  1,518 cpu-migrations            #    0.174 K/sec              
      ( +- 22.82% )
                  3,183 page-faults               #    0.364 K/sec              
      ( +-  1.19% )
         24,708,133,421 cycles                    #    2.825 GHz                
      ( +-  3.36% )
         25,856,687,203 instructions              #    1.05  insns per cycle    
      ( +-  3.76% )
          4,111,319,492 branches                  #  470.141 M/sec              
      ( +-  3.74% )
             21,390,733 branch-misses             #    0.52% of all branches    
      ( +-  3.66% )
    
            1.023946171 seconds time elapsed                                    
      ( +-  0.05% )
    
    Change-Id: I1fefe8b4c41fdde6e9744f2efec9476af8269c53
    Reviewed-on: http://gerrit.cloudera.org:8080/16444
    Tested-by: Kudu Jenkins
    Reviewed-by: Bankim Bhavsar <[email protected]>
---
 src/kudu/rpc/connection.cc |  3 ++-
 src/kudu/rpc/connection.h  | 20 ++++++++------------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/kudu/rpc/connection.cc b/src/kudu/rpc/connection.cc
index 0350fad..ddd715a 100644
--- a/src/kudu/rpc/connection.cc
+++ b/src/kudu/rpc/connection.cc
@@ -33,6 +33,7 @@
 #include <glog/logging.h>
 
 #include "kudu/gutil/map-util.h"
+#include "kudu/gutil/port.h"
 #include "kudu/gutil/strings/human_readable.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/rpc/inbound_call.h"
@@ -206,7 +207,7 @@ Connection::Connection(ReactorThread *reactor_thread,
       direction_(direction),
       last_activity_time_(MonoTime::Now()),
       is_epoll_registered_(false),
-      next_call_id_(1),
+      call_id_(std::numeric_limits<int32_t>::max()),
       credentials_policy_(policy),
       negotiation_complete_(false),
       is_confidential_(false),
diff --git a/src/kudu/rpc/connection.h b/src/kudu/rpc/connection.h
index a77d4d5..5ec15e9 100644
--- a/src/kudu/rpc/connection.h
+++ b/src/kudu/rpc/connection.h
@@ -30,12 +30,11 @@
 #include <ev++.h>
 #include <glog/logging.h>
 
-#include "kudu/gutil/port.h"
 #include "kudu/gutil/ref_counted.h"
 #include "kudu/rpc/connection_id.h"
+#include "kudu/rpc/remote_user.h"
 #include "kudu/rpc/rpc_controller.h"
 #include "kudu/rpc/rpc_header.pb.h"
-#include "kudu/rpc/remote_user.h"
 #include "kudu/rpc/transfer.h"
 #include "kudu/util/monotime.h"
 #include "kudu/util/net/sockaddr.h"
@@ -50,10 +49,11 @@ namespace rpc {
 class DumpConnectionsRequestPB;
 class InboundCall;
 class OutboundCall;
-class RpcConnectionPB;
 class ReactorThread;
+class RpcConnectionPB;
 class RpczStore;
 class SocketStatsPB;
+
 enum class CredentialsPolicy;
 
 //
@@ -292,13 +292,8 @@ class Connection : public RefCountedThreadSafe<Connection> 
{
   // and ensuring we roll over from INT32_MAX to 0.
   // Negative numbers are reserved for special purposes.
   int32_t GetNextCallId() {
-    int32_t call_id = next_call_id_;
-    if (PREDICT_FALSE(next_call_id_ == std::numeric_limits<int32_t>::max())) {
-      next_call_id_ = 0;
-    } else {
-      next_call_id_++;
-    }
-    return call_id;
+    static constexpr uint32_t kCallIdMask = 
std::numeric_limits<int32_t>::max(); // 0x7fffffff
+    return static_cast<int32_t>(++call_id_ & kCallIdMask);
   }
 
   // An incoming packet has completed transferring on the server side.
@@ -371,8 +366,9 @@ class Connection : public RefCountedThreadSafe<Connection> {
   // being handled.
   inbound_call_map_t calls_being_handled_;
 
-  // the next call ID to use
-  int32_t next_call_id_;
+  // The internal counter to generate next call ID to use. The call ID is
+  // a signed integer: 31 LSBs of the internal counter are used to represent 
it.
+  uint32_t call_id_;
 
   // Starts as Status::OK, gets set to a shutdown status upon Shutdown().
   Status shutdown_status_;

Reply via email to