Skip to content

Commit

Permalink
Add throttling logic for creating documents to provide per-cluster ra…
Browse files Browse the repository at this point in the history
…te-limiting at the HTTP route level (#13896)

To better protect the AFR service from crashing due to high counts of
creating document requests, it has been proposed that we rate limit the
“create document”, "get deltas" API route, and "connect document" socket
at a per-cluster level. We also extend the existing throttling logic to
provide per-cluster rate-limiting at the HTTP route level.
  • Loading branch information
tianzhu007 authored Feb 9, 2023
1 parent 35ba759 commit f38f7de
Show file tree
Hide file tree
Showing 18 changed files with 34,628 additions and 101 deletions.
14 changes: 9 additions & 5 deletions server/BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export class AlfredResources implements core.IResources {
public webSocketLibrary: string,
public orderManager: core.IOrdererManager,
public tenantManager: core.ITenantManager,
public restThrottler: core.IThrottler,
public socketConnectThrottler: core.IThrottler,
public restTenantThrottler: core.IThrottler,
public restClusterThrottlers: Map<string, core.IThrottler>,
public socketConnectTenantThrottler: core.IThrottler,
public socketConnectClusterThrottler: core.IThrottler,
public socketSubmitOpThrottler: core.IThrottler,
public socketSubmitSignalThrottler: core.IThrottler,
public singleUseTokenCache: core.ICache,
Expand All @@ -35,7 +37,7 @@ export class AlfredResources implements core.IResources {
public metricClientConfig: any,
public documentsCollection: core.ICollection<core.IDocument>,
public throttleAndUsageStorageManager?: core.IThrottleAndUsageStorageManager,
)
)
....

export class AlfredResourcesFactory implements core.IResourcesFactory<AlfredResources> {
Expand All @@ -49,8 +51,10 @@ export class AlfredResourcesFactory implements core.IResourcesFactory<AlfredReso
webSocketLibrary,
orderManager,
tenantManager,
restThrottler,
socketConnectThrottler,
restTenantThrottler,
restClusterThrottler,
socketConnectTenantThrottler,
socketConnectClusterThrottler
socketSubmitOpThrottler,
socketSubmitSignalThrottler,
redisJwtCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,52 @@ data:
"sessionStickinessDurationMs": {{ .Values.alfred.sessionStickinessDurationMs }},
"enableConnectionCountLogging": {{ .Values.alfred.enableConnectionCountLogging }},
"throttling": {
"restCalls": {
"maxPerMs": {{ .Values.alfred.throttling.restCalls.maxPerMs }},
"maxBurst": {{ .Values.alfred.throttling.restCalls.maxBurst }},
"minCooldownIntervalInMs": {{ .Values.alfred.throttling.restCalls.minCooldownIntervalInMs }},
"minThrottleIntervalInMs": {{ .Values.alfred.throttling.restCalls.minThrottleIntervalInMs }},
"maxInMemoryCacheSize": {{ .Values.alfred.throttling.restCalls.maxInMemoryCacheSize }},
"maxInMemoryCacheAgeInMs": {{ .Values.alfred.throttling.restCalls.maxInMemoryCacheAgeInMs }},
"enableEnhancedTelemetry": {{ .Values.alfred.throttling.restCalls.enableEnhancedTelemetry }}
"restCallsPerTenant": {
"maxPerMs": {{ .Values.alfred.throttling.restCallsPerTenant.maxPerMs }},
"maxBurst": {{ .Values.alfred.throttling.restCallsPerTenant.maxBurst }},
"minCooldownIntervalInMs": {{ .Values.alfred.throttling.restCallsPerTenant.minCooldownIntervalInMs }},
"minThrottleIntervalInMs": {{ .Values.alfred.throttling.restCallsPerTenant.minThrottleIntervalInMs }},
"maxInMemoryCacheSize": {{ .Values.alfred.throttling.restCallsPerTenant.maxInMemoryCacheSize }},
"maxInMemoryCacheAgeInMs": {{ .Values.alfred.throttling.restCallsPerTenant.maxInMemoryCacheAgeInMs }},
"enableEnhancedTelemetry": {{ .Values.alfred.throttling.restCallsPerTenant.enableEnhancedTelemetry }}
},
"socketConnections": {
"maxPerMs": {{ .Values.alfred.throttling.socketConnections.maxPerMs }},
"maxBurst": {{ .Values.alfred.throttling.socketConnections.maxBurst }},
"minCooldownIntervalInMs": {{ .Values.alfred.throttling.socketConnections.minCooldownIntervalInMs }},
"minThrottleIntervalInMs": {{ .Values.alfred.throttling.socketConnections.minThrottleIntervalInMs }},
"maxInMemoryCacheSize": {{ .Values.alfred.throttling.socketConnections.maxInMemoryCacheSize }},
"maxInMemoryCacheAgeInMs": {{ .Values.alfred.throttling.socketConnections.maxInMemoryCacheAgeInMs }},
"enableEnhancedTelemetry": {{ .Values.alfred.throttling.socketConnections.enableEnhancedTelemetry }}
"restCallsPerCluster": {
"createDoc": {
"maxPerMs": {{ .Values.alfred.throttling.restCallsPerCluster.createDoc.maxPerMs }},
"maxBurst": {{ .Values.alfred.throttling.restCallsPerCluster.createDoc.maxBurst }},
"minCooldownIntervalInMs": {{ .Values.alfred.throttling.restCallsPerCluster.createDoc.minCooldownIntervalInMs }},
"minThrottleIntervalInMs": {{ .Values.alfred.throttling.restCallsPerCluster.createDoc.minThrottleIntervalInMs }},
"maxInMemoryCacheSize": {{ .Values.alfred.throttling.restCallsPerCluster.createDoc.maxInMemoryCacheSize }},
"maxInMemoryCacheAgeInMs": {{ .Values.alfred.throttling.restCallsPerCluster.createDoc.maxInMemoryCacheAgeInMs }},
"enableEnhancedTelemetry": {{ .Values.alfred.throttling.restCallsPerCluster.createDoc.enableEnhancedTelemetry }}
},
"getDeltas": {
"maxPerMs": {{ .Values.alfred.throttling.restCallsPerCluster.getDeltas.maxPerMs }},
"maxBurst": {{ .Values.alfred.throttling.restCallsPerCluster.getDeltas.maxBurst }},
"minCooldownIntervalInMs": {{ .Values.alfred.throttling.restCallsPerCluster.getDeltas.minCooldownIntervalInMs }},
"minThrottleIntervalInMs": {{ .Values.alfred.throttling.restCallsPerCluster.getDeltas.minThrottleIntervalInMs }},
"maxInMemoryCacheSize": {{ .Values.alfred.throttling.restCallsPerCluster.getDeltas.maxInMemoryCacheSize }},
"maxInMemoryCacheAgeInMs": {{ .Values.alfred.throttling.restCallsPerCluster.getDeltas.maxInMemoryCacheAgeInMs }},
"enableEnhancedTelemetry": {{ .Values.alfred.throttling.restCallsPerCluster.getDeltas.enableEnhancedTelemetry }}
}
},
"socketConnectionsPerTenant": {
"maxPerMs": {{ .Values.alfred.throttling.socketConnectionsPerTenant.maxPerMs }},
"maxBurst": {{ .Values.alfred.throttling.socketConnectionsPerTenant.maxBurst }},
"minCooldownIntervalInMs": {{ .Values.alfred.throttling.socketConnectionsPerTenant.minCooldownIntervalInMs }},
"minThrottleIntervalInMs": {{ .Values.alfred.throttling.socketConnectionsPerTenant.minThrottleIntervalInMs }},
"maxInMemoryCacheSize": {{ .Values.alfred.throttling.socketConnectionsPerTenant.maxInMemoryCacheSize }},
"maxInMemoryCacheAgeInMs": {{ .Values.alfred.throttling.socketConnectionsPerTenant.maxInMemoryCacheAgeInMs }},
"enableEnhancedTelemetry": {{ .Values.alfred.throttling.socketConnectionsPerTenant.enableEnhancedTelemetry }}
},
"socketConnectionsPerCluster": {
"maxPerMs": {{ .Values.alfred.throttling.socketConnectionsPerCluster.maxPerMs }},
"maxBurst": {{ .Values.alfred.throttling.socketConnectionsPerCluster.maxBurst }},
"minCooldownIntervalInMs": {{ .Values.alfred.throttling.socketConnectionsPerCluster.minCooldownIntervalInMs }},
"minThrottleIntervalInMs": {{ .Values.alfred.throttling.socketConnectionsPerCluster.minThrottleIntervalInMs }},
"maxInMemoryCacheSize": {{ .Values.alfred.throttling.socketConnectionsPerCluster.maxInMemoryCacheSize }},
"maxInMemoryCacheAgeInMs": {{ .Values.alfred.throttling.socketConnectionsPerCluster.maxInMemoryCacheAgeInMs }},
"enableEnhancedTelemetry": {{ .Values.alfred.throttling.socketConnectionsPerCluster.enableEnhancedTelemetry }}
},
"submitOps": {
"maxPerMs": {{ .Values.alfred.throttling.submitOps.maxPerMs }},
Expand Down
29 changes: 27 additions & 2 deletions server/routerlicious/kubernetes/routerlicious/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,40 @@ alfred:
sessionStickinessDurationMs: 3600000
enableConnectionCountLogging: false
throttling:
restCalls:
restCallsPerTenant:
maxPerMs: 1000000
maxBurst: 1000000
minCooldownIntervalInMs: 1000000
minThrottleIntervalInMs: 1000000
maxInMemoryCacheSize: 1000
maxInMemoryCacheAgeInMs: 60000
enableEnhancedTelemetry: false
socketConnections:
restCallsPerCluster:
createDoc:
maxPerMs: 1000000
maxBurst: 1000000
minCooldownIntervalInMs: 1000000
minThrottleIntervalInMs: 1000000
maxInMemoryCacheSize: 1000
maxInMemoryCacheAgeInMs: 60000
enableEnhancedTelemetry: false
getDeltas:
maxPerMs: 1000000
maxBurst: 1000000
minCooldownIntervalInMs: 1000000
minThrottleIntervalInMs: 1000000
maxInMemoryCacheSize: 1000
maxInMemoryCacheAgeInMs: 60000
enableEnhancedTelemetry: false
socketConnectionsPerTenant:
maxPerMs: 1000000
maxBurst: 1000000
minCooldownIntervalInMs: 1000000
minThrottleIntervalInMs: 1000000
maxInMemoryCacheSize: 1000
maxInMemoryCacheAgeInMs: 60000
enableEnhancedTelemetry: false
socketConnectionsPerCluster:
maxPerMs: 1000000
maxBurst: 1000000
minCooldownIntervalInMs: 1000000
Expand Down
Loading

0 comments on commit f38f7de

Please sign in to comment.