Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phasic

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phasic

Run functions in phases. Useful for load and performance testing

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8K
decreased by-4.44%
Maintainers
1
Weekly downloads
 
Created
Source

phasic

phasic Demo

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

Get Started

Install from npm

npm i phasic

Import in your project

import { runPhases } from 'phasic'

Define phases

const phases = [{
  duration: 10,
  arrivalRate: 1
},
{
  duration: 10,
  arrivalRate: 100
}]

Where duration is the duration of the phase and arrivalRate is how many times the function will be called per second

In 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

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

Run your code in phases

let errorCount = 0

runPhases(phases, () => fetch('http://localhost:3000').catch(() => errorCount++))
.then((resultList) => {
  console.log('Error rate:', (errorCount / resultList.length * 100).toFixed(2) + '%')
})

In this example, we're making a HTTP request to http://localhost:3000 and reporting the error rate

The runPhases function returns a Promise<PromiseSettledResult<any>[]>. You can learn more about it in the Promise.allSettled() MDN article

Keywords

FAQs

Package last updated on 24 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc