Skip to content

Commit 72c30c4

Browse files
Mike ProsserMike Prosser
authored andcommitted
limit gRPC call rate to avoid overwhelming the server
1 parent b8e09eb commit 72c30c4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/nipanel/_panel_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import threading
7+
import time
78
from typing import Callable, TypeVar
89

910
import grpc
@@ -178,7 +179,9 @@ def _invoke_with_retry(
178179
) -> _T:
179180
"""Invoke a gRPC method with retry logic."""
180181
try:
181-
return method(*args, **kwargs)
182+
retval = method(*args, **kwargs)
183+
time.sleep(0.001) # limit gRPC call rate to avoid overwhelming the server
184+
return retval
182185
except grpc.RpcError as e:
183186
if e.code() == grpc.StatusCode.UNAVAILABLE or e.code() == grpc.StatusCode.UNKNOWN:
184187
# if the service is unavailable, we can retry the connection

0 commit comments

Comments
 (0)