-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add protocol buffers support for messages and gRPC services #1271
Comments
👋 Thanks for opening this issue! Get help or engage by:
|
/assignme |
Though I understand that some people might want to use gRPC, this is way too slow/heavyweight for our use case. Further, the mentioned tools currently pretty much hard-code Please ensure while doing so to put such things into a separate crate not polluting the |
I'm unassigning myself from this GitHub issue for now, as I'm unsure whether adding serialization and conversions with an additional layer on top will remain performant, given that the core only works with Rust structs. Furthermore, making changes to the core without introducing breaking changes is proving to be difficult. I've attached my progress so far. Please let me know if there's an alternative approach I could take to achieve this without modifying the core of OpenRaft. |
I didn't really look into your change, but I don't understand this statement. Adding gRPC to Instead, Similarly, for communication with the remote side, the network traits allow your implementation to cache whatever you like, including connections and gRPC objects to reuse for the next communication (e.g., a gRPC shell for The only serialization you need to add is for control plane stuff like voting or membership - but that's hardly performance-relevant. For example, in your change, for each communication you are opening a new connection, formatting some URLs in process. Why not put this connection to a member of Hope this helps. Can you elaborate where else do you see an issue? |
Could you share the link to your project if it’s open source and you’re comfortable sharing it? I referred to Databend, as it seemed like the only gRPC-based OpenRaft implementation I could find. However, I may have misunderstood how OpenRaft integrates with Databend, given the size and complexity of Databend’s codebase. That said, I’ll take some time to go through the codebase in more detail and attempt this again. Thank you for your input so far! If possible, I’d really appreciate it if you could leave comments on my PR with suggestions for how I could approach things differently. |
I can't speak for Databend, since I never looked into its codebase. Unfortunately, our project is not open-source, so I can't share the code. Further, I'm not that familiar with gRPC, since we use much leaner zero-copy Cap'n Proto-based serialization in our services, so I can't give you more pointers beyond the obvious - passing references to serialized objects via entries and caching existing connections in the network layer, as I already mentioned above (probably the connection caching will make the biggest difference). I remember Protobufs (which are behind gRPC) allow keeping materialized instances of serialized objects for later reuse to prevent re-allocating of memory, at least in C++ implementation, but since I'm not familiar with the interfaces, I can't help you much there. Maybe @drmingdrmer can give you some pointers into Databend's codebase how the serialization and caching is done there. |
As @schreter mentioned, for most of the types, you do not need to add conversion to use them. But instead, just assign the protobuf generated types to Openraft with openraft::declare_raft_types!(pub TypeConfig); You should tell Openraft to use the type defined in protobuf directly using: openraft::declare_raft_types!(
pub TypeConfig:
Node = openraft_proto::protobuf::BasicNode
); Currently, only the BasicNode type is defined in Protocol Buffers. Similar definitions need to be added for other types including And in order to allow Openraft to use these protobuf types, these types need to implement corresponding traits as There are a few types that can not be configured with openraft/openraft/src/entry/traits.rs Lines 24 to 38 in fc73dc7
The other issue with caching a connection in |
/assignme |
Hi, felt like we don't need a separate package for grpc inside openraft now that I understood how it works as a library :). So just added an example for grpc. Let me know your thoughts. I'll update readme if everything looks good |
It looks like an example would be good enough. Some of the data type in |
Problem statement
Currently, Openraft does not use Protocol Buffers (proto) messages; instead, it passes Rust structs for internal communication. This necessitates that anyone writing a gRPC network layer must rewrite proto files like the example found in databend's source code
Solution
Openraft can have proto file and generated pb file in the repo along with From and Into trait converters that people can use in writing thier network component
Example from kv-memstore:
Instead of
it will look something like this
Scope and tools:
The plan is to utilize
prost
andtonic
for handling proto files and generating Rust code. As I delve deeper into the codebase, I will update this section with more details.Open questions:
rust-protobuf
instead ofprost
The text was updated successfully, but these errors were encountered: