On Wed, Aug 15, 2018 at 11:02 PM ranjith <[email protected]> wrote:

> Thanks Nathaniel for suggesting the optimizations. I did the changes in my
> code and noticed that there are 101 threads spawned (each thread mimics as
> a server running on its own port).
>

I think it's more accurate to say that since your server is servicing 101
concurrent RPCs, 101 threads are used, since the current implementation of
the server submits service of each RPC as its own function to be executed
in the application-provided thread pool.

However I noticed that data is not streaming every second from the server.
> Here is my entire code
>
> from concurrent import futures
> from multiprocessing import Process, Queue
> import time
> import math
> import grpc
> import plugin_pb2
> import plugin_pb2_grpc
> import data_streamer
> import threading
> import datetime
> import sys
> import get_sensor_data
>
> _ONE_DAY_IN_SECONDS = 60 * 60 * 24
>
>
> class OpenConfigServicer(plugin_pb2_grpc.OpenConfigServicer):
>
>         def dataSubscribe(self, request, context):
>             try:
>                 path = '/data-sensor'
>                 metadata = None
>                 data = get_sensor_data(path, metadata)
>                 data_point = data[0]
>                 while True:
>                     print 'test:{}, {}'.format(threading.current_thread(),
> datetime.datetime.now())
>                     yield data_point
>                     # Each server should stream data every second
>                     time.sleep(1)
>             except Exception as e:
>                 import traceback
>                 print 'Exception is streaming data:{}, {}'.format(
>                         e, traceback.format_exc())
>
>
> def serve():
>         server = grpc.server(futures.ThreadPoolExecutor(max_workers=101))
>
> plugin_pb2_grpc.add_OpenConfigServicer_to_server(OpenConfigServicer(),
> server)
>         for i in range(50051, 50152):
>             server.add_insecure_port('[::]:' + str(i))
>         server.start()
>         try:
>             while True:
>                 time.sleep(_ONE_DAY_IN_SECONDS)
>         except KeyboardInterrupt:
>                 server.stop(0)
>
>
> if __name__ == '__main__':
>     serve()
>

This can't be your entire code, because something must be connecting to
your server and invoking RPCs. :-P What's the load on your host? How
certain are you that the threads that are servicing your RPCs have
sufficient resources to run in the time in which you wish them to run? If
you drop the number of concurrent RPCs from 101 to 50 or 20 or 10, does the
problem continue to occur?
-Nathaniel

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAEOYnAQ4ttPJfcPbvgLaBsUByGhT-A_F-5iPiit_3cgg7877nw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to