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
-
Install GraphQL Benchmark.
- Clone the files in this GitHub repository to your local machine.
- Run the following command to install to install
k6on Mac:brew install k6For k6 installation instructions on Linux, Windows, or Docker, see the k6 installation guide.
-
Run the benchmark.
- Run the following command to benchmark using the configuration options described in
driver.js:k6 run --vus 10 --duration 30s driver.jsThe command runs the load test with 10 virtual users for 30 seconds. You can alter the values for
--vusand--durationin 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
targetsblock inendpoints/index.js. The default endpoint returns the current version of API Connect Essentials (represented by its former namestepzenin 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
weightyou can also run the test against other endpoints and compare the performance of API Connect for GraphQL Software to other services like Google or Yahoo. For example, to test API Connect for GraphQL against Google, set theweightfor Google to1: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 }, ];
- Run the following command to benchmark using the configuration options described in
-
Test your own endpoint.
To test your own API Connect for GraphQL GraphQL API, alter the variables
stepzenLightandstepzenHeavyinendpoints/index.js. If you want to test a light query, for example a query without nested fields, alterstepzenLight: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
weightforstepzenLightto1after filling in your API Connect for GraphQL GraphQL API endpoint and inserting a query for this endpoint. You could repeat the same steps forstepzenHeavyif you want to test more complex queries that send requests to multiple data sources or contain heavily nested fields.