Skip to content

Commit 1ebcc6e

Browse files
committed
preconnect policy
Signed-off-by: jukie <[email protected]>
1 parent 16aa810 commit 1ebcc6e

27 files changed

+2384
-0
lines changed

api/v1alpha1/connection_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,37 @@ type BackendConnection struct {
7070
// +optional
7171
// +notImplementedHide
7272
SocketBufferLimit *resource.Quantity `json:"socketBufferLimit,omitempty"`
73+
74+
// Preconnect configures proactive upstream connections to reduce latency by establishing
75+
// connections before they’re needed and avoiding connection establishment overhead.
76+
// If unset, Envoy will fetch connections as needed to serve in-flight requests.
77+
//
78+
// +optional
79+
Preconnect *PreconnectPolicy `json:"preconnect,omitempty"`
80+
}
81+
82+
// Preconnect configures proactive upstream connections to reduce latency by establishing
83+
// connections before they’re needed and avoiding connection establishment overhead.
84+
type PreconnectPolicy struct {
85+
// PerUpstreamRatio configures the ratio of connections to anticipate per-upstream for each
86+
// incoming connection. This is most effective for high-QPS or latency-sensitive services
87+
// where connection establishment cost is significant.
88+
// Allowed values are between 1.0 and 3.0.
89+
//
90+
// +kubebuilder:validation:Minimum=1
91+
// +kubebuilder:validation:Maximum=3
92+
// +optional
93+
PerUpstreamRatio *float64 `json:"perUpstreamRatio,omitempty"`
94+
95+
// PredictiveRatio configures how many connections to anticipate for an upstream cluster
96+
// for each incoming connection. Useful for latency sensitive, low-QPS services.
97+
// Relies on deterministic endpoint selection and is only supported with RoundRobin
98+
// or Random load balancing.
99+
// Minimum value is 1.0.
100+
//
101+
// +kubebuilder:validation:Minimum=1
102+
// +optional
103+
PredictiveRatio *float64 `json:"predictiveRatio,omitempty"`
73104
}
74105

75106
type ConnectionLimit struct {

api/v1alpha1/shared_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ type BackendCluster struct {
585585

586586
// ClusterSettings provides the various knobs that can be set to control how traffic to a given
587587
// backend will be configured.
588+
//
589+
// +kubebuilder:validation:XValidation:rule="!((has(self.connection) && has(self.connection.preconnect) && has(self.connection.preconnect.predictiveRatio)) && !(has(self.loadBalancer) && has(self.loadBalancer.type) && self.loadBalancer.type in ['Random', 'RoundRobin']))",message="predictiveRatio in preconnect policy only works with RoundRobin or Random load balancers"
588590
type ClusterSettings struct {
589591
// LoadBalancer policy to apply when routing traffic from the gateway to
590592
// the backend endpoints. Defaults to `LeastRequest`.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,31 @@ spec:
183183
For example, 20Mi, 1Gi, 256Ki etc.
184184
Note: that when the suffix is not provided, the value is interpreted as bytes.
185185
x-kubernetes-int-or-string: true
186+
preconnect:
187+
description: |-
188+
Preconnect configures proactive upstream connections to reduce latency by establishing
189+
connections before they’re needed and avoiding connection establishment overhead.
190+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
191+
properties:
192+
perUpstreamRatio:
193+
description: |-
194+
PerUpstreamRatio configures the ratio of connections to anticipate per-upstream for each
195+
incoming connection. This is most effective for high-QPS or latency-sensitive services
196+
where connection establishment cost is significant.
197+
Allowed values are between 1.0 and 3.0.
198+
maximum: 3
199+
minimum: 1
200+
type: number
201+
predictiveRatio:
202+
description: |-
203+
PredictiveRatio configures how many connections to anticipate for an upstream cluster
204+
for each incoming connection. Useful for latency sensitive, low-QPS services.
205+
Relies on deterministic endpoint selection and is only supported with RoundRobin
206+
or Random load balancing.
207+
Minimum value is 1.0.
208+
minimum: 1
209+
type: number
210+
type: object
186211
socketBufferLimit:
187212
allOf:
188213
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
@@ -2236,6 +2261,12 @@ spec:
22362261
: true'
22372262
- message: either compression or compressor can be set, not both
22382263
rule: '!has(self.compression) || !has(self.compressor)'
2264+
- message: predictiveRatio in preconnect policy only works with RoundRobin
2265+
or Random load balancers
2266+
rule: '!((has(self.connection) && has(self.connection.preconnect) &&
2267+
has(self.connection.preconnect.predictiveRatio)) && !(has(self.loadBalancer)
2268+
&& has(self.loadBalancer.type) && self.loadBalancer.type in [''Random'',
2269+
''RoundRobin'']))'
22392270
status:
22402271
description: status defines the current status of BackendTrafficPolicy.
22412272
properties:

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyextensionpolicies.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,31 @@ spec:
302302
For example, 20Mi, 1Gi, 256Ki etc.
303303
Note: that when the suffix is not provided, the value is interpreted as bytes.
304304
x-kubernetes-int-or-string: true
305+
preconnect:
306+
description: |-
307+
Preconnect configures proactive upstream connections to reduce latency by establishing
308+
connections before they’re needed and avoiding connection establishment overhead.
309+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
310+
properties:
311+
perUpstreamRatio:
312+
description: |-
313+
PerUpstreamRatio configures the ratio of connections to anticipate per-upstream for each
314+
incoming connection. This is most effective for high-QPS or latency-sensitive services
315+
where connection establishment cost is significant.
316+
Allowed values are between 1.0 and 3.0.
317+
maximum: 3
318+
minimum: 1
319+
type: number
320+
predictiveRatio:
321+
description: |-
322+
PredictiveRatio configures how many connections to anticipate for an upstream cluster
323+
for each incoming connection. Useful for latency sensitive, low-QPS services.
324+
Relies on deterministic endpoint selection and is only supported with RoundRobin
325+
or Random load balancing.
326+
Minimum value is 1.0.
327+
minimum: 1
328+
type: number
329+
type: object
305330
socketBufferLimit:
306331
allOf:
307332
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
@@ -1036,6 +1061,13 @@ spec:
10361061
type: object
10371062
type: object
10381063
type: object
1064+
x-kubernetes-validations:
1065+
- message: predictiveRatio in preconnect policy only works with
1066+
RoundRobin or Random load balancers
1067+
rule: '!((has(self.connection) && has(self.connection.preconnect)
1068+
&& has(self.connection.preconnect.predictiveRatio)) && !(has(self.loadBalancer)
1069+
&& has(self.loadBalancer.type) && self.loadBalancer.type
1070+
in [''Random'', ''RoundRobin'']))'
10391071
failOpen:
10401072
default: false
10411073
description: |-

0 commit comments

Comments
 (0)