{"id":17353290,"url":"https://github.com/matteofigus/api-benchmark","last_synced_at":"2025-04-04T09:08:50.400Z","repository":{"id":10254433,"uuid":"12362873","full_name":"matteofigus/api-benchmark","owner":"matteofigus","description":"A node.js tool to benchmark APIs","archived":false,"fork":false,"pushed_at":"2023-01-24T04:23:41.000Z","size":436,"stargazers_count":311,"open_issues_count":8,"forks_count":34,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-28T08:08:07.537Z","etag":null,"topics":["api","benchmark","http"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matteofigus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-25T17:39:05.000Z","updated_at":"2024-01-04T15:44:55.000Z","dependencies_parsed_at":"2023-02-13T16:46:11.846Z","dependency_job_id":null,"html_url":"https://github.com/matteofigus/api-benchmark","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteofigus%2Fapi-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteofigus%2Fapi-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteofigus%2Fapi-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteofigus%2Fapi-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matteofigus","download_url":"https://codeload.github.com/matteofigus/api-benchmark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149501,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","benchmark","http"],"created_at":"2024-10-15T17:16:17.983Z","updated_at":"2025-04-04T09:08:50.381Z","avatar_url":"https://github.com/matteofigus.png","language":"JavaScript","readme":"# api-benchmark\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/matteofigus/api-benchmark.svg)](https://greenkeeper.io/)\n\nA node.js tool that measures and compares performances of single and multiple apis inspired by [BenchmarkJs](http://benchmarkjs.com/).\n[![Gitter](https://badges.gitter.im/matteofigus/api-benchmark.svg)](https://gitter.im/matteofigus/api-benchmark?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n[Why all of this? (blog post)](http://tech.opentable.co.uk/blog/2014/02/28/api-benchmark/)\n\n![https://raw.github.com/matteofigus/api-benchmark-www/master/public/images/screen-shot.png](https://raw.github.com/matteofigus/api-benchmark-www/master/public/images/screen-shot.png)\n\nTo see an example of a request/response [look at this gist](https://gist.github.com/matteofigus/6651234).\n\nIf you want to benchmark your api via [grunt](http://gruntjs.com/) take a look at [grunt-api-benchmark](https://github.com/matteofigus/grunt-api-benchmark).\n\n* [Requirements](#requirements)\n* [Installation](#installation)\n* [Usage](#usage)\n* API\n  * [`measure`](#measureservice-routes-options--callback)\n  * [`compare`](#compareservices-routes-options--callback)\n  * [`getHtml`](#gethtmlresults-callback)\n* [The `Route` object](#route-object)\n* [The `Options` object](#options-object)\n* [Tuning your machine to benchmark](#tuning)\n* [Contributing](#contributing)\n* [Why all of this?](http://tech.opentable.co.uk/blog/2014/02/28/api-benchmark/)\n\n# Requirements\n\nNode version: min: **4**, recommended: **8**\n\nBuild status: Unix: [![Build Status](https://secure.travis-ci.org/matteofigus/api-benchmark.png?branch=master)](http://travis-ci.org/matteofigus/api-benchmark) | Windows: [![Build status](https://ci.appveyor.com/api/projects/status/7lo2m92rg4cy47u7/branch/master?svg=true)](https://ci.appveyor.com/project/matteofigus/api-benchmark/branch/master)\n\n[![NPM](https://nodei.co/npm/api-benchmark.png?downloads=true)](https://npmjs.org/package/api-benchmark)\n\n# Installation\n\n```shell\nnpm i api-benchmark\n```\n\n# Usage\n\n### measure(service, [routes](#route-object), [[options](#options-object)], callback)\n\nMeasures performances of a given api for multiple routes\n\n```js\nvar apiBenchmark = require('api-benchmark');\n\nvar service = {\n  server1: 'http://myserver:myport/mypath/'\n};\n\nvar routes = { route1: 'route1', route2: 'route2' };\n\napiBenchmark.measure(service, routes, function(err, results) {\n  console.log(results);\n  // displays some stats!\n});\n```\n\n### compare(services, [routes](#route-object), [[options](#options-object)], callback)\n\nCompares performances of a given list of api servers with the same routes. Useful in case of load balancers, globalised services, deployment of new versions.\n\n```js\nvar apiBenchmark = require('api-benchmark');\n\nvar services = {\n  server1: 'http://myserver:myport/mypath/',\n  server2: 'http://myserver2:myport2/mypath2/'\n};\n\nvar routes = { route1: 'route1', route2: 'route2' };\n\napiBenchmark.compare(services, routes, function(err, results) {\n  console.log(results);\n  // displays some stats, including the winner!\n});\n```\n\nAll the Http verbs and headers are supported.\n\n```js\nvar apiBenchmark = require('api-benchmark');\n\nvar services = {\n  server1: 'http://myserver:myport/mypath/',\n  server2: 'http://myserver2:myport2/mypath2/'\n};\n\nvar routes = {\n  route1: {\n    method: 'get',\n    route: 'getRoute',\n    headers: {\n      Cookie: 'cookieName=value',\n      Accept: 'application/json'\n    }\n  },\n  route2: 'getRoute2',\n  route3: {\n    method: 'post',\n    route: 'postRoute',\n    data: {\n      test: true,\n      moreData: 'aString'\n    }\n  }\n};\n\napiBenchmark.compare(services, routes, function(err, results) {\n  console.log(results);\n  // displays some stats, including the winner!\n});\n```\n\n### getHtml(results, callback)\n\nGiven a results object, gets the html report.\n\n```js\nvar apiBenchmark = require('api-benchmark');\n\nvar service = {\n  server1: 'http://myserver:myport/mypath/'\n};\n\nvar routes = { route1: 'route1', route2: 'route2' };\n\napiBenchmark.measure(service, routes, function(err, results) {\n  apiBenchmark.getHtml(results, function(error, html) {\n    console.log(html);\n    // now save it yourself to a file and enjoy\n  });\n});\n```\n\n### Route object\n\n#### method\n\n(String, default 'get'): Http verb.\n\n#### route\n\n(String): the route to benchmark\n\n#### headers\n\n(Object): the headers to send. In case of function (that has to return an object) it will be evaulated for each request.\n\n#### data\n\n(Object): the data sent with the request. In case of function (that has to return an object) it will be evaulated for each request.\n\n#### query\n\n(Object): the query sent with the request. In case of function (that has to return an object) it will be evaulated for each request.\n\n#### expectedStatusCode\n\n(Number, default null): if it is a number, generates an error when the status code of the response is different\n\n#### maxMean\n\n(Number, default null): if it is a number, generates an error when the mean value for a benchmark cycle is major than the expected value\n\n#### maxSingleMean\n\n(Number, default null): if it is a number, generates an error when the mean across all the concurrent requests value is major than the expected value\n\n### Options object\n\n#### debug\n\n(Boolean, default false): Displays some info on the console.\n\n#### runMode\n\n(String, default 'sequence'): Can be 'sequence' (each request is made after receiving the previous response) or 'parallel' (all requests are made in parallel).\n\n#### maxConcurrentRequests\n\n(Number, default 100): When in runMode='parallel' it is the maximum number of concurrent requests are made.\n\n#### delay\n\n(Number, default 0): When in runMode='sequence', it is the delay between test cycles (secs).\n\n#### maxTime\n\n(Number, default 10): The maximum time a benchmark is allowed to run before finishing (secs).\nNote: Cycle delays aren't counted toward the maximum time.\n\n#### minSamples\n\n(Number, default 20): The minimum sample size required to perform statistical analysis.\n\n#### stopOnError\n\n(Boolean, default true): Stops the benchmark as soon as it receives an error. When false, the benchmark goes on and the errors are collected inside the callback.\n\n# Tuning\n\nYou should tune your machine to remove any OS limits in terms of opening and quickly recycling sockets.\n\n### Linux and Mac OS X\n\n```sh\nsudo sysctl -w kern.maxfiles=25000\nsudo sysctl -w kern.maxfilesperproc=24500\nsudo sysctl -w kern.ipc.somaxconn=20000\nulimit -S -n 20000\n```\n\n# Docker version\n\nContainerized version of api-benchmark is available here: [docker-api-benchmark](https://hub.docker.com/r/johnshumon/docker-api-benchmark/)\n\n# Contributing\n\n**This project is actively looking for contributors. If you wish to be involved, please open an issue and get in touch. Thanks!**\n\nFor the latest updates and release information follow [@matteofigus](https://twitter.com/matteofigus) on twitter.\nFeel free to open new Issues in case of Bugs or Feature requests.\nPull requests are welcome: first run all the tests locally doing `npm test`.\n\n### Tests\n\n```shell\nnpm test\n```\n\n### TODO\n\n* Command-line simple interface\n* Multi-thread requests\n* SOAP\n* Killer mode - [ask for details](https://twitter.com/matteofigus)\n\n# License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteofigus%2Fapi-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatteofigus%2Fapi-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteofigus%2Fapi-benchmark/lists"}