|
| 1 | +# Extensions - Rate Limiting |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +- [Introduction](#Introduction) |
| 6 | +- [Extension Definition](#Extension-Definition) |
| 7 | + - [Workflow KPIs Definition](#Workflow-KPIs-Definition) |
| 8 | +- [Example](#Example) |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +Out workflows can execute numerous downstream services. Rate limiting can be used to protect these |
| 13 | +downstream services from flooding. In addition, rate limiting can help us keep our cost |
| 14 | +at a desired rate in cases where downstream service invocations have an associated cost factor. |
| 15 | + |
| 16 | +## Extension Definition |
| 17 | + |
| 18 | +| Parameter | Description | Type | Required | |
| 19 | +| --- | --- | --- | --- | |
| 20 | +| extensionid | Unique extension Id (default is 'workflow-kpi-extension') | string | yes | |
| 21 | +| workflowid | Workflow definition unique identifier (workflow id property) | string | yes | |
| 22 | +| workflowVersions | Workflow versions. If not defined, applies to all workflow instances (regardless of their associated workflow version) | array | no | |
| 23 | +| [singleInstance](#Single-Instance-Definition) | Rate limits per single workflow instance | object | no | |
| 24 | +| [allInstances](#All-Instances-Definition) | Rate limits per all workflow instances | object | no | |
| 25 | + |
| 26 | +### Single Instance Definition |
| 27 | + |
| 28 | +| Parameter | Description | Type | Required | |
| 29 | +| --- | --- | --- | --- | |
| 30 | +| maxActionsPerSecond | Sets the rate limiting on number of actions that can be executed per second. Notice that the number is represented as number type, so that you can set it to less than 1 if needed. For example, set the number to 0.1 means you want workflow actions should be executed once every 10 seconds. Default zero value means 'unlimited'| number | no | |
| 31 | +| maxConcurrentActions | Maximum number of actions that can be executed in parallel | string | no | |
| 32 | +| maxProducedEventsPerSecond |Sets the rate limiting on number of events that can be produced per second. Notice that the number is represented as number type, so that you can set it to less than 1 if needed. For example, set the number to 0.1 means workflow can produce events once every 10 seconds. Default zero value means 'unlimited' | string | no | |
| 33 | +| maxStates | Maximum number of workflow states that should be executed. Default is zero, meaning unlimited. | string | no | |
| 34 | +| maxTransitions | Maximum number of workflow transitions that should be executed. Default is zero, meaning unlimited. | string | no | |
| 35 | + |
| 36 | +### All Instances Definition |
| 37 | + |
| 38 | +| Parameter | Description | Type | Required | |
| 39 | +| --- | --- | --- | --- | |
| 40 | +| maxActionsPerSecond | Sets the rate limiting on number of actions that can be executed per second. Notice that the number is represented as number type, so that you can set it to less than 1 if needed. For example, set the number to 0.1 means you want workflow actions should be executed once every 10 seconds. Default zero value means 'unlimited'| number | no | |
| 41 | +| maxConcurrentActions | Maximum number of actions that can be executed in parallel | string | no | |
| 42 | +| maxProducedEventsPerSecond |Sets the rate limiting on number of events that can be produced per second. Notice that the number is represented as number type, so that you can set it to less than 1 if needed. For example, set the number to 0.1 means workflow can produce events once every 10 seconds. Default zero value means 'unlimited' | string | no | |
| 43 | +| maxStates | Maximum number of workflow states that should be executed. Default is zero, meaning unlimited. | string | no | |
| 44 | +| maxTransitions | Maximum number of workflow transitions that should be executed. Default is zero, meaning unlimited. | string | no | |
| 45 | + |
| 46 | +## Example |
| 47 | + |
| 48 | +The following example shows a workflow definition on the left and |
| 49 | +an associated sample Rate Limiting extension definition on the right. |
| 50 | + |
| 51 | +<table> |
| 52 | +<tr> |
| 53 | + <th>Workflow</th> |
| 54 | + <th>Rate Limiting Extension</th> |
| 55 | +</tr> |
| 56 | +<tr> |
| 57 | +<td valign="top"> |
| 58 | + |
| 59 | +```yaml |
| 60 | +id: processapplication |
| 61 | +name: Process Application |
| 62 | +version: '1.0' |
| 63 | +specVersion: '0.7' |
| 64 | +start: ProcessNewApplication |
| 65 | +states: |
| 66 | + - name: ProcessNewApplication |
| 67 | + type: event |
| 68 | + onEvents: |
| 69 | + - eventRefs: |
| 70 | + - ApplicationReceivedEvent |
| 71 | + actions: |
| 72 | + - functionRef: processApplicationFunction |
| 73 | + - functionRef: acceptApplicantFunction |
| 74 | + - functionRef: depositFeesFunction |
| 75 | + end: |
| 76 | + produceEvents: |
| 77 | + - eventRef: NotifyApplicantEvent |
| 78 | +functions: |
| 79 | + - name: processApplicationFunction |
| 80 | + operation: file://myservice.json#process |
| 81 | + - name: acceptApplicantFunction |
| 82 | + operation: file://myservice.json#accept |
| 83 | + - name: depositFeesFunction |
| 84 | + operation: file://myservice.json#deposit |
| 85 | +events: |
| 86 | + - name: ApplicationReceivedEvent |
| 87 | + type: application |
| 88 | + source: "/applications/new" |
| 89 | + - name: NotifyApplicantEvent |
| 90 | + type: notifications |
| 91 | + source: "/applicants/notify" |
| 92 | +``` |
| 93 | +
|
| 94 | +</td> |
| 95 | +<td valign="top"> |
| 96 | +
|
| 97 | +```yaml |
| 98 | +extensionid: workflow-ratelimiting-extension |
| 99 | +workflowid: processapplication |
| 100 | +singleInstance: |
| 101 | + maxActionsPerSecond: 0.1 |
| 102 | + maxConcurrentActions: 200 |
| 103 | + maxProducedEventsPerSecond: 2 |
| 104 | + maxStates: '1000' |
| 105 | + maxTransitions: '1000' |
| 106 | +allInstances: |
| 107 | + maxActionsPerSecond: 1 |
| 108 | + maxConcurrentActions: 500 |
| 109 | + maxProducedEventsPerSecond: 20 |
| 110 | + maxStates: '10000' |
| 111 | + maxTransitions: '10000' |
| 112 | + |
| 113 | +``` |
| 114 | + |
| 115 | +</td> |
| 116 | +</tr> |
| 117 | +</table> |
0 commit comments