UNPKG

3.08 kBMarkdownView Raw
1# spikearrest plugin
2
3## Summary
4
5The `spikearrest` plugin protects against traffic spikes. It throttles the number of requests processed by an Edge Microgateway instance.
6
7## When to use this plugin?
8
9Use this plugin when you want to restrict the number of API requests to Edge Microgateway without respect to a user or client application.
10
11
12## Plugin configuration properties
13
14You can set the following properties in the `spikearrest` stanza in the Edge Microgateway configuration file.
15
16```yaml
17spikearrest:
18 # How often the spike arrest execution window resets. Valid values are seconds or minutes.
19 # Default: none
20
21 timeUnit: minute
22
23 # The maximum number of requests to allow during the timeUnit.
24 # Default: none
25
26 allow: 10
27
28 # bufferSize is optional. If bufferSize > 0, SpikeArrest will attempt to smooth requests by
29 # returning only when the next appropriate execution window is available.
30 # bufferSize is how many requests to "queue" before returning (immediately) with a isAllowed = false.
31 # Default: 0
32
33 bufferSize: 5
34```
35
36## Enable the plugin
37
38In the Edge Microgateway configuration file (`org-env-config.yaml`) make sure that your plugin sequence is as shown below. Typically, the `spikearrest` plugin is listed first in the plugin sequence, but this is not mandatory.
39
40```yaml
41plugins:
42 sequence:
43 - spikearrest
44 - oauth
45```
46
47## Configure the plugin
48
49In the same configuration file you also need to configure the `spikearrest` plugin if you want to change the default behavior. The example below changes the `spikearrest` plugin to allow 10 requests per minute and it buffers a maximum of 50 requests before returning an error to the client for subsequent requests.
50
51```yaml
52spikearrest:
53 timeUnit: minute
54 allow: 10
55 bufferSize: 50
56```
57
58## Best Practices for configuring this plugin
59
60* The `spikearrest` plugin is typically listed first in the plugin sequence.
61* When Edge Microgateway starts it spawns worker processes based on the number of CPU cores, so if you have an 8 core machine, then it will spawn 8 worker processes. Each work process will have its own spike arrest counter. Therefore, you should consider the total number of requests that you want Edge Microgateway to allow and divide by the CPU core count. This will effectively ensure that your total allowed count is applied.
62 * Use the `EDGEMICRO_PROCESSES` environment variable to restrict the number of work processes that Edge Microgateway spawns when it starts.
63
64## Errors
65If triggered, the `spikearrest` generates the following error message.
66
67```
68HTTP/1.1 503 Service Unavailable
69Date: Thu, 17 Oct 2019 14:51:25 GMT
70Connection: keep-alive
71Content-Length: 46
72
73{"message":"SpikeArrest engaged","status":503}%
74```
75
76## To learn more
77
78Review the following `spikearrest` plugin documentation.
79* [Spike Arrest Plugin](https://docs.apigee.com/api-platform/microgateway/3.0.x/use-plugins#usingthespikearrestplugin-addingthespikearrestplugin)
80* Dependencies
81 * [volos-spikearrest-memory](https://www.npmjs.com/package/volos-spikearrest-memory) module.