Why does not grpc use a lot of cpu?

679 views
Skip to first unread message

Gyuseong jo

unread,
Sep 27, 2017, 11:18:41 AM9/27/17
to grpc.io

 I created a grpc server using python. (grpc 1.6.0, python 3.5.2, ubuntu 16.04.2 LTS, 4 core cpu)

 I use ThreadPoolExcutor.
 server = grpc.server(futures.ThreadPoolExecutor(max_workers=300))

 However, always use only 25% CPU.

 It seems to use only single core.

 What should I do?

 




Nathaniel Manista

unread,
Sep 27, 2017, 7:28:33 PM9/27/17
to Gyuseong jo, grpc.io
On Wed, Sep 27, 2017 at 8:18 AM, Gyuseong jo <busj...@gmail.com> wrote:
[gRPC Python] seems to use only single core.

How many cores do you think it should use? How familiar are you with Python's Global Interpreter Lock (GIL)? How likely do you think it is that the single-core use that you're seeing is due to Python's GIL? What about your code is written suggests that it should be using more than one core? If you take gRPC "out of the experiment" and just exercise your service-side application code alone in a single Python interpreter, do you see it take advantage of multiple cores?

We've got some work planned for the future to better support multicore Python use cases, but for now gRPC Python is GIL-limited in most scenarios.
-Nathaniel

Gyuseong jo

unread,
Sep 27, 2017, 10:39:47 PM9/27/17
to grpc.io
This is server code:
 
    def queryResult(self, request, context):
        count = 0
        # for index in range(0, 10000000):
        #     count = count + index
        while True:
            count = count + 1
        return None 

this use cpu 25%
but this code use cpu 50%

    def queryResult(self, request, context):
        count = 0
        # for index in range(0, 10000000):
        #     count = count + index
        while True:
            print(count)
            count = count + 1
        return None 

why?

Carl Mastrangelo

unread,
Oct 3, 2017, 8:48:41 PM10/3/17
to grpc.io
Out of curiosity, why are you timing an infinite loop?

Nathaniel Manista

unread,
Oct 4, 2017, 12:33:18 PM10/4/17
to Gyuseong jo, grpc.io
Probably because of the way the Python interpreter is implemented - how much do you know on that (admittedly quite large) topic? More narrowly: how much CPU do you think those two code snippets should use, and why?
-Nathaniel

longgu...@gmail.com

unread,
Jan 12, 2018, 4:39:57 AM1/12/18
to grpc.io
 -----------------------
      
it is same to me. golang grpc server can not use as much cpu as i set.    it use at most 10 cpus.
  why? 

 



venkat...@gmail.com

unread,
Jul 26, 2018, 1:43:34 AM7/26/18
to grpc.io
Does gRPC Python support multicore use case now ? 
We are using t2.xlarge instance types for our python grpc server , it is also running on kubernetes .
this is our resource request 
 "requests": {
      "cpu": "1800m",
      "memory": "3584Mi"
 }
we would like to know can we utilize the requested cpu to the fullest .
here the grpcio version we use
grpcio==1.13.0
grpcio-tools==1.11.0

Srini Polavarapu

unread,
Aug 6, 2018, 8:29:30 PM8/6/18
to grpc.io
If your workload is CPU intensive then you should pre-fork your subprocesses and have each one start their own gRPC server. gRPC-Python does not support forking after the server is created. If your workload is not CPU intensive (i.e., subprocesses/threads block on I/O frequently) then using ThreadPoolExecutor should scale fine.
Reply all
Reply to author
Forward
0 new messages