npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arehs

v1.1.7

Published

The arehs ensures the best possible large batch processing, which is oriented towards event-driven chunk processing.

Downloads

77

Readme

🏛️ Arehs

The arehs ensures the best possible large batch processing, which is oriented towards event-driven chunk processing.
It does this by immediately allocating the next asynchronous task call for dense packing, rather than waiting for the first asynchronous task call to complete.

In that way we can achieve multiple things:

  • Control the throughput of our service by setting the concurrency of the Promise Pool.
  • Manage load on the downstream services by setting the concurrency of the Promise Pool.
  • Increase the performance of our application
  • Reduced CPU idle time, etc.

📚 Getting Started

arehs supports both CommonJS and ES Modules.

CommonJS

const { Arehs } = require("arehs");

ES Modules

import { Arehs } from "arehs";

Example

  • create: The purpose of the create method is to create an Arehs instance from a specific array of data.
  • withConcurrency: Methods that set the value for parallelism and return the current instance.(default: 10)
  • timeoutLimit: The default value is 0. If it's greater than 0, the option works, and an error is thrown if the operation takes longer than the timeout time(ms).
  • stopOnFailure: If the stopOnFailure option is set to true, the function stops processing and emits appropriate events.
  • retryLimit: Set a limit on the number of retries on failure.
  • mapAsync: Calling the mapAsync function starts the process of asynchronously processing the input data and returning the results. If the stopOnFailure option is set to true, the function stops processing and emits appropriate events. This can be useful for handling transient errors or ensuring data processing resilience. Also, if the retryLimit option is greater than 0, you can set a limit on the number of retries on failure.
import { Arehs } from "arehs";

const dataArr = [
  { id: 1, name: "John" },
  { id: 2, name: "Alice" },
  { id: 3, name: "Bob" }
];

const result = await Arehs.create(dataArr)
  .withConcurrency(10)
  .mapAsync(async data => {
    return await someAsyncFunction(data);
  });

⚡️ Performance

Tests have shown that Arehs can be improved by about 30% over Promise.all.

import { Arehs } from "arehs";

const delay = (i) => {
  return new Promise((res, rej) => {
    setTimeout(() => {
      res(i);
    }, 150 + Math.random() * 1000);
  });
};

(async () => {
  const tasks = Array.from({ length: 1000 }).map((d, i) => i);

  const startArehs = performance.now();
  await Arehs.create(tasks).withConcurrency(50).mapAsync(delay);
  const endArehs = performance.now();

  console.log(`Arehs: ${endArehs - startArehs}ms`);

  const startPromiseAll = performance.now();
  while (tasks.length > 0) {
    const chunkedTasks = tasks.splice(0, 50);
    await Promise.all(chunkedTasks.map(delay));
  }
  const endPromiseAll = performance.now();

  console.log(`Promise.all: ${endPromiseAll - startPromiseAll}ms`);
})();
    promiseAllTime: 19.859867874979972(s)
    promisePoolTime: 13.55725229203701(s)

Promise.all

As you can see, Promise.all runs as long as the slowest promise in the batch.
So your main thread is basically “doing nothing” and is waiting for the slowest request to finish.
The longest promise in the Promise array, number 4, will be the chunk's execution time.
This creates an inefficient problem where the next promises don't do any work until the longest promise is finished.

Arehs

Arehs is all about making the most of Node.js's main thread by running the Promise Pool Pattern.
To achieve better utilization we need densely pack the API calls (or any other async task) so that we do not wait while the most extended call completes, rather we schedule the next call as soon as the first one finishes.

🙋‍♀️FAQ

Is this always better than Promise.all?

No, there is No silver bullet.
This can increase your application's performance when you're making a lot of API calls and asynchronous operations.
Also, it may not make much difference in situations where each promise has roughly the same work time.
If you can't get any further performance improvement with Promise.all in your environment,
you can give it a try, but if you can get by with Promise.all, you don't have to.
Therefore, you should try to use Arehs in your projects that need performance improvements only after thoroughly testing it.
It will help you. Thank you.

👨‍👩‍👧‍👦 Contributors

  • Author: Jin Park