Skip to content

Commit a476f09

Browse files
thibowkAurelienGasser
authored andcommitted
feat: allow configuring gRPC keepalive (#478)
Signed-off-by: Thibaud Martinez <thibaud.martinez@owkin.com> Signed-off-by: Aurélien Gasser <aurelien.gasser@gmail.com>
1 parent 7190f3a commit a476f09

File tree

6 files changed

+46
-7
lines changed

6 files changed

+46
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.31.2] 2022-09-30
9+
10+
### Added
11+
12+
- Allow configuring gRPC keepalive
13+
814
## [0.31.1] 2022-09-29
915

1016
### Fixed

backend/backend/settings/common.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def build_broker_url(user: str, password: str, host: str, port: str) -> str:
131131
"django_structlog.middlewares.CeleryMiddleware",
132132
]
133133

134-
135134
DJANGO_LOG_SQL_QUERIES = to_bool(os.environ.get("DJANGO_LOG_SQL_QUERIES", "True"))
136135
if DJANGO_LOG_SQL_QUERIES:
137136
MIDDLEWARE.append("libs.sql_printing_middleware.SQLPrintingMiddleware")
@@ -282,7 +281,6 @@ def build_broker_url(user: str, password: str, host: str, port: str) -> str:
282281
WORKER_PVC_SUBTUPLE = os.environ.get("WORKER_PVC_SUBTUPLE")
283282
WORKER_REPLICA_SET_NAME = os.environ.get("WORKER_REPLICA_SET_NAME")
284283

285-
286284
NAMESPACE = os.getenv("NAMESPACE")
287285
HOSTNAME = os.getenv("HOSTNAME")
288286

@@ -316,7 +314,6 @@ def build_broker_url(user: str, password: str, host: str, port: str) -> str:
316314
+ ["django_prometheus.middleware.PrometheusAfterMiddleware"]
317315
)
318316

319-
320317
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000
321318

322319
# Uploaded file max size, in bytes

backend/backend/settings/deps/orchestrator.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,29 @@
1010
ORCHESTRATOR_TLS_CLIENT_CERT_PATH = os.environ.get("ORCHESTRATOR_TLS_CLIENT_CERT_PATH")
1111
ORCHESTRATOR_TLS_CLIENT_KEY_PATH = os.environ.get("ORCHESTRATOR_TLS_CLIENT_KEY_PATH")
1212
ORCHESTRATOR_RETRY_DELAY = 1
13-
ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS = int(os.environ.get("ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS", "5000"))
13+
14+
# @ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS: The period (in milliseconds) after which a keepalive ping is sent on the
15+
# transport.
16+
#
17+
# NB: For keepalive to work properly and as intended, the client-side keepalive settings should be in agreement
18+
# with the server-side settings. If a client sends pings more often than the server is willing to accept,
19+
# the connection will be terminated with a GOAWAY frame with "too_many_pings" as the debug data.
20+
ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS = int(os.getenv("ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS", "60000"))
21+
22+
# @ORCHESTRATOR_GRPC_KEEPALIVE_TIMEOUT_MS: The amount of time (in milliseconds) the sender of the keepalive ping
23+
# waits for an acknowledgement. If it does not receive an acknowledgement within this time, it will close
24+
# the connection.
25+
ORCHESTRATOR_GRPC_KEEPALIVE_TIMEOUT_MS = int(os.getenv("ORCHESTRATOR_GRPC_KEEPALIVE_TIMEOUT_MS", "20000"))
26+
27+
# @ORCHESTRATOR_GRPC_KEEPALIVE_PERMIT_WITHOUT_CALLS: If set to 1 (0: false; 1: true), allows keepalive pings
28+
# to be sent even if there are no calls in flight.
29+
ORCHESTRATOR_GRPC_KEEPALIVE_PERMIT_WITHOUT_CALLS = bool(
30+
int(os.getenv("ORCHESTRATOR_GRPC_KEEPALIVE_PERMIT_WITHOUT_CALLS", "0"))
31+
)
32+
33+
# @ORCHESTRATOR_GRPC_KEEPALIVE_MAX_PINGS_WITHOUT_DATA The maximum number of pings that can be sent when there is
34+
# no data/header frame to be sent. gRPC Core will not continue sending pings if we run over the limit.
35+
# Setting it to 0 allows sending pings without such a restriction.
36+
ORCHESTRATOR_GRPC_KEEPALIVE_MAX_PINGS_WITHOUT_DATA = int(
37+
os.getenv("ORCHESTRATOR_GRPC_KEEPALIVE_MAX_PINGS_WITHOUT_DATA", "0")
38+
)

backend/backend/settings/test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
ORCHESTRATOR_TLS_ENABLED = False
2020
ORCHESTRATOR_MTLS_ENABLED = False
2121
ORCHESTRATOR_RETRY_DELAY = 0
22-
ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS = 10000
22+
ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS = 60000
23+
ORCHESTRATOR_GRPC_KEEPALIVE_TIMEOUT_MS = 20000
24+
ORCHESTRATOR_GRPC_KEEPALIVE_PERMIT_WITHOUT_CALLS = False
25+
ORCHESTRATOR_GRPC_KEEPALIVE_MAX_PINGS_WITHOUT_DATA = 0
2326

2427
LEDGER_MSP_ID = "testOrgMSP"
2528
LEDGER_CHANNELS = {"mychannel": {"chaincode": {"name": "mycc"}}}

backend/substrapp/orchestrator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def get_orchestrator_client(channel_name: str = None) -> OrchestratorClient:
2323
if channel_name is not None:
2424
chaincode = settings.LEDGER_CHANNELS[channel_name]["chaincode"]["name"]
2525

26-
opts = (("grpc.keepalive_time_ms", settings.ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS),)
26+
opts = (
27+
("grpc.keepalive_time_ms", settings.ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS),
28+
("grpc.keepalive_timeout_ms", settings.ORCHESTRATOR_GRPC_KEEPALIVE_TIMEOUT_MS),
29+
("grpc.keepalive_permit_without_calls", settings.ORCHESTRATOR_GRPC_KEEPALIVE_PERMIT_WITHOUT_CALLS),
30+
("grpc.http2.max_pings_without_data", settings.ORCHESTRATOR_GRPC_KEEPALIVE_MAX_PINGS_WITHOUT_DATA),
31+
)
2732

2833
return OrchestratorClient(host, channel_name, mspid, chaincode, cacert, client_key, client_cert, opts=opts)

docs/settings.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ Accepted true values for `bool` are: `1`, `ON`, `On`, `on`, `T`, `t`, `TRUE`, `T
7272

7373
| Type | Setting | Default value | Comment |
7474
|------|---------|---------------|---------|
75-
| int | `ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS` | `5000` | |
75+
| int | `ORCHESTRATOR_GRPC_KEEPALIVE_MAX_PINGS_WITHOUT_DATA` | `0` | |
76+
| int | `ORCHESTRATOR_GRPC_KEEPALIVE_PERMIT_WITHOUT_CALLS` | `0` | |
77+
| int | `ORCHESTRATOR_GRPC_KEEPALIVE_TIMEOUT_MS` | `20000` | |
78+
| int | `ORCHESTRATOR_GRPC_KEEPALIVE_TIME_MS` | `60000` | |
7679
| string | `ORCHESTRATOR_HOST` | nil | |
7780
| bool | `ORCHESTRATOR_MTLS_ENABLED` | nil | |
7881
| string | `ORCHESTRATOR_PORT` | nil | |

0 commit comments

Comments
 (0)