Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use incrementing counter for stream id #188

Merged
merged 2 commits into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ void ConnectionManagerImpl::onDrainTimeout() {
}

DateFormatter ConnectionManagerImpl::ActiveStream::date_formatter_("%a, %d %b %Y %H:%M:%S GMT");
std::atomic<uint64_t> 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();
Expand Down
5 changes: 5 additions & 0 deletions source/common/http/conn_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>,
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
// provide the intended behavior when doing runtime routing, etc.
static std::atomic<uint64_t> next_stream_id_;

ConnectionManagerImpl& connection_manager_;
const uint64_t stream_id_;
StreamEncoder* response_encoder_{};
Expand Down