RPC and IPC data marshalling - networking

In RPC, the stubs at client and server needs to marshal and unmarshal data, then it sends it to the Lower layer to send it over network. Do TCP/IP also Marshal the data to binary stream? Why the Middleware needs to marshal the invocation request?
I'm trying to understand am so confused because as I know using IPC we don't marshal the data we just use send() and recv().
Thank you.

The job of the proxy is to marshal the call from the client by serializing the arguments to bytes so it can be transmitted across the network. The stub in the server deserializes them again and makes the call. Possible return values go back the same way.
There is no marshaling in TCP, it just transmit bytes.

Related

gRPC serialization behavior for local vs remote connections

In the gRPC Java implementation, are objects serialized when sent from a gRPC service with a local connection in the same process?
Suppose we have one java process with two classes A and B. If class A uses a gRPC client to send data to a gRPC server backed by class B, do the client and server share a Java object reference, or is the data serialized and sent over the established local Netty connection?
When using the in-process transport, Protobuf serialization/deserialization will generally be avoided.
The Protobuf marshaller in gRPC generates an InputStream when serializing a message. When using the in-process transport, that InputStream is passed back to the Protobuf marshaller to deserialize a message. The Protobuf marshaller implements the InputStream directly and only serializes the message when bytes are actually read from the stream. When deserializing, the marshaller checks whether it generated the InputStream and, if so, grabs the message directly and returns it without ever converting the message to bytes. This is safe because Protobuf objects in Java are immutable.
This approach is unique to grpc-java with the in-process transport. Most other implementations require serializing to bytes and use mutable protocol buffers. grpc-netty encodes to HTTP/2, so always serializes to bytes.

gRPC bi-directional stream processing with multi-threaded clients

A gRPC newbie question here.
We have a source system that exposes a bi directional gRPC stream. In order to scale our application, we wanted to process the stream data in parallel. Is it possible to have concurrent / multiple gRPC clients consuming from the stream without any conflicts in data processing / during acknowledgement process etc?
Thanks
Is this in the context of a single streaming call? In that case the answer is no. You have a single gRPC client receiving one response stream and it can use worker threads to hand off messages from the stream.
If you are thinking of multiple gRPC clients in an application talking to the same server (I don't see any advantage of doing that) each one will make a separate call and will receive a separate response stream.

MPI asynchronous sending

I need asynchronous message sending. I read about non-blocking sending on MPI (e.g. MPI_Isend or MPI_Ibcast) and functions to wait/test that sending request (MPI_Wait*/MPI_Test*). However I realize (through testing and web info) that non-blocking send might never get progress on receiver unless that sender invokes functions MPI_Wait*/MPI_Test* after it sends. How can I get a real (and optimal) asynchronous sending?
Regards

Is servlet also a kind of RPC?

As far as I understand, RPC is a client-server model while the client sends some requests to the server side and get some results back. Then, is Java servlet also a kind of RPC which uses HTTP protocol? Am I right?
Here is the very first sentence of the wikipedia article on RPC:
In computer science, a remote procedure call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding the details for this remote interaction.1 That is, the programmer writes essentially the same code whether the subroutine is local to the executing program, or remote.
So, Servlets would be an RPC mechanism if you could invoke a servlet from a client using
SomeResult r = someObject.doSomething();
That's not the case at all. To invoke a servlet, you need to explicitely send a HTTP request and encode parameters in the way the servlet expects them, then read and parse the response.

Can both ends of a gRPC connection accept method calls?

From the introduction on gRPC:
In gRPC a client application can directly call methods on a server application on a different machine as if it was a local object, making it easier for you to create distributed applications and services. As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. On the server side, the server implements this interface and runs a gRPC server to handle client calls. On the client side, the client has a stub that provides exactly the same methods as the server.
The above paragraph talks about a client and a server, with the former being the one who is invoking methods to the other. What am I wondering is: can the server-end of the connection invoke methods that have been registered on the client?
No, a server cannot invoke calls on the client. gRPC works with HTTP, and HTTP has not had such semantics in the past.
There has been discussion as to various ways to achieve such a feature, but I'm unaware of any work having started or general agreement on a design. gRPC does support bidirectional streaming, which may get you some of what you need. With bidirectional streaming the client can respond to messages from server, but the client still calls the server and only one type of message can be sent for that call.
The protocol does not implement it, but you may pretend this situation.
Define a server method that returns a stream of a ServerRequest message:
import "google/protobuf/any.proto";
service FullDuplex {
rpc WaitRequests (google.protobuf.Any) returns (stream ServerRequest);
}
message ServerRequest {
float someValue = 1;
float anotherAnother = 1;
}
ServerRequest may be an Oneof, so your may receive different types of server requests.
If you need that your client sends back a response for each request, you may create a stream from your client to the server, but you will need to implement a logic in your server side that triggers a timeout waiting for that response.
service FullDuplex {
rpc WaitRequests (stream ClientResponse) returns (stream ServerRequest);
}
What you can do is start a HTTP server in both processes and use clients at each end to initiate communication. There's a bit of boilerplate involved and you have to design a simple handshaking protocol (one end registers with the other, advertising its listen address) but it's not too much work.

Resources