{"id":13454888,"url":"https://github.com/alexfernandez/loadtest","last_synced_at":"2025-05-12T13:24:34.975Z","repository":{"id":41168827,"uuid":"10855300","full_name":"alexfernandez/loadtest","owner":"alexfernandez","description":"Runs a load test on the selected URL. Fast and easy to use. Can be integrated in your own workflow using the API.","archived":false,"fork":false,"pushed_at":"2025-03-08T11:15:44.000Z","size":647,"stargazers_count":2608,"open_issues_count":12,"forks_count":212,"subscribers_count":39,"default_branch":"main","last_synced_at":"2025-04-23T16:07:37.258Z","etag":null,"topics":["loadtesting","nodejs","performance","testing-tools"],"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/alexfernandez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"alexfernandez","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2013-06-21T23:50:01.000Z","updated_at":"2025-04-22T18:47:39.000Z","dependencies_parsed_at":"2024-12-11T16:33:01.199Z","dependency_job_id":"88899b3a-c2b1-496b-816b-dda737330f82","html_url":"https://github.com/alexfernandez/loadtest","commit_stats":{"total_commits":507,"total_committers":52,"mean_commits":9.75,"dds":0.2761341222879684,"last_synced_commit":"76f5f091f13e33ec8e5df6bf59866eacf2a92dde"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfernandez%2Floadtest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfernandez%2Floadtest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfernandez%2Floadtest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfernandez%2Floadtest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexfernandez","download_url":"https://codeload.github.com/alexfernandez/loadtest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745857,"owners_count":21957454,"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":["loadtesting","nodejs","performance","testing-tools"],"created_at":"2024-07-31T08:00:58.991Z","updated_at":"2025-05-12T13:24:34.939Z","avatar_url":"https://github.com/alexfernandez.png","language":"JavaScript","readme":"[![run on repl.it](http://repl.it/badge/github/alexfernandez/loadtest)](https://repl.it/github/alexfernandez/loadtest)\n\n[![NPM](https://nodei.co/npm/loadtest.png?downloads=true)](https://nodei.co/npm/loadtest/)\n\n[![Package quality](https://packagequality.com/badge/loadtest.png)](https://packagequality.com/#?package=loadtest)\n\n# loadtest\n\nRuns a load test on the selected HTTP or WebSockets URL. The API allows for easy integration in your own tests.\n\n## Installation\n\nInstall globally as root:\n\n    # npm install -g loadtest\n\nOn Ubuntu or Mac OS X systems install using sudo:\n\n    $ sudo npm install -g loadtest\n\nFor access to the API just install it in your `npm` package as a dev dependency:\n\n    $ npm install --save-dev loadtest\n\n### Compatibility\n\nVersions 6 and later should be used at least with Node.js v16 or later:\n\n* Node.js v16 or later: ^6.0.0\n* Node.js v10 or later: ^5.0.0\n* Node.js v8 or later: 4.x.y\n* Node.js v6 or earlier: ^3.1.0\n* ES5 support (no `let`, `const` or arrow functions): ^2.0.0.\n\n## Usage\n\nWhy use `loadtest` instead of any other of the available tools, notably Apache `ab`?\n`loadtest` allows you to configure and tweak requests to simulate real world loads.\n\n### Basic Usage\n\nRun as a script to load test a URL:\n\n    $ loadtest [-n requests] [-c concurrency] [-k] URL\n\nThe URL can be \"http://\", \"https://\" or \"ws://\".\nSet the max number of requests with `-n`, and the desired level of concurrency with the `-c` parameter.\nUse keep-alive connections with `-k` whenever it makes sense,\nwhich should be always except when you are testing opening and closing connections.\n\nSingle-dash parameters (e.g. `-n`) are designed to be compatible with\n[Apache `ab`](http://httpd.apache.org/docs/2.2/programs/ab.html),\nexcept that here you can add the parameters _after_ the URL.\n\nTo get online help, run loadtest without parameters:\n\n    $ loadtest\n\n### Usage Dos\n\nThe set of basic options are designed to be compatible with Apache `ab`.\nBut while `ab` can only set a concurrency level and lets the server adjust to it,\n`loadtest` allows you to set a rate or requests per second with the `--rps` option.\nExample:\n\n    loadtest -c 10 --rps 200 http://mysite.com/\n\nThis command sends exactly 200 requests per second with concurrency 10,\nso you can see how your server copes with sustained rps.\nEven if `ab` reported a rate of 200 rps,\nyou will be surprised to see how a constant rate of requests per second affects performance:\nno longer are the requests adjusted to the server, but the server must adjust to the requests!\nRps rates are usually lowered dramatically, at least 20~25% (in our example from 200 to 150 rps),\nbut the resulting figure is much more robust.\n\n`loadtest` is also quite extensible.\nUsing the provided API it is very easy to integrate loadtest with your package, and run programmatic load tests.\nloadtest makes it very easy to run load tests as part of systems tests, before deploying a new version of your software.\nThe result includes mean response times and percentiles,\nso that you can abort deployment e.g. if 99% of all requests don't finish in 10 ms or less.\n\n### Usage Don'ts\n\n`loadtest` performance has improved significantly,\nbut it is still limited.\n`loadtest` saturates a single CPU pretty quickly,\nso it uses half the available cores in your processor.\nThe Node.js processes can reach 100% usage in `top`,\nwhich happens approx. when your load is above 4000~7000 rps per core.\nIn this case please adjust the number of cores.\nSo for instance with eight cores you can expect to get a maximum performance of\n8 * 5000 = 40 krps.\n\nYou can measure the practical limits of `loadtest` on your specific test machines by running it against a simple\n[test server](#test-server)\nand seeing when it reaches 100% CPU. Run the following commands on two different consoles:\n\n    $ node bin/testserver.js\n    $ node bin/loadtest.js -n 1000000 -c 100 http://localhost:7357/\n\nIf you have reached the limits of `loadtest` even after using all cores,\nthere are other tools that you can try.\n\n* [AutoCannon](https://www.npmjs.com/package/autocannon): also an `npm` package,\nawesome tool with an interface similar to `wrk`.\n* [Apache `ab`](http://httpd.apache.org/docs/2.2/programs/ab.html)\nhas great performance, but it is limited by a single CPU performance.\nIts practical limit is somewhere around ~40 krps.\n* [weighttp](http://redmine.lighttpd.net/projects/weighttp/wiki) is also `ab`-compatible\nand is supposed to be very fast (the author has not personally used it).\n* [wrk](https://github.com/wg/wrk) is multithreaded and highly performance.\nIt may need installing from source though, and its interface is not `ab`-compatible.\n* [wrk2](https://github.com/giltene/wrk2): evolution of `wrk`.\n\n### Regular Usage\n\nThe following parameters are compatible with Apache ab.\n\n#### `-t`, `--maxSeconds`\n\nMax number of seconds to wait until requests no longer go out.\nDefault is 10 seconds, applies only if no `--maxRequests` is specified.\n\nNote: this is different than Apache `ab`, which stops _receiving_ requests after the given seconds.\n\n**Warning**: max seconds used to have no default value,\nso tests would run indefinitely if no `--maxSeconds` and no `--maxRequests` were specified.\nMax seconds was changed to default to 10 in version 8.\n\n#### `-n`, `--maxRequests`\n\nNumber of requests to send out.\nDefault is no limit;\nwill keep on sending until the time limit in `--maxSeconds` is reached.\n\nNote: the total number of requests sent can be bigger than the parameter if there is a concurrency parameter;\nloadtest will report just the first `n`.\n\n#### `-c`, `--concurrency`\n\nloadtest will create a certain number of clients; this parameter controls how many.\nRequests from them will arrive concurrently to the server.\nDefault value is 10.\n\nNote: requests are not sent in parallel (from different processes),\nbut concurrently (a second request may be sent before the first has been answered).\nDoes not apply if `--requestsPerSecond` is specified.\n\nBeware: if concurrency is too low then it is possible that there will not be enough clients\nto send all the supported traffic,\nadjust it with `-c` if needed.\n\n**Warning**: concurrency used to have a default value of 1,\nuntil it was changed to 10 in version 8.\n\n#### `-k`, `--keepalive`\n\nOpen connections using keep-alive:\nuse header `Connection: keep-alive` instead of `Connection: close`.\n\nNote: Uses [agentkeepalive](https://npmjs.org/package/agentkeepalive),\nwhich performs better than the default node.js agent.\n\n#### `-C`, `--cookie cookie-name=value`\n\nSend a cookie with the request. The cookie `name=value` is then sent to the server.\nThis parameter can be repeated as many times as needed.\n\n#### `-H`, `--header header:value`\n\nSend a custom header with the request. The line `header:value` is then sent to the server.\nThis parameter can be repeated as many times as needed.\nExample:\n\n    $ loadtest -H user-agent:tester/0.4 ...\n\nNote: if not present, loadtest will add a few headers on its own: the \"host\" header parsed from the URL,\na custom user agent \"loadtest/\" plus version (`loadtest/1.1.0`), and an accept header for \"\\*/\\*\".\n\nNote: when the same header is sent several times, only the last value will be considered.\nIf you want to send multiple values with a header, separate them with semicolons:\n\n    $ loadtest -H accept:text/plain;text-html ...\n\nNote: if you need to add a header with spaces, be sure to surround both header and value with quotes:\n\n    $ loadtest -H \"Authorization: Basic xxx==\"\n\n#### `-T`, `--contentType`\n\nSet the MIME content type for POST data. Default: `text/plain`.\n\n#### `-P`, `--postBody`\n\nSend the string as the POST body. E.g.: `-P '{\"key\": \"a9acf03f\"}'`\n\n#### `-A`, `--patchBody`\n\nSend the string as the PATCH body. E.g.: `-A '{\"key\": \"a9acf03f\"}'`\n\n#### `-m`, `--method`\n\nSet method that will be sent to the test URL.\nAccepts: `GET`, `POST`, `PUT`, `DELETE`, `PATCH`,\nand lowercase versions. Default is `GET`.\nExample: `-m POST`.\n\n#### `--data body`\n\nAdd some data to send in the body. It does not support method GET.\nRequires setting the method with `-m` and the type with `-T`.\nExample: `--data '{\"username\": \"test\", \"password\": \"test\"}' -T 'application/x-www-form-urlencoded' -m POST`\n\n\n#### `-p`, `--postFile`\n\nSend the data contained in the given file in the POST body.\nRemember to set `-T` to the correct content-type.\n\nIf `POST-file` has `.js` extension it will be `import`ed. It should be a valid node module and it\nshould `export` a default function, which is invoked with an automatically generated request identifier\nto provide the body of each request.\nThis is useful if you want to generate request bodies dynamically and vary them for each request.\n\nExample:\n\n```javascript\nexport default function request(requestId) {\n  // this object will be serialized to JSON and sent in the body of the request\n  return {\n\tkey: 'value',\n\trequestId: requestId\n  }\n}\n```\n\nSee sample file in `sample/post-file.js`, and test in `test/body-generator.js`.\n\n#### `-u`, `--putFile`\n\nSend the data contained in the given file as a PUT request.\nRemember to set `-T` to the correct content-type.\n\nIf `PUT-file` has `.js` extension it will be `import`ed. It should be a valid node module and it\nshould `export` a default function, which is invoked with an automatically generated request identifier\nto provide the body of each request.\nThis is useful if you want to generate request bodies dynamically and vary them for each request.\nFor examples see above for `-p`.\n\n#### `-a`, `--patchFile`\n\nSend the data contained in the given file as a PATCH request.\nRemember to set `-T` to the correct content-type.\n\nIf `PATCH-file` has `.js` extension it will be `import`ed. It should be a valid node module and it\nshould `export` a default function, which is invoked with an automatically generated request identifier\nto provide the body of each request.\nThis is useful if you want to generate request bodies dynamically and vary them for each request.\nFor examples see above for `-p`.\n\n##### `-r`, `--recover`\n\nRecover from errors. Always active: loadtest does not stop on errors.\nAfter the tests are finished, if there were errors a report with all error codes will be shown.\n\n#### `-s`, `--secureProtocol`\n\nThe TLS/SSL method to use. (e.g. TLSv1_method)\n\nExample:\n\n    $ loadtest -n 1000 -s TLSv1_method https://www.example.com\n\n#### `-V`, `--version`\n\nShow version number and exit.\n\n### Advanced Usage\n\nThe following parameters are _not_ compatible with Apache ab.\n\n#### `--rps`, `--requestsPerSecond`\n\nControls the number of requests per second that are sent.\nCannot be fractional, e.g. `--rps 0.5`.\nIn this mode each request is not sent as soon as the previous one is responded,\nbut periodically even if previous requests have not been responded yet.\n\nNote: the `--concurrency` option will be ignored if `--requestsPerSecond` is specified;\nclients will be created on demand.\n\nNote: `--rps` is not supported for websockets.\n\n#### `--cores number`\n\nStart `loadtest` in multi-process mode on a number of cores simultaneously.\nForks the requested number of processes using the\n[Node.js cluster module](https://nodejs.org/api/cluster.html).\nDefault: half the available CPUs on the machine.\n\nThe total number of requests and the rps rate are shared among all processes.\nThe result shown is the aggregation of results from all cores.\n\nNote: this option is not available in the API,\nsince it runs just within the calling process.\n\n**Warning**: the default value for `--cores` has changed in version 7+,\nfrom 1 to half the available CPUs on the machine.\nSet to 1 to get the previous single-process mode.\n\n#### `--timeout milliseconds`\n\nTimeout for each generated request in milliseconds.\nSetting this to 0 disables timeout (default).\n\n#### `-R requestGeneratorModule.js`\n\nUse a custom request generator function from an external file.\nSee an example of a request generator module in [`requestGenerator`](doc/api.md#requestGenerator).\nAlso see [`sample/request-generator.js`](sample/request-generator.js) for some sample code including a body\n(or [`sample/request-generator.ts`](sample/request-generator.ts) for ES6/TypeScript).\n\n#### `--agent` (deprecated)\n\nOpen connections using keep-alive.\n\nNote: instead of using the default agent, this option is now an alias for `-k`.\n\n#### `--quiet`\n\nDo not show any messages.\n\n#### `--debug` (deprecated)\n\nShow debug messages.\n\nNote: deprecated in version 6+.\n\n#### `--insecure`\n\nAllow invalid and self-signed certificates over https.\n\n#### `--cert path/to/cert.pem`\n\nSets the certificate for the http client to use. Must be used with `--key`.\n\n#### `--key path/to/key.pem`\n\nSets the key for the http client to use. Must be used with `--cert`.\n\n#### `--tcp` (experimental)\n\nOption to use low level TCP sockets,\nfaster than the standard HTTP library.\nNot all options are supported.\n\n**Warning**: experimental option.\nMay not work with your test case.\nSee [TCP Sockets Performance](doc/tcp-sockets.md) for details.\n\n### Test Server\n\nloadtest bundles a test server. To run it:\n\n    $ testserver-loadtest [options] [port]\n\nThis command will show the number of requests received per second,\nthe latency in answering requests and the headers for selected requests.\n\nThe server returns a short text 'OK' for every request,\nso that latency measurements don't have to take into account request processing.\n\nIf no port is given then default port 7357 will be used.\nThe optional delay instructs the server to wait for the given number of milliseconds\nbefore answering each request, to simulate a busy server.\nYou can also simulate errors on a given percent of requests.\n\nThe following optional parameters are available.\n\n#### `--delay ms`\n\nWait the specified number of milliseconds before answering each request.\n\n#### `--error 5xx`\n\nReturn the given error for every request.\n\n#### `--percent yy`\n\nReturn an error (default 500) only for the specified % of requests.\n\n#### `--cores number`\n\nNumber of cores to use. If not 1, will start in multi-process mode.\n\nNote: since version v6.3.0 the test server uses half the available cores by default;\nuse `--cores 1` to use in single-process mode.\n\n### Complete Example\n\nLet us now see how to measure the performance of the test server.\n\nFirst we install `loadtest` globally:\n\n    $ sudo npm install -g loadtest\n\nNow we start the test server:\n\n    $ testserver-loadtest --cores 2\n    Listening on http://localhost:7357/\n    Listening on http://localhost:7357/\n\nOn a different console window we run a load test against it for 20 seconds\nwith concurrency 10 (only relevant results are shown):\n\n    $ loadtest http://localhost:7357/ -t 20 -c 10\n    ...\n    Requests: 9589, requests per second: 1915, mean latency: 10 ms\n    Requests: 16375, requests per second: 1359, mean latency: 10 ms\n    Requests: 16375, requests per second: 0, mean latency: 0 ms\n    ...\n    Completed requests:  16376\n    Requests per second: 368\n    Total time:          44.503181166000005 s\n\n    Percentage of requests served within a certain time\n      50%      4 ms\n      90%      5 ms\n      95%      6 ms\n      99%      14 ms\n     100%      35997 ms (longest request)\n\nThe result was quite erratic, with some requests taking up to 36 seconds;\nthis suggests that Node.js is queueing some requests for a long time, and answering them irregularly.\nNow we will try a fixed rate of 1000 rps:\n\n    $ loadtest http://localhost:7357/ -t 20 -c 10 --rps 1000\n    ...\n    Requests: 4551, requests per second: 910, mean latency: 0 ms\n    Requests: 9546, requests per second: 1000, mean latency: 0 ms\n    Requests: 14549, requests per second: 1000, mean latency: 20 ms\n    ...\n    Percentage of requests served within a certain time\n      50%      1 ms\n      90%      2 ms\n      95%      8 ms\n      99%      133 ms\n     100%      1246 ms (longest request)\n\nAgain erratic results. In fact if we leave the test running for 50 seconds we start seeing errors:\n\n    $ loadtest http://localhost:7357/ -t 50 -c 10 --rps 1000\n    ...\n    Requests: 29212, requests per second: 496, mean latency: 14500 ms\n    Errors: 426, accumulated errors: 428, 1.5% of total requests\n\nLet us lower the rate to 500 rps:\n\n    $ loadtest http://localhost:7357/ -t 20 -c 10 --rps 500\n    ...\n    Requests: 0, requests per second: 0, mean latency: 0 ms\n    Requests: 2258, requests per second: 452, mean latency: 0 ms\n    Requests: 4757, requests per second: 500, mean latency: 0 ms\n    Requests: 7258, requests per second: 500, mean latency: 0 ms\n    Requests: 9757, requests per second: 500, mean latency: 0 ms\n    ...\n    Requests per second: 500\n    Completed requests:  9758\n    Total errors:        0\n    Total time:          20.002735398000002 s\n    Requests per second: 488\n    Total time:          20.002735398000002 s\n\n    Percentage of requests served within a certain time\n      50%      1 ms\n      90%      1 ms\n      95%      1 ms\n      99%      14 ms\n     100%      148 ms (longest request)\n\nMuch better: a sustained rate of 500 rps is seen most of the time,\n488 rps average, and 99% of requests answered within 14 ms.\n\nWe now know that our server can accept 500 rps without problems.\nNot bad for a single-process naïve Node.js server...\nWe may refine our results further to find at which point from 500 to 1000 rps our server breaks down.\n\nBut instead let us research how to improve the result.\nOne obvious candidate is to add keep-alive to the requests so we don't have to create\na new connection for every request.\nThe result (with the same test server) is impressive:\n\n    $ loadtest http://localhost:7357/ -t 20 -c 10 -k\n    ...\n    Requests per second: 4099\n\n    Percentage of requests served within a certain time\n    50%      2 ms\n    90%      3 ms\n    95%      3 ms\n    99%      10 ms\n    100%      25 ms (longest request)\n\nNow we're talking! The steady rate also goes up to 2 krps:\n\n    $ loadtest http://localhost:7357/ -t 20 -c 10 --keepalive --rps 2000\n    ...\n    Requests per second: 1950\n\n    Percentage of requests served within a certain time\n      50%      1 ms\n      90%      2 ms\n      95%      2 ms\n      99%      7 ms\n     100%      20 ms (longest request)\n\nNot bad at all: 2 krps with a single core, sustained.\nHowever, it you try to push it beyond that, at 3 krps it will fail miserably.\n\n## API\n\n`loadtest` is not limited to running from the command line; it can be controlled using an API,\nthus allowing you to load test your application in your own tests.\nA short introduction follows; see [complete docs for API](doc/api.md).\n\n### Invoke Load Test\n\nTo run a load test, invoke the exported function `loadTest()` with the desired options:\n\n```javascript\nimport {loadTest} from 'loadtest'\n\nconst options = {\n    url: 'http://localhost:8000',\n    maxRequests: 1000,\n}\nconst result = await loadTest(options)\nresult.show()\nconsole.log('Tests run successfully')\n```\n\nBeware: if there are no `maxRequests` and no `maxSeconds`, the test will run forever.\n\n### `loadTest()` Parameters\n\nA simplified list of parameters is shown below;\nsee [doc/api.md](doc/api.md) for the full explanations with examples.\n\n* `url`: URL to invoke, mandatory.\n* `concurrency`: how many clients to start in parallel.\n* `maxRequests`: max number of requests; after they are reached the test will end.\n* `maxSeconds`: max number of seconds to run the tests.\n* `timeout`: timeout for each generated request in milliseconds, set to 0 to disable (default).\n* `cookies`: array of cookies to send, of the form `name=value`.\n* `headers`: object with headers, each with the value as string. Separate by semicolons to have multiple values.\n* `method`: HTTP method to use, default `GET`.\n* `body`: contents to send in the body of the message.\n* `contentType`: MIME type to use for the body, default `text/plain`.\n* `requestsPerSecond`: how many requests will be sent per second.\n* `requestGenerator`: custom request generator function.\n* `agentKeepAlive`: if true, will use 'Connection: Keep-alive'.\n* `quiet`: if true, do not show any messages.\n* `indexParam`: regexp to replace in URL and body with a unique index. The string specified in this parameter will be passed to `new Regexp(here, 'g')`. Do not use together with `indexParamLiteral`.\n* `indexParamLiteral`: literal string to replace in URL and body with a unique index. Do not use together with `indexParam`.\n* `indexParamCallback`: function to generate unique indexes.\n* `insecure`: allow invalid and self-signed certificates over https.\n* `secureProtocol`: TLS/SSL method to use.\n* `statusCallback(error, result)`: function to call after every request is completed.\n* `contentInspector(result)`: function to call before aggregating statistics.\n    \n### Start Test Server\n\nTo start the test server use the exported function `startServer()` with a set of options:\n\n```javascript\nimport {startServer} from 'loadtest'\nconst server = await startServer({port: 8000})\n// do your thing\nawait server.close()\n```\n\nThe following options are available,\nsee [doc/api.md](doc/api.md) for details.\n\n* `port`: optional port to use for the server, default 7357.\n* `delay`: milliseconds to wait before answering each request.\n* `error`: HTTP status code to return, default 200 (no error).\n* `percent`: return error only for the given % of requests.\n* `logger(request, response)`: function to call after every request.\n\nReturns a test server that you can `close()` when finished.\n\n### Configuration file\n\nIt is possible to put configuration options in a file named `.loadtestrc` in your working directory or in a file whose name is specified in the `loadtest` entry of your `package.json`. The options in the file will be used only if they are not specified in the command line.\n\nThe expected structure of the file is the following:\n\n```json\n{\n\t\"delay\": \"Delay the response for the given milliseconds\",\n\t\"error\": \"Return an HTTP error code\",\n\t\"percent\": \"Return an error (default 500) only for some % of requests\",\n\t\"maxRequests\": \"Number of requests to perform\",\n\t\"concurrency\": \"Number of requests to make\",\n\t\"maxSeconds\": \"Max time in seconds to wait for responses\",\n\t\"timeout\": \"Timeout for each request in milliseconds\",\n\t\"method\": \"method to url\",\n\t\"contentType\": \"MIME type for the body\",\n\t\"body\": \"Data to send\",\n\t\"file\": \"Send the contents of the file\",\n\t\"cookies\": {\n\t\t\"key\": \"value\"\n\t},\n\t\"headers\": {\n\t\t\"key\": \"value\"\n\t},\n\t\"secureProtocol\": \"TLS/SSL secure protocol method to use\",\n\t\"insecure\": \"Allow self-signed certificates over https\",\n\t\"cert\": \"The client certificate to use\",\n\t\"key\": \"The client key to use\",\n\t\"requestGenerator\": \"JS module with a custom request generator function\",\n\t\"recover\": \"Do not exit on socket receive errors (default)\",\n\t\"agentKeepAlive\": \"Use a keep-alive http agent\",\n\t\"proxy\": \"Use a proxy for requests\",\n\t\"requestsPerSecond\": \"Specify the requests per second for each client\",\n\t\"indexParam\": \"pattern to replace with a generated index in the URL\",\n\t\"indexParamLiteral\": \"string to replace with a generated index in the URL\",\n\t\"indexParamCallback\": \"function() {that generates ids to insert into the URL}\"\n}\n```\n\nSee sample file in `sample/.loadtestrc`.\n\nFor more information about the actual configuration file name, read the [confinode user manual](https://github.com/slune-org/confinode/blob/master/doc/en/usermanual.md#configuration-search). In the list of the [supported file types](https://github.com/slune-org/confinode/blob/master/doc/extensions.md), please note that only synchronous loaders can be used with _loadtest_.\n\n### Complete Example\n\nThe file `test/integration.js` contains complete examples, which are also a full integration test suite:\nthey start the server with different options, send requests, waits for finalization and close down the server.\n\n## Licensed under The MIT License\n\nCopyright (c) 2013-9 Alex Fernández \u003calexfernandeznpm@gmail.com\u003e\nand [contributors](https://github.com/alexfernandez/loadtest/graphs/contributors).\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","funding_links":["https://github.com/sponsors/alexfernandez"],"categories":["Packages","JavaScript","Development","包","\\*nix/\\*nux","目录","Testing","Number"],"sub_categories":["Testing","测试","Benchmarking","Web Development","测试相关"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfernandez%2Floadtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexfernandez%2Floadtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfernandez%2Floadtest/lists"}