본문 바로가기

etc

[gRPC] gRPC 간단 정리

RPC(Remote Procedure call)??

 

remote procedure call(RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction.
RPCs are a form of inter-process communication(IPC), in that different processes have different address spaces

- https://en.wikipedia.org/wiki/Remote_procedure_call

 

- 개발자는 remote interaction의 detail을 신경쓰지 않고 원격에 있는 프로시저를 로컬에서 사용할 수 있습니다.

- request-response 형태의 프로토콜으로, client는 known remote server에 parameter와 함께 request message를 전달하여 프로시저를 실행하게 됩니다.

 

 

이벤트 흐름

 

1. client는 client stub에 로컬 프로시저를 호출합니다.

2. client stub은 요청을 잘 조립해서(marshalling) request message를 만들고 system call을 만들게됩니다.

3. client쪽 os는 server에 해당 message를 전송합니다.

4. server쪽 os는 server stub으로 들어오는 패킷을 넘깁니다.

5. server stub은 메시지를 분해하여 요청 파라미터를 얻게됩니다.(unmarshalling)

6. server stub은 server 프로시저를 호출하고, 결과를 역순으로 다시 응답하게됩니다.

 

* client stub은 stub, server stub은 skeleton 로도 불리며, 각각 gateway역할을 하고 메시지를 다루는 인터페이스? 정도로 이해하였습니다.

 

 

gRPC??

 

In gPRC, a client application can directly call a method on a server application on a different machine as if it were a local object, making it easier for you to create distributed applications and services. 

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 (referred to as just a client in some languages) that provides the same methods as the server.

gRPC clients and servers can run and talk to each other in a variety of environments

-
https://grpc.io/docs/what-is-grpc/introduction/

 

 

다양한 환경에서 서버와 통신할 수 있는 것을 표현한 그림

 

기본적으로 공식문서에서도 큰 틀은 rpc와 같습니다. 클라이언트에서 서버에 프로시저를 호출하게 되고, 그 반환값을 가져오게됩니다. gRPC를 이용해서 쉽게 다양한 환경(언어)의 server, client를 구성할 수 있게됩니다.. 

 

그렇다면 근본적인 의문이든다. 왜 gRPC를 쓸까?

보통 JSON을 사용하는 REST API나 XML과 달리 gRPC Protobuf 을 사용하게됩니다. 프로토콜 버퍼라고 불리며 매우 작고 인/디코딩 속도가 빠른 바이너리 직렬화 형식입니다. 당연히 바이너리 형식이기 때문에 사람이 해석할 수 없다거나하는 단점이나 크기가 매우 작다는 장점이 존재하게 됩니다. 따라서 낮은 대역폭환경이나 마이크로 서비스에 주로 이용된다고 합니다.

 

https://docs.microsoft.com/ko-kr/aspnet/core/grpc/comparison?view=aspnetcore-5.0#strict-specification 

 

gRPC 서비스와 HTTP API 비교

gRPC와 HTTP API를 비교한 방법과 권장 시나리오를 알아봅니다.

docs.microsoft.com

위 글은 gRPC와 HTTP API를 비교하는 글인데 읽어보면 어느정도 gRPC 사용에 대해 이해를 도울 수 있을거라 생각합니다.

 

 

 

protocol buffer와 go kit 프레임워크 + HTTP/gRPC 두개를 이용한 마이크로서비스 간단한 구현해보고 포스팅하도록 하겠습니다!

 

 

 

* reference

https://grpc.io/docs/what-is-grpc/introduction/ : gRPC 공식 문서

https://en.wikipedia.org/wiki/Remote_procedure_call : rpc wiki

https://en.wikipedia.org/wiki/Distributed_object_communication : stub, skeleton

 

 

 

 

 

'etc' 카테고리의 다른 글

protocol buffer 정리  (0) 2021.08.04