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

ya-rfc

v2.1.0

Published

Yet Another Remote Function Call library for Node js

Downloads

33

Readme

ya-rfc

npm version license test Coverage Status Language grade: JavaScript

Yet Another Remote Function Call library for Node js.

Ya-rpc anables to run functions on remote machines within a distributed system without worrying about network messaging or load balancing.

It provides an easy way to implement performance-critical applications by parallel execution on machines and processes.

basic execution flow

Key Features

Typical execution flow

basic execution flow

Installation

$ npm install ya-rfc

ya-rfc is tested with versions 12, 14 & 16 on of node.js on ubuntu-latest.

Quick start

const ya = require('ya-rfc');

Broker

Create a rfc broker that accepts TCP, IPC and websocket connections (only one transport required)

const namedPipe = path.join('\\\\.\\pipe', 'some-pipe');

ya.broker([
  ya.transports.ipc(namedPipe),
  ya.transports.tcp(8005, 'localhost'),
  ya.transports.ws(8006, 'localhost')]);

Server

Define functions that remote rfc clients will request to execute

// procedures.js
module.exports = {
  sum: (a, b) => {
    return a + b
  },
  count: (until, progress) => {
    const x = parseInt(until / 10)
    for (let i = 0; i < until; i++) {
      if (i % x === 0) {
        progress(`${i}/${until}`)
      }
    }
    return until
  }
};

Create a (ideally multiple) rfc server that connects to the Broker over TCP, it can also be IPC or websocket

ya.server(ya.transports.tcp(8005, 'localhost'), 'procedures.js');

// ya.server(ya.transports.ws(8006, 'localhost'));

// const win32namedPipe = require('path').join('\\\\.\\pipe', 'some-pipe');
// ya.server(ya.transports.ipc(win32namedPipe));

Client

Create a rfc client that connects to the Broker over TCP, it can also be IPC or websocket

const client = ya.client(ya.transports.tcp(8005, 'localhost'));

// const wsClient = ya.client(ya.transports.ws(8006, 'localhost'))

// const win32namedPipe = require('path').join('\\\\.\\pipe', 'some-pipe')
// const ipcClient = ya.client(ya.transports.ipc(win32namedPipe))

Execute a function remotely

tcpClient.remote.sum(1, 2)
  .then(result => {
    console.log(result)
  })
  .catch(error => {
    console.error(error)
  });
/* output:
3
*/

Execute a function remotely and get notified of its progression

client.remote.count(10000, {
  onProgress: (progress) => {
    console.log('progress', progress)
  }
})
  .then(result => {
    console.log('result is', result)
  })
  .catch(error => {
    console.error(error)
  });
/* output:
progress 0/10000
progress 1000/10000
progress 2000/10000
progress 3000/10000
progress 4000/10000
progress 5000/10000
progress 6000/10000
progress 7000/10000
progress 8000/10000
progress 9000/10000
result is 10000
*/

User defined load balancing

By default, each server will be assigned a maximum of 4*cpu-cores concurrent requests distributed (round robin) on its 2*cpu-cores workers. The broker will always route requests to the less loaded server.

You can create a server with an arbitrary number of workers

ya.server(transport, modulePath, { workers:10 })

You can define the maximum accepted load. For example, if each request has a load of 1, a maximum of 100 concurrent requests can be defined as such:

ya.server(transport, modulePath, { maxLoad:[100] })

Alternatively you can unset (not recommended) the limit by providing -1

ya.server(transport, modulePath, { maxLoad:[-1] })

By default, all requests are assigned a load of 1, this can be overridden like this:

rfc.remote.foo(bar, { load:[10] })

Often, the impact of a request on cpu or memory usage has to be modelled with several values, this is why maxLoad and load options are to be provided as arrays.

Versioning

Yaps-node uses Semantic Versioning for predictable versioning.

License

This library is licensed under MIT.