-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Introduce listener TCP connection buffer configuration and implement … #558
Conversation
…read buffer limits (envoyproxy#150). Baby steps towards flow control. This patch plumbs the TCP connection buffer limits to the listener and enforces it on the read buffer only. Later patches will also plumb to the upstream cluster connection and cover the write buffer (which requires the watermark API).
I'm trying to unbury myself. I will look at this later today or this weekend. |
@@ -52,6 +52,9 @@ use_original_dst | |||
destination port. If there is no listener associated with the original destination port, the | |||
connection is handled by the listener that receives it. Default is false. | |||
|
|||
per_connection_buffer_limit_bytes | |||
*(optional, integer)* Soft limit on size of the listener's new connection read and write buffers. If unspecified, an implementation defined default is applied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please specify the default value here.
return read_buffer_limit_ > 0 && read_buffer_.length() >= read_buffer_limit_; | ||
} | ||
// Mark read buffer ready to read in the event loop. This is used when yielding following | ||
// shouldDrainReadBuffer(). TODO(htuch): While this is the basis for also yielding to other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: put todo on new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A few (annoying, sorry) comments.
@@ -52,6 +52,9 @@ use_original_dst | |||
destination port. If there is no listener associated with the original destination port, the | |||
connection is handled by the listener that receives it. Default is false. | |||
|
|||
per_connection_buffer_limit_bytes | |||
*(optional, integer)* Soft limit on size of the listener's new connection read and write buffers. If unspecified, an implementation defined default is applied (1MB). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 100 col line break
include/envoy/event/dispatcher.h
Outdated
* @return Network::ListenerPtr a new listener that is owned by the caller. | ||
*/ | ||
virtual Network::ListenerPtr createListener(Network::ConnectionHandler& conn_handler, | ||
Network::ListenSocket& socket, | ||
Network::ListenerCallbacks& cb, | ||
Stats::Store& stats_store, bool bind_to_port, | ||
bool use_proxy_proto, bool use_orig_dst) PURE; | ||
bool use_proxy_proto, bool use_orig_dst, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, to ask you to do this, but I have a feeling we are going to keep adding params/options here. (I know soon we will split use_original_dst into use_orginal_port/use_original_address, etc.). Can we define a struct ListenerOptions
and just pass that. That way we don't have to change a gazillion mocks and callsites the next time we add a param.
include/envoy/event/dispatcher.h
Outdated
* @return Network::ListenerPtr a new listener that is owned by the caller. | ||
*/ | ||
virtual Network::ListenerPtr createListener(Network::ConnectionHandler& conn_handler, | ||
Network::ListenSocket& socket, | ||
Network::ListenerCallbacks& cb, | ||
Stats::Store& stats_store, bool bind_to_port, | ||
bool use_proxy_proto, bool use_orig_dst) PURE; | ||
bool use_proxy_proto, bool use_orig_dst, | ||
size_t per_connection_buffer_limit_bytes) PURE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of size_t, can we be specific with either uint32_t or uint64_t (probably uint32_t). Same applies all the other places we reference this.
@@ -42,7 +42,12 @@ const std::string Json::Schema::LISTENER_SCHEMA(R"EOF( | |||
"ssl_context" : {"$ref" : "#/definitions/ssl_context"}, | |||
"bind_to_port" : {"type": "boolean"}, | |||
"use_proxy_proto" : {"type" : "boolean"}, | |||
"use_original_dst" : {"type" : "boolean"} | |||
"use_original_dst" : {"type" : "boolean"}, | |||
"per_connection_buffer_limit_bytes" : { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"per_connection_read_buffer_limit_bytes" ? Next we will have write high/low watermark so might get confusing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning on using per_connection_buffer_limit_bytes to drive both the watermark for the write buffer (automatically setting low watermark at a fraction like 0.5) and the read buffer, under the assumption that we want to keep config simple and that read/write buffer limits should be somewhat symmetric in general. I know there are scenarios where this isn't true, but this could be reasonable for v1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sounds good.
include/envoy/network/connection.h
Outdated
* Set a soft limit on the size of the read buffer prior to flushing to further stages in the | ||
* processing pipeline. | ||
*/ | ||
virtual void setReadBufferLimit(size_t limit) PURE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_t
include/envoy/network/listener.h
Outdated
return {.bind_to_port_ = true, | ||
.use_proxy_proto_ = false, | ||
.use_original_dst_ = false, | ||
.per_connection_buffer_limit_bytes_ = false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= 0
@@ -87,6 +98,7 @@ class ConnectionImpl : public virtual Connection, | |||
Address::InstancePtr local_address_; | |||
Buffer::OwnedImpl read_buffer_; | |||
Buffer::OwnedImpl write_buffer_; | |||
size_t read_buffer_limit_ = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_t
@@ -63,6 +63,7 @@ class ConnectionImpl : public virtual Connection, | |||
Ssl::Connection* ssl() override { return nullptr; } | |||
State state() override; | |||
void write(Buffer::Instance& data) override; | |||
void setReadBufferLimit(size_t limit) override { read_buffer_limit_ = limit; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_t
@@ -47,6 +47,7 @@ class ListenerImpl : public Listener { | |||
const bool use_proxy_proto_; | |||
ProxyProtocol proxy_protocol_; | |||
const bool use_original_dst_; | |||
const size_t per_connection_buffer_limit_bytes_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just have a ListenerOptions as a member var and then you can just copy it in via passed in options.
Signed-off-by: Shikugawa <Shikugawa@gmail.com>
Because we shared the `release` bazel config between both iOS and Android, Android builds were incorrectly having llvm bitcode enabled for them. Signed-off-by: Keith Smiley <keithbsmiley@gmail.com> Signed-off-by: JP Simard <jp@jpsim.com>
Because we shared the `release` bazel config between both iOS and Android, Android builds were incorrectly having llvm bitcode enabled for them. Signed-off-by: Keith Smiley <keithbsmiley@gmail.com> Signed-off-by: JP Simard <jp@jpsim.com>
…read buffer limits (#150).
Baby steps towards flow control. This patch plumbs the TCP connection buffer limits to the listener
and enforces it on the read buffer only. Later patches will also plumb to the upstream cluster
connection and cover the write buffer (which requires the watermark API).