-
Notifications
You must be signed in to change notification settings - Fork 4
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
Migrate from GRPC to JSON RPC (with binary variant for higher performance) #495
Comments
This now takes priority over all GRPC problems. |
Because we have pre-existing experience with protobuf. And we have a large corpus of protobuf definitions already. (Even though we will be reworking those with respect to JSON RPC) Then protobuf is probably a good choice for our binary alternative encoding. However the choice of protobuf library is important too. Our existing stack is pretty complex involving This all seemingly can be replaced with 1 library: https://github.com/bufbuild/protobuf-es. |
There are some things we need further specify above the JSON RPC spec: https://www.jsonrpc.org/specification. Because this is light on the details. Firstly if we were to use the Secondly the error structure doesn't quite match our serialiation atm. We can stuff our entire error serialisation into the Furthermore, we have to consider what usage is the |
The request object is an open spec. We could add additional properties to a request object, in order to cover the usage of metadata we have in GRPC. In GRPC there's leading and trailing metadata: #249 (comment) But if we do with the request object, we could actually add metadata to every single request object. |
The response object can also be extended with |
Solving this problem should also involve bringing in rxjs properly. |
Still to spec out:
|
I've recently created a WIP Basically web streams doesn't have a native "duplex" stream. The only closest is the So the first order of business is to develop a function that maps;
To
Where JSON is the JSON RPC message format. Although we have some requirements regarding leading headers and trailing headers discussed in #249 (#249 (comment)). |
@tegefaulkes start prototyping this implementation with an new PR targetting this epic. I think having a new |
@tegefaulkes is this the larger epic? Please link all new issues created involving RPC migration here including the recent issues you created. |
I linked the new RPC issues to this epic. |
Also pending is single class files should be using default export. The migration of client handlers kept the GRPC style handlers. But with agent handler migration we should switch over properly. |
With the latest merges, the demos shouild still work right? CLI demo and agent to agent demo we sent to Mercury. |
I added MatrixAI/js-rpc#1 to this epic too. |
Just a clarification, do we actually have a binary protocol atm using protobuf? Or do we just switch from JSONRPC to raw binary stream such as during file upload? @tegefaulkes can you expand on the relevant handlers and where this is applied. |
We don't have a protocol per say. But we can send anything over the raw streams. That could be protobuf, BISON or whatever. AFAIK the demo should still work. All the relevant tests are still working. |
Can you explain how this works in the context of file uploading? Explain in reference to one of the client service handlers. What happens during the streaming? It should be client streaming right? Then initial message is JSON, then subsequently it's just chunks of the raw file being uploaded? How does one signal end of file? Just by ending stream? I need more clarity on this. |
It's down to implementation of the handlers. but you'd include metadata in the header message and then just start writing the contents of the file to the stream. and then end the writable of the RPC stream to signal the end. You can if you wanted to build an extra layer of protocol over this. You will also have to deal with Endianness if you don't serialise the data with something like protobuf but thats a normal concern for raw binary streams. |
Ok so how does it currently work with respect to What are the handlers currently implemented to do? Are we dealing with endianess? Is it possible that the client side may be a different endianess compared to the server side? Like if we are on an intel machine and send it to a different kind of machine could that cause problems? |
It's possible? I'm not sure, its definitely something to look out for. As for the handlers. I think anything that would be sending data such as secrets is implemented pretty simply right now. create and get are sending the secrets contents in a binary string and not even streaming it. So It needs to be changed to do streaming. |
Ok so we need to change them to streaming and we also need to change them to using protobuf which at the very least would fix any issues with endianness. This reminds me of the HTTP style uploads which switch from http request to multipart upload format. In this sense we should do something very similar. Have a parameter that indicates the type of request. |
New issue at MatrixAI/js-rpc#2. |
I think this is what you wanted to be tagged in @CMCDragonkai |
Can #525 address this as well? It's one big QUIC integration plus RPC migration. There's alot of subissues under this epic that we could address, but some of it can be pushed to later. |
I could but I'd rather not 'kitchen sink' PRs. |
After some discussion regarding MatrixAI/js-rpc#2. It is now understood that we don't need to embed protobuf or cbor or some binary variant into our RPC. The RPC can already just drop down to byte level streams (this functionality is tracked in MatrixAI/js-rpc#2). Once it is dropped to the binary level, it is up to the RPC caller and handlers to decide to use whatever data format they want. If they wish to use protobuf they can, if they wish to use CBOR they can. But the RPC system itself doesn't require this functionality by default. There are 2 usecases for using Protobuf/CBOR:
For usecase 1, we should prefer to use protobuf or cbor, and not mix the usage. Protobuf has more wider acceptance, but CBOR has more support for the native types of JS. CBOR is likely to be used in the DB when MatrixAI/js-db#58 is done. For usecase 2, for simplicity I believe we should migrate to using the base64url style rather than the |
As per the discussion in MatrixAI/js-ws#3 Do note that there's quite a few levels of encapsulation here for websocket transport.
Error management should be specified too. |
There should be tests for uploading and downloading files using the raw stream from Polykey client to Polykey agent, and then synchronising those vaults to agent to agent. In both hops, they should be dropping down to raw streams. |
This is done with rpc and ws integrated. No more GRPC is in PK. |
Note I removed the pagination issue out of this. Those are usability issues to be applied separately. |
Specification
Due to various issues with GRPC, and a combined effort to replace both the networking in #234 and transport agnostic RPC #249, this epic covers all the problems we have with GRPC and changes we will need to do to the RPC handling architecture.
We want to go with JSON RPC because it is going to be the most suitable for third party integration.
We can have a binary protocol format for increased performance when this is detected. Candidates are:
We need to choose one based on benchmarks, and UI/UX of converting to our internal datasets, reliability of third party libraries, portability of parsing and generating libraries and wide-deployment.
Additional context
See all sub issues under this epic.
Tasks
The text was updated successfully, but these errors were encountered: