1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

better SharedBytes usage for h2

This commit is contained in:
Nikolay Kim 2017-12-14 20:48:31 -08:00
parent 2b0994e448
commit 106f43e874
6 changed files with 25 additions and 16 deletions

View File

@ -76,12 +76,12 @@ Each result is best of five runs. All measurements are req/sec.
Name | 1 thread | 1 pipeline | 3 thread | 3 pipeline | 8 thread | 8 pipeline
---- | -------- | ---------- | -------- | ---------- | -------- | ----------
Actix | 81400 | 710200 | 121000 | 1684000 | 106300 | 2206000
Gotham | 61000 | 178000 | | | |
Iron | | | | | 94500 | 78000
Rocket | | | | | 95500 | failed
Shio | 71800 | 317800 | | | | |
tokio-minihttp | 106900 | 1047000 | | | |
Actix | 81.400 | 710.200 | 121.000 | 1.684.000 | 106.300 | 2.206.000
Gotham | 61..000 | 178.000 | | | |
Iron | | | | | 94.500 | 78.000
Rocket | | | | | 95.500 | failed
Shio | 71.800 | 317.800 | | | | |
tokio-minihttp | 106.900 | 1.047.000 | | | |
Some notes on results. Iron and Rocket got tested with 8 threads,
which showed best results. Gothan and tokio-minihttp seem does not support

View File

@ -569,7 +569,7 @@ impl ContentEncoder {
#[inline(always)]
pub fn write_eof(&mut self) -> Result<(), io::Error> {
let encoder = mem::replace(
self, ContentEncoder::Identity(TransferEncoding::eof(SharedBytes::default())));
self, ContentEncoder::Identity(TransferEncoding::eof(SharedBytes::empty())));
match encoder {
ContentEncoder::Br(encoder) => {

View File

@ -246,11 +246,15 @@ impl Entry {
// Payload and Content-Encoding
let (psender, payload) = Payload::new(false);
let mut req = HttpRequest::new(
parts.method, parts.uri, parts.version, parts.headers, Some(payload));
let msg = settings.get_http_message();
msg.get_mut().uri = parts.uri;
msg.get_mut().method = parts.method;
msg.get_mut().version = parts.version;
msg.get_mut().headers = parts.headers;
msg.get_mut().payload = Some(payload);
msg.get_mut().addr = addr;
// set remote addr
req.set_peer_addr(addr);
let mut req = HttpRequest::from_message(msg);
// Payload sender
let psender = PayloadType::new(req.headers(), psender);
@ -270,7 +274,7 @@ impl Entry {
Entry {task: task.unwrap_or_else(|| Pipeline::error(HTTPNotFound)),
payload: psender,
recv: recv,
stream: H2Writer::new(resp),
stream: H2Writer::new(resp, settings.get_shared_bytes()),
flags: EntryFlags::empty(),
capacity: 0,
}

View File

@ -31,17 +31,19 @@ pub(crate) struct H2Writer {
encoder: PayloadEncoder,
flags: Flags,
written: u64,
buffer: SharedBytes,
}
impl H2Writer {
pub fn new(respond: Respond<Bytes>) -> H2Writer {
pub fn new(respond: Respond<Bytes>, buf: SharedBytes) -> H2Writer {
H2Writer {
respond: respond,
stream: None,
encoder: PayloadEncoder::empty(SharedBytes::default()),
encoder: PayloadEncoder::empty(buf.clone()),
flags: Flags::empty(),
written: 0,
buffer: buf,
}
}
@ -116,7 +118,7 @@ impl Writer for H2Writer {
// prepare response
self.flags.insert(Flags::STARTED);
self.encoder = PayloadEncoder::new(SharedBytes::default(), req, msg);
self.encoder = PayloadEncoder::new(self.buffer.clone(), req, msg);
if let Body::Empty = *msg.body() {
self.flags.insert(Flags::EOF);
}

View File

@ -99,6 +99,10 @@ impl Drop for SharedBytes {
impl SharedBytes {
pub fn empty() -> Self {
SharedBytes(None, None)
}
pub fn new(bytes: Rc<BytesMut>, pool: Rc<SharedBytesPool>) -> SharedBytes {
SharedBytes(Some(bytes), Some(pool))
}

View File

@ -154,7 +154,6 @@ impl<S> HttpRequest<S> {
// get mutable reference for inner message
// mutable reference should not be returned as result for request's method
#[inline]
#[allow(mutable_transmutes)]
#[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))]
fn as_mut(&self) -> &mut HttpMessage {
self.0.get_mut()