-
Notifications
You must be signed in to change notification settings - Fork 24
Spike Arrest Quick Start
A Spike Arrest policy protects against traffic spikes. It throttles the number of requests processed by an API proxy and sent to a backend, protecting against performance lags and downtime.
This topic explains how to add a spike arrest policy to an Apigee-127 API.
- Before you begin
- Configuring spike arrest in the Swagger editor
- Testing the spike arrest configuration
- Spike arrest options
- Deep dive
- Code sample
- Related information
If you're using the default skeleton project (the one that's installed when you do a127 project create
), then you can skip this step.
But just keep in mind that you must include one of the volos-spikearrest-*
modules in your project's package.json
file. In this example, we're going to use volos-spikearrest-memory
. If you change package.json
, remember to run npm install
in the project root folder to install the dependencies.
For information on the volos-spikearrest-*
modules, see the Volos.js page on GitHub.
Adding a spike arrest policy using Volos.js is as simple as adding a few lines of YAML in your API's Swagger specification file.
- Execute
$ a127 project edit
to open up the Swagger editor. - In the Swagger configuration file, under
x-a127-services
, add the following to enable an in-memory spike arrest provider. In this case, the spike arrest limit is set to allow no more than 10 API calls per minute. See the section "How it works" for more details.
x-a127-services:
spikearrest:
provider: "volos-spikearrest-memory"
options:
timeUnit: "minute"
bufferSize: 10
allow: 10
- Finally, use the
x-a127-apply
extension to apply this policy to the paths you want to enforce spike arrest on:
paths:
/hello:
x-swagger-router-controller: hello_world
x-a127-authorizations: {}
x-a127-apply:
spikearrest: {}
You set up your spike arrest to allow 10 API calls per minute. When this limit is exceeded, the API returns an error. Let's test it out.
- Start the app with
a127 project start
. - Call the API several times in quick succession:
$ curl http://localhost:10010/hello\?name\=Me
The spike arrest policy is enforced if the number of calls violates the specified rule. In that case, the API returns a 503 error with the message Error: Spike arrest engaged
.
options:
timeUnit: "minute"
bufferSize: 10
allow: 10
-
timeUnit: How often the spike arrest execution window resets - may be in seconds or minutes.
-
allow: The maximum number of requests to allow during the timeUnit.
-
bufferSize: (optional, default = 0) if bufferSize > 0, SpikeArrest will attempt to smooth requests by returning only when the next appropriate execution window is available. bufferSize is how many requests to "queue" before returning (immediately).
For a more detailed description of spike arrest, including advanced configuration options, see Spike arrest deep dive.
For a working spike arrest example, see Apigee-127 samples on GitHub.
See the volos-spikearrest-common description on GitHub for details on the underlying Volos.js module.
Having Trouble? Try posting your question to the Apigee Community. Or, for more links and resources, check out our Help Page
Need help? Visit the Apigee Community ! |
---|
-
Getting started
-
Add policies to your API
-
Add security policies
-
Deploy your projects
-
Programmatic hooks
-
Good to know about
-
Deep dives
-
Reference topics
-
Troubleshooting and getting help
-
Related resources