-
Notifications
You must be signed in to change notification settings - Fork 43
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
Buffer pool tracking issue #365
Comments
API of The user get the buffer from the registry directly and pass the ownership to the read method. |
Also note that there's |
Note about io-uring internals:
Buffer ring is a newer feature. It lets the kernel to choose an available buffer, which means the users cannot choose the buffer themselves, and should return the buffer after consuming it. |
The returned buffer might be better if it's owned: pub trait AsyncReadManaged {
type BufferPool;
type Buffer: Deref<Target = [u8]>;
async fn read_managed(
&mut self,
buffer_pool: &Self::BufferPool,
len: usize,
) -> IoResult<Self::Buffer>;
} The inner buffer pool might be |
@Berrysoft Can you provide some examples? I'm not entirely sure how this is supposed to be used. |
The usage is like this: let pool = BufferPool::new(/* count: */16, /* buffer len: */1024).unwrap();
let mut stream = TcpStream::connect(addr).await.unwrap();
// Use len = 0 to make the driver select one.
let buffer = stream.read_managed(&pool, 0).await.unwrap();
// Use buffer, and drop it to return it to the pool. |
@Berrysoft So every IO depends on some specific type of BufferPool, is that right? If users want abstraction, they need to do it themselves. |
I think so. The buffer count & buffer len of the buffer pool is controled by the user, and they can even create many pools if they want. |
What about this: trait BufferPool {
type Buffer;
}
trait AsyncReadManaged {
type Pool: BufferPool + ?Sized;
async fn read_managed(
&mut self,
buffer_pool: &Self::Pool,
len: usize,
) -> IoResult<<Self::Pool as BufferPool>::Buffer>;
} It's still flexibile (i.e., no other constraint on buffer pool, hell it can even be |
I have thought about this design, but didn't choose it because, there might be a case that the implementer of |
Prior Art
AsyncReadBufferPool::read_buffer_pool
,AsyncReadAtBufferPool::read_at_buffer_pool
, withBufferPool
andBuffer
associated typestokio-uring
(read_fixed
/write_fixed
ofTcpStream
)In Progress
AsyncReadManaged::read_managed
AsyncReadManagedAt::read_managed_at
Any other advice or design?
The text was updated successfully, but these errors were encountered: