{"id":19855003,"url":"https://github.com/stepci/phasic","last_synced_at":"2025-05-02T01:30:37.931Z","repository":{"id":62075106,"uuid":"556865315","full_name":"stepci/phasic","owner":"stepci","description":"Run functions in phases. Useful for load and performance testing","archived":false,"fork":false,"pushed_at":"2022-10-24T18:55:54.000Z","size":16,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-20T08:49:15.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/stepci.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":"2022-10-24T16:59:32.000Z","updated_at":"2023-03-13T10:10:28.000Z","dependencies_parsed_at":"2022-10-26T02:30:40.644Z","dependency_job_id":null,"html_url":"https://github.com/stepci/phasic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepci%2Fphasic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepci%2Fphasic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepci%2Fphasic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepci%2Fphasic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stepci","download_url":"https://codeload.github.com/stepci/phasic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251969253,"owners_count":21673182,"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":[],"created_at":"2024-11-12T14:11:22.515Z","updated_at":"2025-05-02T01:30:37.439Z","avatar_url":"https://github.com/stepci.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phasic\n\n![phasic Demo](https://i.imgur.com/VUV3sdS.gif)\n\n`phasic` is a low-level library for running asynchronous code repeatedly, in phases. This is useful for load and performance testing, where you want to start at a lower request per second rate and slowly increase the rate\n\n## Get Started\n\n**Install from npm**\n\n```\nnpm i phasic\n```\n\n**Import in your project**\n\n```js\nimport { runPhases } from 'phasic'\n```\n\n**Define phases**\n\n```js\nconst phases = [{\n  duration: 10,\n  arrivalRate: 1\n},\n{\n  duration: 10,\n  arrivalRate: 100\n}]\n```\n\nWhere `duration` is the duration of the phase and `arrivalRate` is how many times the function will be called per second\n\nIn this example we have two phases, where the first phase lasts 10 seconds and a function is called once every second (10 calls) and a second phase, where a phase lasts 10 seconds, but the function is called 100 times per second (1000 calls). In total there would be 1010 function calls\n\n\u003e Note: Phase duration only defines the time window in which the functions should be called (not finished!). You should take that into account, if you're intending to run asynchronous tasks like HTTP requests or database reads\n\n**Run your code in phases**\n\n```js\nimport { runPhases } from '../src'\nimport fetch, { Response } from 'node-fetch'\n\nconst phases = [{\n  duration: 10,\n  arrivalRate: 1\n},\n{\n  duration: 10,\n  arrivalRate: 100\n}]\n\nlet errorCount = 0\n\nrunPhases\u003cResponse\u003e(phases, () =\u003e fetch('http://localhost:3000').catch(() =\u003e errorCount++))\n.then((resultList) =\u003e {\n  console.log('Status Codes:', resultList.map((result) =\u003e (result as PromiseFulfilledResult\u003cResponse\u003e).value.status))\n  console.log('Error rate:', (errorCount / resultList.length * 100).toFixed(2) + '%')\n})\n```\n\nIn this example, we're making a HTTP request to `http://localhost:3000` and reporting the error rate\n\nThe runPhases function returns a `Promise\u003cPromiseSettledResult\u003cT\u003e[]\u003e`. You can learn more about it in the [`Promise.allSettled()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) MDN article\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepci%2Fphasic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstepci%2Fphasic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepci%2Fphasic/lists"}