From 0eb758107ddc9a089cf7ca005d425ba36ed0b233 Mon Sep 17 00:00:00 2001 From: Matt Klein Date: Wed, 2 Nov 2016 14:15:21 -0700 Subject: [PATCH 1/2] perf: use incrementing counter for stream id See code comment for more info. --- source/common/http/conn_manager_impl.cc | 4 ++-- source/common/http/conn_manager_impl.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/common/http/conn_manager_impl.cc b/source/common/http/conn_manager_impl.cc index 5547ccff42a0..259a6e3be29b 100644 --- a/source/common/http/conn_manager_impl.cc +++ b/source/common/http/conn_manager_impl.cc @@ -264,10 +264,10 @@ void ConnectionManagerImpl::onDrainTimeout() { } DateFormatter ConnectionManagerImpl::ActiveStream::date_formatter_("%a, %d %b %Y %H:%M:%S GMT"); +std::atomic ConnectionManagerImpl::ActiveStream::next_stream_id_(0); ConnectionManagerImpl::ActiveStream::ActiveStream(ConnectionManagerImpl& connection_manager) - : connection_manager_(connection_manager), - stream_id_(connection_manager.random_generator_.random()), + : connection_manager_(connection_manager), stream_id_(next_stream_id_++), request_timer_(connection_manager_.config_.stats().named_.downstream_rq_time_.allocateSpan()), request_info_(connection_manager_.codec_->protocolString()) { connection_manager_.config_.stats().named_.downstream_rq_total_.inc(); diff --git a/source/common/http/conn_manager_impl.h b/source/common/http/conn_manager_impl.h index 4a742e4c49ba..9aee41c28043 100644 --- a/source/common/http/conn_manager_impl.h +++ b/source/common/http/conn_manager_impl.h @@ -379,6 +379,11 @@ class ConnectionManagerImpl : Logger::Loggable, bool local_complete_{}; }; + // NOTE: This is used for stable randomness. For performance reasons we use an incrementing + // counter shared across all threads. This may lead to burstiness but in general should + // prove the intended behavior when doing runtime routing, etc. + static std::atomic next_stream_id_; + ConnectionManagerImpl& connection_manager_; const uint64_t stream_id_; StreamEncoder* response_encoder_{}; From ae1fea9f121b2993c72f1f990d61fa5fb72b2703 Mon Sep 17 00:00:00 2001 From: Matt Klein Date: Wed, 2 Nov 2016 14:18:23 -0700 Subject: [PATCH 2/2] fix --- source/common/http/conn_manager_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/http/conn_manager_impl.h b/source/common/http/conn_manager_impl.h index 9aee41c28043..c019b45b9858 100644 --- a/source/common/http/conn_manager_impl.h +++ b/source/common/http/conn_manager_impl.h @@ -381,7 +381,7 @@ class ConnectionManagerImpl : Logger::Loggable, // NOTE: This is used for stable randomness. For performance reasons we use an incrementing // counter shared across all threads. This may lead to burstiness but in general should - // prove the intended behavior when doing runtime routing, etc. + // provide the intended behavior when doing runtime routing, etc. static std::atomic next_stream_id_; ConnectionManagerImpl& connection_manager_;