SkillAgentSearch skills...

Jsfbp

FBP implementation written using JavaScript and node-fibers

Install / Use

/learn @jpaulm/Jsfbp
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

npm version Build Status Known Vulnerabilities

jsfbp

JavaScript Implementation of FBP - no longer supported. Please take a copy by Oct. 1, 2021 if you need one!

General web site on Flow-Based Programming: https://jpaulm.github.io/fbp/ .

<!-- A scheduling logic error was detected in November 2016 that had been introduced into JSFBP in June, but was not spotted at that time. We have therefore had to reset the code back to the state it was in in June, as at that point all our tests worked fine! Strangely enough the Travis CI tests did not detect any problem, so this was not detected. This in turn means that later changes have had to be backed out, but, as far as we know, all our tests are working. Sorry for any inconvenience - we will try to bring the code back up to date as soon as possible. -->

"Classical" FBP "green thread" implementation written in JavaScript, using Node-Fibers - https://github.com/laverdet/node-fibers.

JSFBP takes advantage of JavaScript's concept of functions as first-degree objects to allow applications to be built using "green threads". JSFBP makes use of an internal "Future Events Queue" which supports the green threads, and provides quite good performance (see below) - the JavaScript events queue is only used for JavaScript asynchronous functions, as before.

<!-- I personally do not recommend using this FBP implementation, as compared with the Java, C# or C++ implementations on https://github.com/jpaulm , as `jsfbp` uses Node-Fibers, which has not been "blessed" by the JavaScript community, and even then, if I understand it correctly, does not support multiple cores (unlike the afore-mentioned implementations), although of course you could use sockets. My personal experience is also that JavaScript is hard to debug because of its lack of strict typing, although again TypeScript may solve this issue. -->

JSFBP is no longer supported, as Node-Fibers is being discontinued (I assume early 2021). Here is the relevant quote from https://github.com/laverdet/node-fibers :

<blockquote>"The author of this project recommends you avoid its use if possible. The original version of this module targeted nodejs v0.1.x in early 2011 when JavaScript on the server looked a lot different. Since then async/await, Promises, and Generators were standardized and the ecosystem as a whole has moved in that direction."</blockquote>

Installing Fibers

As suggested in https://github.com/laverdet/node-fibers/issues/new , make sure your version of nodejs is an even one.

Go into command mode, and enter npm install fibers.

If this command has trouble finding Python, install Python 2.7.10, then run npm --add-python-to-path='true' --debug install --global windows-build-tools. Don't know if this is still necessary!

General

To run test cases, position in your command shell to GitHub/jsfbp and type in node examples/fbptestxx, where xx is the test case number.

Test cases so far:

  • fbptest01 - 3 processes:
    • gendata (generates ascending numeric values)
    • copier (copies)
    • recvr (displays incoming values to console)

jsfbp

  • fbptest02 - gendata replaced with reader
  • fbptest03 - gendata and reader both feeding into copier.IN
  • fbptest04 - gendata feeding repl which sends 3 copies of input IP (as specified in network), each copy going to a separate element of array port OUT; all 3 copies then feeding into recvr.IN
  • fbptest05 - Two copies of reader running concurrently, one feeds directly into rrmerge ("round robin" merge) input port element 0; other one into copier and then into rrmerge input port element 1; from rrmerge.OUT to recvr.IN
  • fbptest06 - The output streams of the repl (in fbptest04) are fed to the input array port of rrmerge, and from its OUT to recvr.IN
  • fbptest07 - Creates a deadlock condition - the status of each Process is displayed
  • fbptest08 - reads text, reverses it twice and outputs it
  • fbptest09 - copier in fbptest01 is replaced with a version of copier which terminates prematurely and closes its input port, bringing the network down (ungracefully!)
  • fbptest10 - copier in fbptest01 is replaced with a non-looping version of copier
  • fbptest11 - Load balancer (lbal) feeding 3 instances of a random delay component (randdelay)

