-
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
Changes from 3 commits
42bb622
a7b3478
5df5456
9c66fb6
0b27b80
0f14891
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,16 @@ class Dispatcher { | |
* (http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt) | ||
* @param use_orig_dst if a connection was redirected to this port using iptables, | ||
* allow the listener to hand it off to the listener associated to the original port | ||
* @param per_connection_buffer_limit_bytes soft limit on size of the listener's new connection | ||
* read and write buffers. | ||
* @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 commentThe 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 |
||
size_t per_connection_buffer_limit_bytes) PURE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
/** | ||
* Create a listener on a specific port. | ||
|
@@ -108,14 +111,15 @@ class Dispatcher { | |
* (http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt) | ||
* @param use_orig_dst if a connection was redirected to this port using iptables, | ||
* allow the listener to hand it off to the listener associated to the original port | ||
* @param per_connection_buffer_limit_bytes soft limit on size of the listener's new connection | ||
* read and write buffers. | ||
* @return Network::ListenerPtr a new listener that is owned by the caller. | ||
*/ | ||
virtual Network::ListenerPtr createSslListener(Network::ConnectionHandler& conn_handler, | ||
Ssl::ServerContext& ssl_ctx, | ||
Network::ListenSocket& socket, | ||
Network::ListenerCallbacks& cb, | ||
Stats::Store& stats_store, bool bind_to_port, | ||
bool use_proxy_proto, bool use_orig_dst) PURE; | ||
virtual Network::ListenerPtr | ||
createSslListener(Network::ConnectionHandler& conn_handler, Ssl::ServerContext& ssl_ctx, | ||
Network::ListenSocket& socket, Network::ListenerCallbacks& cb, | ||
Stats::Store& stats_store, bool bind_to_port, bool use_proxy_proto, | ||
bool use_orig_dst, size_t per_connection_buffer_limit_bytes) PURE; | ||
|
||
/** | ||
* Allocate a timer. @see Event::Timer for docs on how to use the timer. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,12 @@ class Connection : public Event::DeferredDeletable, public FilterManager { | |
* are installed. | ||
*/ | ||
virtual void write(Buffer::Instance& data) PURE; | ||
|
||
/** | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. uint32_t |
||
}; | ||
|
||
typedef std::unique_ptr<Connection> ConnectionPtr; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. OK sounds good. |
||
"type" : "integer", | ||
"minimum" : 0, | ||
"exclusiveMinimum" : true | ||
} | ||
}, | ||
"required": ["port", "filters"], | ||
"additionalProperties": false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. uint32_t |
||
|
||
// Network::BufferSource | ||
Buffer::Instance& getReadBuffer() override { return read_buffer_; } | ||
|
@@ -79,6 +80,16 @@ class ConnectionImpl : public virtual Connection, | |
virtual void closeSocket(uint32_t close_type); | ||
void doConnect(); | ||
void raiseEvents(uint32_t events); | ||
// Should the read buffer be drained? | ||
bool shouldDrainReadBuffer() { | ||
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 connections to provide some | ||
// fair sharing of CPU resources, the underlying event loop does not make any fairness guarantees. | ||
// Reconsider how to make fairness happen. | ||
void setReadBufferReady() { file_event_->activate(Event::FileReadyType::Read); } | ||
|
||
static const Address::InstancePtr null_local_address_; | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. uint32_t |
||
|
||
private: | ||
// clang-format off | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ class ListenerImpl : public Listener { | |
public: | ||
ListenerImpl(Network::ConnectionHandler& conn_handler, Event::DispatcherImpl& dispatcher, | ||
ListenSocket& socket, ListenerCallbacks& cb, Stats::Store& stats_store, | ||
bool bind_to_port, bool use_proxy_proto, bool use_orig_dst); | ||
bool bind_to_port, bool use_proxy_proto, bool use_orig_dst, | ||
size_t per_connection_buffer_limit_bytes); | ||
|
||
/** | ||
* Accept/process a new connection. | ||
|
@@ -47,6 +48,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 commentThe 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. |
||
|
||
private: | ||
static void errorCallback(evconnlistener* listener, void* context); | ||
|
@@ -60,9 +62,9 @@ class SslListenerImpl : public ListenerImpl { | |
SslListenerImpl(Network::ConnectionHandler& conn_handler, Event::DispatcherImpl& dispatcher, | ||
Ssl::Context& ssl_ctx, ListenSocket& socket, ListenerCallbacks& cb, | ||
Stats::Store& stats_store, bool bind_to_port, bool use_proxy_proto, | ||
bool use_orig_dst) | ||
bool use_orig_dst, size_t per_connection_buffer_limit_bytes) | ||
: ListenerImpl(conn_handler, dispatcher, socket, cb, stats_store, bind_to_port, | ||
use_proxy_proto, use_orig_dst), | ||
use_proxy_proto, use_orig_dst, per_connection_buffer_limit_bytes), | ||
ssl_ctx_(ssl_ctx) {} | ||
|
||
// ListenerImpl | ||
|
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