Conversation
|
That code seems (IIRC) pretty similar to what
Our testing method is a bit different. I used a large file and a single client at a time. |
|
I guess we should have both benchmarks in code somewhere, but I'll stick to Using
That seems kind of ridiculous. I'm not even sure if using fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Option<Self::Item>> {
match block_in_place(|| {
self.buf.reserve(BUF_SIZE);
let slice = self.buf.bytes_mut();
let slice = unsafe {
std::slice::from_raw_parts_mut(slice.as_mut_ptr() as *mut u8, slice.len())
};
(&*self.file).read(slice)
}) {
Ok(0) => Poll::Ready(None),
Ok(size) => {
unsafe { self.buf.advance_mut(size) };
let retval = self.buf.split().freeze();
Poll::Ready(Some(Ok(retval)))
}
Err(e) => Poll::Ready(Some(Err(e))),
}
} |
|
Well that's a nice improvement, right? :-). Yeah, pity it won't with with the single-threaded runtime. Maybe we can do nothing and wait for tokio to fix the fs performance. Otherwise it's safe to use AFAICT. |
Code is rough, and not sure if this is a good idea. Just playing around with ideas in #24.
This bypasses
tokio::fsand directly usesspawn_blockinginspired by Tokio internals. This allows us to skip Tokio's internal buffering, and read directly into our ownBytesMut.It looks like, at least on macOS, the OS will fill whatever size buffer we give it.
Some relative results on my own machine using the example server with:
ab -n 1000 -c 10 http://127.0.0.1:3000/search-index.js(an 975K file), and tweaking our ownBUF_SIZE:These numbers are really shifty, though. But what I do find interesting is that there's an apparent ~13% increase comparing the two runs with 8 KB buffers.
Besides skipping a copy, the other thing I thought might make a difference is the change in
open_with_metadata. Through Tokio internals, we previously did separatespawn_blockingcalls for the open and stat steps there, but I combined these in this PR. To try eliminate this, I split the new code into two manualspawn_blockingcalls and got these numbers:So that only accounts for maybe ~1.5% of that 13% gain.
cc @lnicola