Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Spike Arrest Quick Start

Will Witman edited this page Mar 2, 2015 · 1 revision

Adding a spike arrest policy

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

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.

Configuring spike arrest in the Swagger editor

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.

  1. Execute $ a127 project edit to open up the Swagger editor.
  2. 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
  1. 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: {}

Testing the spike arrest configuration

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.

  1. Start the app with a127 project start.
  2. 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.

Spike arrest options

    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).

Deep dive

For a more detailed description of spike arrest, including advanced configuration options, see Spike arrest deep dive.

Code sample

For a working spike arrest example, see Apigee-127 samples on GitHub.

Related information

See the volos-spikearrest-common description on GitHub for details on the underlying Volos.js module.

Clone this wiki locally