DataDog / glommio

Glommio is a thread-per-core crate that makes writing highly parallel asynchronous applications in a thread-per-core architecture easier for rustaceans.
Other
2.93k stars 161 forks source link

Implement `Send + Sync` for `ReadResult` #667

Closed ozgrakkurt closed 1 month ago

ozgrakkurt commented 1 month ago

This might be useful in a case like this:

If we copy 4MB of data, unless we are using pre-allocated huge pages in the application it causes massive amount of page faults and is a big bottleneck.

glommer commented 1 month ago

Being Send + Sync means that now you have two threads manipulating that data. If you pass ownership, than you can still pass it.

If you really want to be manipulating the same buffer in multiple threads, in the general case, that is unsafe. You can guarantee its safety by wrapping this in its own api, but that doesn't mean the general purpose api should be send + sync.

ozgrakkurt commented 1 month ago

Being Send + Sync means that now you have two threads manipulating that data. If you pass ownership, than you can still pass it.

If you really want to be manipulating the same buffer in multiple threads, in the general case, that is unsafe. You can guarantee its safety by wrapping this in its own api, but that doesn't mean the general purpose api should be send + sync.

thank you 🙏

I take the ReadResult copy into Vec<u8> and send it over but this still causes a lot of page faults when copying because the ReadResult is huge. It would be nice to be able to send it directly and drop it in the other thread but doesn't seem like this will be easy to implement on glommio side from what I understand.

Maybe I should just focus on getting my reads smaller 👍