Measuring API Performance

One of the most critical metrics for any API is its performance. API Connect for GraphQL is optimized to deliver you a fast and reliable GraphQL API.

About this task

Use the GraphQL benchmark tool to test the performance of your GraphQL API.

Procedure

  1. Install GraphQL Benchmark.
    1. Clone the files in this GitHub repository to your local machine.
    2. Run the following command to install to install k6 on Mac:
      brew install k6

      For k6 installation instructions on Linux, Windows, or Docker, see the k6 installation guide.

  2. Run the benchmark.
    1. Run the following command to benchmark using the configuration options described in driver.js:
      k6 run --vus 10 --duration 30s driver.js

      The command runs the load test with 10 virtual users for 30 seconds. You can alter the values for --vus and --duration in the command to run the test with a different amount of virtual users or a different duration.

      The endpoints you can test against are listed in the targets block in endpoints/index.js. The default endpoint returns the current version of API Connect Essentials (represented by its former name stepzen in the example):

      export const targets = [
        { target: google, weight: 0 },
        { target: yahoo, weight: 0 },
        { target: httpbin, weight: 0 },
        { target: stepzenVersion, weight: 1 },
        { target: stepzenLight, weight: 0 },
        { target: stepzenHeavy, weight: 0 },
      ];

      By changing the value for weight you can also run the test against other endpoints and compare the performance of API Connect Essentials to other services like Google or Yahoo. For example, to test API Connect for GraphQL against Google, set the weight for Google to 1:

      export const targets = [
        { target: google, weight: 1 },
        { target: yahoo, weight: 0 },
        { target: httpbin, weight: 0 },
        { target: stepzenVersion, weight: 1 },
        { target: stepzenLight, weight: 0 },
        { target: stepzenHeavy, weight: 0 },
      ];
  3. Test your own endpoint.

    To test your own API Connect for GraphQL GraphQL API, alter the variables stepzenLight and stepzenHeavy in endpoints/index.js. If you want to test a light query, for example a query without nested fields, alter stepzenLight:

    const stepzenLight = {
      method: 'POST',
      endpoint: 'REPLACE_WITH_YOUR_OWN_STEPZEN_ENDPOINT',
      counterName: 'stepzenLight',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        query: `
          query MyQuery {
            // INSERT_YOUR_OWN_QUERY
          }
        `,
      }),
    };

    Make sure to set the weight for stepzenLight to 1 after filling in your API Connect for GraphQL GraphQL API endpoint and inserting a query for this endpoint. You could repeat the same steps for stepzenHeavy if you want to test more complex queries that send requests to multiple data sources or contain heavily nested fields.