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

memsync

v0.5.13

Published

Cross-process object/memory synchronization

Downloads

5

Readme

MemSync


Build Status NPM version

Process-to-process object synchronization. Backed by node-ipc.

  • Multiple NodeJS processes can write to and read from the shared object.
  • No extra server host process is needed, every process can act as a host, when the host process exits, the host role is taken over by another process.

API

Instantiate the memsync object

import { MemSync } from 'memsync'
let memsync = new MemSync(/* name */ 'my_shared_object', /* defaultObject */ {
    foo: 1,
    bar: 2,
    qux: [ 'one', 'two' ]
});

await memsync.start();

start discovers other nodes

  1. When the server already exists, we connect to the server and receive current object. Now our process holds the up-to-date data, receives new patches from the network and sends the changes to the host. When the host exits, we rediscover the network, and will try to act as a server, as we now holding the up-to-date object.
  2. When the process-to-process network does not exists, we create a server and start accepting new processes to join and will later share the current data with the clients

Make changes

We support partially the mongodb update operators

await memsync.patch({
    $set: {
        foo: 2
    }
})

We apply the patch immediately the object, and will try to

  1. if client: send to the host, which will accept the patch to itself, and broadcast the patch to other nodes.
  2. if server: broadcast the patch to nodes, if any.
Race conditions and conflict resolutions
  1. When multiple processes modify different parts of the object - there is no conflicts and the patch order has no matter.
  2. When multiple patches for the same data are made - the host acts as the source of truth - it accepts the patches by timestamp (patch creation date by client), if for any reason a patch is delivered to the host with older timestamp, as already was applied, it will be rejected and the sender (the client) will be notified about current state and current patches.

Stop

You can stop the node anytime

  1. if it is a client, it just disconnects
  2. if it is a server, it also stops listening, and one of alive nodes (if any) will act then as a server
memsync.stop()

Observe

Observe the objects properties

memsync.observe('foo', (fooValue) => {
    console.log(`FooValue changed`, fooValue);
})

Server

The process may expose a server to query the object and it current state

let memory = new MemSync('foo-bar', { num: 0 }, {
    server: { port: 8883 }
});
// Starts memory sync process, and also exposes the 8883 for http queries
await memory.start();

You can query the state of the foo-bar object from extern

curl http://localhost:8883/foo-bar

//e.g.> `{ num: 1}`