I have implemented a gRPC Server to delegate tasks from a client process to this server.
Considering multiple clients I wonder if the Servicer-Class is transient or permanent.
I derive the servicer as follows:
class MyServicer(my_pb2_grpc.MyServicer):
def __init__(self):
self.attrA = 0
self.attrB = 0
self.attrC = 0
def rpcMethodA(self, request, context):
self.attrA += 1
def rpcMethodB(self, request, context):
...
The server starts like
server = grpc.server(futures.ThreadPoolExecutor())
my_pb2_grpc.add_MyServicer_to_server(MyServicer(), server)
server.add_insecure_port('[::]:50000')
server.start()
As shown, MyServicer
has attributes per instance. Is that object maintained ? Will attrA
be incremented for that one instance of the servicer class which is called by one specific client ?
Will there be multiple instances bound for each client ?
How long will that instance exist ? Is it re-created on each new call ?
From testing the behaviour, the gRPC Servicer exposes this behaviour:
Sessions: No session management.
Servicer Lifetime: The servicer instance persists up to server termination.
The derived servicer is used for every client connecting to the server. The attribute attrA
will be incremented as long as the server runs.