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

woven-js

v0.4.3

Published

intelligent multi-threading and server processing

Downloads

7

Readme

WovenJS

npm npm Github All Releases GitHub code size in bytes license GitHub release GitHub Release Date

WovenJS abstracts away the architectural complexity of multi-threading and utilizes optimization metrics to guide your application through the most performant process. Based on client hardware information and network strength, WovenJS dynamically runs intensive processes on the server or on the client. When running on the client, WovenJS leverages the Web Workers API to prevent blocking of the web browser's single thread.

Installing

First npm install woven-js in your web application

npm install --save woven-js
npm install --save-dev woven-loader worker-loader babel-loader webpack

Next, in your express server file, insert the following:

// server.js

const app = require('express')();
const woven = require('woven-js');
const functionsPath = /* 'path to your functions file' */;

woven.configure(functionsPath, { /* client options */ });
app.use(woven.optimize);

In the front end of your app:

// app.js

import Woven from 'woven-js/client';
import wovenWorker from 'worker-loader?inline=true&name=woven-worker.js!babel-loader!woven-loader!<path to your functions>';

const woven = new Woven();

woven.connect(wovenWorker);

woven.run('function name', payload)
  .then(output => {
    /* do something with output */
  });

Be sure to include the path to your functions file in the wovenWorker import! This gets your functions into the bundle. Also be sure you have Webpack installed as a dev dependency, as woven-loader relies on Webpack to work.

In order to work properly, your functions.js file will need to contain only pure functions that can run in Node or on the browser. Avoid relying on core Node or browser libraries. Also, your functions file will need to export all of its functions:

// functions.js

const funcOne = (a, b) => {
  return a + b;
}

const funcTwo = (a) => {
  return a * 2;
}

module.exports = { funcOne, funcTwo };

Usage

The woven.configure() method links the back end with the project's pure functions.

woven.configure(functionsPath, { /* client options */ });

The options object accessible through the configure method also allows for developer customizations:

module.exports = {
  alwaysClient: false,
  alwaysServer: false,
  dynamicMax: 10000,
  fallback: 'server',
  maxThreads: 12,
  pingSize: 'small',
}

Developer Customization Options:

  • alwaysClient/alwaysServer: An optimization override to run processes only on the server or the client, as opposed to letting the WovenJS optimal performance heuristic decide.

  • dynamicMax: WovenJS's dynamic ping is used to determine the data transmission speed of your server->client connection. This property allows you to set a minimum response time in milliseconds. If the dynamic ping is slower than this threshold, the client will be used for processing.

  • fallback: In the event that the optimization process fails, WovenJS will route to the fallback assigned here. Unless modified by the developer the default fallback is to process on the server.

  • maxThreads: A developer override to set the maximum # of threads that can be created for a given client (thread number corrosponds with the number of generated Web Workers).

  • pingSize: Use this property to set an exact size for the dynamic ping data in bytes or choose between WovenJS's preset options: 'tiny'(100bytes), 'small'(4kB), 'medium'(50kB), 'large'(400kB), or 'huge'(1MB).

Make sure that your server/application can handle the larger data transfer (400KB-1MB) before using the large/huge ping size presets.

The woven.connect() method is invoked on the client side to establish a connection between the client and the server.

woven.connect(/* workerFile */);

woven.connect() triggers the WovenJS’s optimize middleware to set the optimization configuration for each client’s connection. Additionally it takes in the reference to the imported Web Workers file so that WovenJS can spawn workers as needed.

WovenJS sends an auto-generated dynamic ping to capture data transmission speed for each client's connection. The dynamic ping should be proportionate to the application's functonality (for example, set the dynamic ping to the size of a JPG for an app that relies heavily on image file transfers).

If the dynamic ping is slower than the dynamicMax threshold, the client will be used for processing. If it's faster, the server will be used.

WovenJS's optimization process evaluates the most performant processing location depending on the hardware, software, and network capabilities of the client-side device. WovenJS will automatically route processing to the server or the client depending on what location will result in the fastest most performant client experience.

Use the woven.run() function wherever you want to run one of the functions in your pure functions file. WovenJS will decide where to run the function based on the optimization heuristic.

woven.run('function name', payload, ...moreArgs)
  .then(output => {
    /* do something with output */
  });

The first argument passed to woven.run() is the name of the function as a string. Next you can pass in any arguments that your function will take. You can pass in as many arguments as you like. woven.run() always returns a promise, so you can chain .then() on to woven.run() to utilize the output.

Contributing

We welcome contributions. If you'd like to contribute, please submit a pull request.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Thanks to Jos Dirksen, whose threadpool inspired our Web Worker pooling setup. Also thanks to the Webpack team for their neato worker-loader.