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

shm

v0.1.0

Published

simple to use, PHP compatible shared memory for node.js

Downloads

7

Readme

nodejs-shm (WORK IN PROGRESS)

Node.js native addon for using shared memory compatible with PHP shmop

Description

Working on bigger project with several autonomous long-running processes I need communication between them. This processes ( workers, drivers ) need share relatively huge amount of data ( 10k - 100k bytes ) and I feel, that communication through TCP sockets is not so fast, as I want.

I have PHP workers with shared memory used with shmop_XXXX commands as "data sources", and another workers, based on node.js, which I need connect with them - that's why I started this work.

Working with shared memory need some discipline, my solution of potential concurrency and race condition problem is simple (not included in sources, only for imagination) :

My shm system is based on one big (10 MB) allocated shared memory block, divided to sections, where can write only exactly one worker. Information about sections (addressOffset, sectionSize, owner) are readed from database and saved in first - header section. SHM creates one process - centralManager, which writes header section. Workers connects to SHM with well-known KEY, reads header section, finds info, where they have memory space (offset and size) and where are spaces of another workers, whose data they maybe need.

And communication between processes can start.

TODO: simple SHM manager.

The module is currently build on windows, linux not already tested.

#####Because a newbie in nodejs, this native addon is maybe not very pretty ... any help invited

Instalation

You can install with npm:

$ npm install -g nodejs-shm

How to Use

API

    C
//	int shmid  .... int shmop_open (int key, char* flags, int mode, int size)
//	int  shmop_size (int shmid)
//	int  shmop_write (int shmid, char * data, int offset, int data_len)
//	unsigned char*  shmop_read (int shmid, int start, int length)
//	int shmop_delete (int shmid)
//	int  shmop_close (int shmid)

    Javascript
        module 	shm
        function openSHM ( key [Number], flags [String], mode [Number], size [Number]) ... returns shmid [Number]
        function sizeSHM ( shmid [Number] ) ... returns allocated size [Number]
        function writeSHM ( shmid [Number], data [Buffer], offset [Number], data_len [Number] ) ... returns written bytes [Number]
        function readSHM ( shmid [Number], start [Number], length [Number] )  ... returns Buffer
        function deleteSHM ( shmid [Number] ) ... return 0 or 1 [Number]
        function closeSHM ( shmid [Number] ) ... return 0 or 1 [Number]

EXAMPLE (test/test.js)

var shm = require('./build/Release/shm');

console.log("Object:\n", shm); 

var shmkey = 1236;

var shmid  = shm.openSHM(shmkey,'c',0,1024);		
console.log("opened shmkey:",shmkey, " shmid:",shmid);

var bubu = new Buffer("1234567890");
console.log("writing '1234567890', written:",shm.writeSHM(shmid,bubu,2,bubu.length));		//10

xxxx = shm.readSHM(shmid,2,10);
console.log("readed(HEXA):", buff2hex(xxxx));

console.log("waiting 10 secs to detach and close");
var timerD = setTimeout( function() {
	console.log("detatch retval:", shm.deleteSHM(shmid) );
	console.log("close retval:", shm.closeSHM(shmid) );
}, 10000);

License

Copyright (c) 2013 Jan Supuka sbmintegral.sk

The MIT License