fbptest11

  • fbptest12 - reader OUT -> IN copier OUT -> IN writer
  • fbptest13 - Simple network to demonstrate functioning of random delay component (randdelay)
  • fbptest14 - Network demonstrating parallelism using two instances of reader and two fixed delay components (delay)
  • fbptestvl - Volume test (see below): gendata -> copier -> discard
  • testsubstreamsensitivesplitting.js - Test substream-sensitive logic in lbal, feeding substreamsensitivemerge.js

"Update" networks

  • update - "Update" run, demonstrating use of collate.js
  • update_c - Same as update.js but routing output to a compare process, rather than to display

The following diagram shows update and update_c in one diagram using the DrawFBP Enclosure function - this is not really a valid DrawFBP diagram, so no port names are shown:

update_combined

Here is update_c by itself, with component and port names marked in - it contains all the information needed to generate a running JSFBP network (the file and report icons do not generate any code):

update_c

WebSockets

  • fbptestws - Schematic web socket server (simple Process shown can be replaced by any structure of Processes, provided interfaces are adhered to)

fbptestws

Some of these have tracing set on, depending on what testing was being done when they were promoted!

These tests (except for fbptestws) can be run sequentially by running fbptests.bat.

Components

  • breader - reads from a binary file specified by FILE IIP and sends one IP per byte in the file. Starts sending IPs as soon as first byte is read.

  • bwriter - takes a stream of IPs containing bytes and writes them to a file from its FILE IIP. Starts writing as soon as the first IP comes in.

  • collate - collates from 1 to any number of sorted input streams, generating merged stream with bracket IPs inserted (sort fields assumed to be contiguous starting at 1st byte; all streams assumed to be sorted on same fields, in ascending sequence)

  • concat - concatenates all the streams that are sent to its array input port (size determined in network definition)

  • copier - copies its input stream to its output stream

  • copier_closing - forces close of input port after 20 IPs

  • copier_nonlooper - same as copier, except that it is written as a non-looper (it has been modified to call the FBP services from lower in the process's stack)

  • discard - discard (drop) all incoming IPs

  • display - display all incoming IPs, including bracket IPs

  • gendata - sends as many IPs to its output port as are specified by its COUNT IIP (each just contains the current count)

  • lbal - load balancer - sends output to output port array element with smallest number of IPs in transit

  • randdelay - sends incoming IPs to output port after random number of millisecs (between 0 and 400)

  • reader - does an asynchronous read on the file specified by its FILE IIP

  • recvr - receives its incoming stream and displays the contents on the console

  • repl - replicates the incoming IPs to the streams specified by an array output port (it does not handle tree structures)

  • reverse - reverses the string contained in each incoming IP

  • rrmerge - "round robin" merge

  • substreamsensitivemerge.js - merges multiple input streams, but keeps IPs in correct sequence within each substream, although sequence of substreams is not guaranteed

  • writer - does an asynchronous write to the file specified by its FILE IIP

  • wsrecv - general web socket "receive" component for web socket server - outputs substream

  • wsresp - general web socket "respond" component sending data from web socket server to client - takes substream as input

  • wssimproc - "simulated" processing for web socket server - actually just outputs 3 names

API

For application developers

Networks can be generated programmatically or by loading in an FBP file.

Programmatically

  1. Get access to JSFBP: var fbp = require('fbp')
  2. Create a new network: var network = new fbp.Network();
  3. Define your network:
  • Add processes: network.defProc(...) Note: when several processes use the same component, defProc takes the process name as a second argument.
  • Connect output ports to input ports: network.connect(...)
  • Specify IIPs: network.initialize(...)
  1. Create a new runtime: var fiberRuntime = new fbp.FiberRuntime();
  2. Run it!
network.run(fiberRuntime, {trace: true/false}, functio
View on GitHub
GitHub Stars125
CategoryDevelopment
Updated2mo ago
Forks23

Languages

JavaScript

Security Score

95/100

Audited on Jan 21, 2026

No findings