mirror of
https://github.com/actix/actix-web.git
synced 2024-12-23 00:26:34 +00:00
better SharedBytes usage for h2
This commit is contained in:
parent
2b0994e448
commit
106f43e874
6 changed files with 25 additions and 16 deletions
12
README.md
12
README.md
|
@ -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
|
Name | 1 thread | 1 pipeline | 3 thread | 3 pipeline | 8 thread | 8 pipeline
|
||||||
---- | -------- | ---------- | -------- | ---------- | -------- | ----------
|
---- | -------- | ---------- | -------- | ---------- | -------- | ----------
|
||||||
Actix | 81400 | 710200 | 121000 | 1684000 | 106300 | 2206000
|
Actix | 81.400 | 710.200 | 121.000 | 1.684.000 | 106.300 | 2.206.000
|
||||||
Gotham | 61000 | 178000 | | | |
|
Gotham | 61..000 | 178.000 | | | |
|
||||||
Iron | | | | | 94500 | 78000
|
Iron | | | | | 94.500 | 78.000
|
||||||
Rocket | | | | | 95500 | failed
|
Rocket | | | | | 95.500 | failed
|
||||||
Shio | 71800 | 317800 | | | | |
|
Shio | 71.800 | 317.800 | | | | |
|
||||||
tokio-minihttp | 106900 | 1047000 | | | |
|
tokio-minihttp | 106.900 | 1.047.000 | | | |
|
||||||
|
|
||||||
Some notes on results. Iron and Rocket got tested with 8 threads,
|
Some notes on results. Iron and Rocket got tested with 8 threads,
|
||||||
which showed best results. Gothan and tokio-minihttp seem does not support
|
which showed best results. Gothan and tokio-minihttp seem does not support
|
||||||
|
|
|
@ -569,7 +569,7 @@ impl ContentEncoder {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn write_eof(&mut self) -> Result<(), io::Error> {
|
pub fn write_eof(&mut self) -> Result<(), io::Error> {
|
||||||
let encoder = mem::replace(
|
let encoder = mem::replace(
|
||||||
self, ContentEncoder::Identity(TransferEncoding::eof(SharedBytes::default())));
|
self, ContentEncoder::Identity(TransferEncoding::eof(SharedBytes::empty())));
|
||||||
|
|
||||||
match encoder {
|
match encoder {
|
||||||
ContentEncoder::Br(encoder) => {
|
ContentEncoder::Br(encoder) => {
|
||||||
|
|
14
src/h2.rs
14
src/h2.rs
|
@ -246,11 +246,15 @@ impl Entry {
|
||||||
// Payload and Content-Encoding
|
// Payload and Content-Encoding
|
||||||
let (psender, payload) = Payload::new(false);
|
let (psender, payload) = Payload::new(false);
|
||||||
|
|
||||||
let mut req = HttpRequest::new(
|
let msg = settings.get_http_message();
|
||||||
parts.method, parts.uri, parts.version, parts.headers, Some(payload));
|
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
|
let mut req = HttpRequest::from_message(msg);
|
||||||
req.set_peer_addr(addr);
|
|
||||||
|
|
||||||
// Payload sender
|
// Payload sender
|
||||||
let psender = PayloadType::new(req.headers(), psender);
|
let psender = PayloadType::new(req.headers(), psender);
|
||||||
|
@ -270,7 +274,7 @@ impl Entry {
|
||||||
Entry {task: task.unwrap_or_else(|| Pipeline::error(HTTPNotFound)),
|
Entry {task: task.unwrap_or_else(|| Pipeline::error(HTTPNotFound)),
|
||||||
payload: psender,
|
payload: psender,
|
||||||
recv: recv,
|
recv: recv,
|
||||||
stream: H2Writer::new(resp),
|
stream: H2Writer::new(resp, settings.get_shared_bytes()),
|
||||||
flags: EntryFlags::empty(),
|
flags: EntryFlags::empty(),
|
||||||
capacity: 0,
|
capacity: 0,
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,19 @@ pub(crate) struct H2Writer {
|
||||||
encoder: PayloadEncoder,
|
encoder: PayloadEncoder,
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
written: u64,
|
written: u64,
|
||||||
|
buffer: SharedBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl H2Writer {
|
impl H2Writer {
|
||||||
|
|
||||||
pub fn new(respond: Respond<Bytes>) -> H2Writer {
|
pub fn new(respond: Respond<Bytes>, buf: SharedBytes) -> H2Writer {
|
||||||
H2Writer {
|
H2Writer {
|
||||||
respond: respond,
|
respond: respond,
|
||||||
stream: None,
|
stream: None,
|
||||||
encoder: PayloadEncoder::empty(SharedBytes::default()),
|
encoder: PayloadEncoder::empty(buf.clone()),
|
||||||
flags: Flags::empty(),
|
flags: Flags::empty(),
|
||||||
written: 0,
|
written: 0,
|
||||||
|
buffer: buf,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +118,7 @@ impl Writer for H2Writer {
|
||||||
|
|
||||||
// prepare response
|
// prepare response
|
||||||
self.flags.insert(Flags::STARTED);
|
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() {
|
if let Body::Empty = *msg.body() {
|
||||||
self.flags.insert(Flags::EOF);
|
self.flags.insert(Flags::EOF);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,10 @@ impl Drop for SharedBytes {
|
||||||
|
|
||||||
impl SharedBytes {
|
impl SharedBytes {
|
||||||
|
|
||||||
|
pub fn empty() -> Self {
|
||||||
|
SharedBytes(None, None)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(bytes: Rc<BytesMut>, pool: Rc<SharedBytesPool>) -> SharedBytes {
|
pub fn new(bytes: Rc<BytesMut>, pool: Rc<SharedBytesPool>) -> SharedBytes {
|
||||||
SharedBytes(Some(bytes), Some(pool))
|
SharedBytes(Some(bytes), Some(pool))
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,6 @@ impl<S> HttpRequest<S> {
|
||||||
// get mutable reference for inner message
|
// get mutable reference for inner message
|
||||||
// mutable reference should not be returned as result for request's method
|
// mutable reference should not be returned as result for request's method
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(mutable_transmutes)]
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))]
|
||||||
fn as_mut(&self) -> &mut HttpMessage {
|
fn as_mut(&self) -> &mut HttpMessage {
|
||||||
self.0.get_mut()
|
self.0.get_mut()
|
||||||
|
|
Loading…
Reference in a new issue