-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Communication from c++ server to python client is too slow #22260
Comments
by the way, I also noticed that the python side gets slower and slower as the loop goes. It first took 2s to finish each iter, and after several tens of iters, it took about 6s, and after more iters, the latency can be as much as 30s. By observing the output of command |
@CoinCheung My first observation looking at your client code is that you seem to be spinning up and tearing down a channel as part of your loop. While this use case is supported, it's not going to be performant. The increasing latency with each iteration sounds weird and, if true, is probably legitimately a bug. 100% CPU also isn't normal. Can you please work things around so that you use a spin up a single shared channel for your client process and see how that affects the metrics you're gathering? |
Actually, I did have tried it, the code is like this: def run_get_batch(stub):
req = BatchRequest()
print('before call')
reply = stub.get_batch(req)
print('after call')
ims = np.frombuffer(
reply.data, dtype=reply.dtype).reshape(reply.shape)
lbs = np.array(reply.labels)
print(ims.shape)
if __name__ == "__main__":
with grpc.insecure_channel(
'localhost:50001',
options=[
('grpc.max_receive_message_length', 1 << 30),
('grpc.max_send_message_length', 1 << 30),
]
) as channel:
stub = ImageServiceStub(channel)
for _ in range(1300):
t1 = time.time()
run_get_batch()
t2 = time.time()
print('time is: {:.4f}'.format(t2 - t1)) I actually observed no difference. The speed would get slower and slower as reported above. |
This issue/PR has been automatically marked as stale because it has not had any update (including commits, comments, labels, milestones, etc) for 30 days. It will be closed automatically if no further update occurs in 7 day. Thank you for your contributions! |
??? Could an issued be closed when nobody noticed it for a long time? |
I've noticed something very similar, except my server was written in Go. The Python client is always taking more than 2 seconds to execute its first RPC within a connection/channel. Subsequent calls finish in about a millisecond each. If the server is written in Python instead, the Python client takes about 10 ms to do its first RPC. This can also be noticed when running the helloworld examples. E.g. the server is helloworld in Go and the client is from helloworld in Python with extra code for taking the time: from __future__ import print_function
import logging
import time #### added this
import grpc
import helloworld_pb2
import helloworld_pb2_grpc
def run():
with grpc.insecure_channel('localhost:50051') as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
start = time.time() #### added this
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
end = time.time() - start #### added this
print("Time in seconds:", end) #### added this
print("Greeter client received: " + response.message)
if __name__ == '__main__':
logging.basicConfig()
run() Run these together and greeter_client.py will print |
Does the community abandon python api? |
They are at least still updating the Python library. |
@CoinCheung Sorry for the slow response on this thread. I haven't had many free cycles in the recent past. I'll take a take a look in the next couple of days. |
@CoinCheung I pulled down your example and ran it, excising the I tried running a profile of your setup and found that the majority of the time is spent in
This is presumably due to the very large protos you are pushing between the client and the server. |
@CoinCheung are you running the client on Windows? |
@SimSmith No. I ran this on Linux 5.2.17. I didn't see any mention of Windows in this thread. @CoinCheung Can you confirm what platform you're running on? |
@gnossen I am running it on linux and the output of command
Also, I am not running on it directly, I am running the program in the ubuntu16.04 docker environment on that machine. |
My environment has been pushed to dockerhub, please look this issue for my environment. |
@CoinCheung Thank you for the repro container! I'm still unable to reproduce though. The RPC latencies I'm recording don't look abnormal at all: I'm not including the time to spin up a channel in these measurements, since the code in the example spins up and tears down a channel for each individual RPC. Instead, you should be using a single channel per worker subprocess. Take a look at the multiprocessing example for the particulars there. |
@CoinCheung I met the same problem. Have you found any clues ? Thanks. |
@ljch2018 Not exactly, the developer of this repo indicates that maybe I should update my operation system kernel, but I have not tried it yet. |
@CoinCheung I have tried to deploy my codes on multiple versions of kernel OS, but nothing changed. |
@ljch2018 If you'd like to file a new issue with a reproduction case, we'll be happy to take a look. The problem in this case was that I could not reproduce the latency issues on any of my machines. |
I met the same problem. my Server is C++ and Client is js in electron, I had a very small .proto.I logged in both client and server,when I called the serivce in client, it took 1-2 seconds for the server to get it, the server returned as soon as it had been called,but it took 2-5 seconds for the client to receive it! |
I found out that when I refresh my electron after it lauched, the grpc speed gets normal! then I turned off the renderer process debugger(I had attached the debugger in launch.json immediately after main process), All things gets right! I built it and tested, the speed is OK. I don't know why the renderer process debugger could affect this,but hope this is helpful to guys have the same problem like me. BY THE WAY, I logged the waitForClientReady function, it returns the error info "Failed to connect before the deadline" when I connected successfully, but do not call the callback function when I failed -- first time turn on the app with the renderer process debugger attached. |
Could you tell me how to run the server.py, client.py and protobuf? PLease |
Hello, why I tried your code but python client could not connect the sever? is there any envoriement need set?thanks a lot!!!! |
I am not sure whether this is a bug or a problem of my configuration, my code list like this:
And the client is like this:
My protobuf is like this:
The problem is that when I run this code, the c++ server claims that it uses about 200ms to finish its task, but the python client claims that it needs 2s to finish one iter. I do not know where is the overhead comes from and how could I make the client as fast as possible. Do you have any suggestions on this please ?
The text was updated successfully, but these errors were encountered: