Giter Site home page Giter Site logo

an attempt to impl zero-copy about realm HOT 2 CLOSED

zhboner avatar zhboner commented on August 16, 2024
an attempt to impl zero-copy

from realm.

Comments (2)

zhboner avatar zhboner commented on August 16, 2024

Zero copy would be a big improvement to the current implemention, but I don't think it is ready in tokio as mentioned in this issue tokio-rs/tokio#2438

from realm.

zephyrchien avatar zephyrchien commented on August 16, 2024

Yup, zero-copy is of much significance, it would become a regret if Realm does not support this feature.

Tokio has its own difficulties, we could not expect Tokio to provide zero-copy APIs in the short term. But in our case, the problem could be simplified, making it possible to write a Tokio-based zero-copy API on our own.

Our async task is just to proxy 2 TCP connection, we never use buffers across tasks. If we create a buffer(pipe) within the task, we could make sure that the pipe is always valid during the async operation. When the task is finished or cancelled, the pipe will be dropped as normal.

Moreover, we could count the left bytes in the pipe, and limit the max read/write bytes when calling splice. This ensures that the pipe will never block, and we no longer need to poll the pipe, waiting for its readable/writeable event.

Given the inner fd of tokio::TcpStream has been registered to the event loop, the only thing we need to do is:

  1. wait the inner fd of TcpStream to become readable
  2. splice fd1 -> pipe_write_half
  3. wait the inner fd of another TcpStream to become writeable
  4. splice pipe_read_half -> fd2

Actually I have did this a few days ago(0abbf2b bin). I added these codes to relay.rs directly. I think the better approach is to encapsulate the pipe into a struct, and impl Drop trait for it, so that the pipe could be dropped automatically.

from realm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.