feat(server): add experimental pipeline flush aggregation option to Http

By enabling `Http::pipeline`, the connection will aggregate response
writes to try to improve sending more responses in a single syscall.
This commit is contained in:
Sean McArthur
2017-09-21 18:09:28 -07:00
parent 16e834d37c
commit dd54f20b55
4 changed files with 90 additions and 7 deletions

View File

@@ -49,6 +49,7 @@ pub use http::request::Request;
/// configured with various protocol-level options such as keepalive.
pub struct Http<B = ::Chunk> {
keep_alive: bool,
pipeline: bool,
_marker: PhantomData<B>,
}
@@ -73,6 +74,7 @@ impl<B: AsRef<[u8]> + 'static> Http<B> {
pub fn new() -> Http<B> {
Http {
keep_alive: true,
pipeline: false,
_marker: PhantomData,
}
}
@@ -85,6 +87,16 @@ impl<B: AsRef<[u8]> + 'static> Http<B> {
self
}
/// Aggregates flushes to better support pipelined responses.
///
/// Experimental, may be have bugs.
///
/// Default is false.
pub fn pipeline(&mut self, enabled: bool) -> &mut Self {
self.pipeline = enabled;
self
}
/// Bind the provided `addr` and return a server ready to handle
/// connections.
///
@@ -185,6 +197,7 @@ impl<B> fmt::Debug for Http<B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Http")
.field("keep_alive", &self.keep_alive)
.field("pipeline", &self.pipeline)
.finish()
}
}
@@ -223,8 +236,10 @@ impl<T, B> ServerProto<T> for Http<B>
} else {
http::KA::Disabled
};
let mut conn = http::Conn::new(io, ka);
conn.set_flush_pipeline(self.pipeline);
__ProtoBindTransport {
inner: future::ok(http::Conn::new(io, ka)),
inner: future::ok(conn),
}
}
}