Skip to content

Commit 0594790

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

26 files changed

+2465
-0
lines changed

api/v1alpha1/connection_types.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,39 @@ 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+
// If unset, Envoy will fetch connections as needed to serve in-flight requests.
89+
// Allowed values are between 1.0 and 3.0.
90+
//
91+
// +kubebuilder:validation:Minimum=1
92+
// +kubebuilder:validation:Maximum=3
93+
// +optional
94+
PerUpstreamRatio *float64 `json:"perUpstreamRatio,omitempty"`
95+
96+
// PredictiveRatio configures how many connections to anticipate for an upstream cluster
97+
// for each incoming connection. Useful for latency sensitive, low-QPS services.
98+
// Relies on deterministic endpoint selection and is only supported with RoundRobin
99+
// or Random load balancing.
100+
// If unset, Envoy will fetch connections as needed to serve in-flight requests.
101+
// Minimum value is 1.0.
102+
//
103+
// +kubebuilder:validation:Minimum=1
104+
// +optional
105+
PredictiveRatio *float64 `json:"predictiveRatio,omitempty"`
73106
}
74107

75108
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,33 @@ 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+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
198+
Allowed values are between 1.0 and 3.0.
199+
maximum: 3
200+
minimum: 1
201+
type: number
202+
predictiveRatio:
203+
description: |-
204+
PredictiveRatio configures how many connections to anticipate for an upstream cluster
205+
for each incoming connection. Useful for latency sensitive, low-QPS services.
206+
Relies on deterministic endpoint selection and is only supported with RoundRobin
207+
or Random load balancing.
208+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
209+
Minimum value is 1.0.
210+
minimum: 1
211+
type: number
212+
type: object
186213
socketBufferLimit:
187214
allOf:
188215
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
@@ -2236,6 +2263,12 @@ spec:
22362263
: true'
22372264
- message: either compression or compressor can be set, not both
22382265
rule: '!has(self.compression) || !has(self.compressor)'
2266+
- message: predictiveRatio in preconnect policy only works with RoundRobin
2267+
or Random load balancers
2268+
rule: '!((has(self.connection) && has(self.connection.preconnect) &&
2269+
has(self.connection.preconnect.predictiveRatio)) && !(has(self.loadBalancer)
2270+
&& has(self.loadBalancer.type) && self.loadBalancer.type in [''Random'',
2271+
''RoundRobin'']))'
22392272
status:
22402273
description: status defines the current status of BackendTrafficPolicy.
22412274
properties:

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,33 @@ 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+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
317+
Allowed values are between 1.0 and 3.0.
318+
maximum: 3
319+
minimum: 1
320+
type: number
321+
predictiveRatio:
322+
description: |-
323+
PredictiveRatio configures how many connections to anticipate for an upstream cluster
324+
for each incoming connection. Useful for latency sensitive, low-QPS services.
325+
Relies on deterministic endpoint selection and is only supported with RoundRobin
326+
or Random load balancing.
327+
If unset, Envoy will fetch connections as needed to serve in-flight requests.
328+
Minimum value is 1.0.
329+
minimum: 1
330+
type: number
331+
type: object
305332
socketBufferLimit:
306333
allOf:
307334
- pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
@@ -1036,6 +1063,13 @@ spec:
10361063
type: object
10371064
type: object
10381065
type: object
1066+
x-kubernetes-validations:
1067+
- message: predictiveRatio in preconnect policy only works with
1068+
RoundRobin or Random load balancers
1069+
rule: '!((has(self.connection) && has(self.connection.preconnect)
1070+
&& has(self.connection.preconnect.predictiveRatio)) && !(has(self.loadBalancer)
1071+
&& has(self.loadBalancer.type) && self.loadBalancer.type
1072+
in [''Random'', ''RoundRobin'']))'
10391073
failOpen:
10401074
default: false
10411075
description: |-

0 commit comments

Comments
 (0)