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

@luminati-io/locker

v0.1.6-lum.2

Published

lock server written in node.js

Downloads

40

Readme

This is extended version of locker.js; original README is below

locker - lock server written in node.js

This is lock server for system that need to share and lock common resources across servers with sub-second precision.

Features

  • Lock timeouts with millisecond precision:
    • Timeout to wait for getting lock.
    • Timeout to keep lock before releae.
  • No polling: one request to acquire, one request to release.
  • Auto-releasing locks on disconnect.
  • Pure node.js. Just awesome.

Clients

node.js

Client for node.js is completely async.

Example:

var Locker = require("locker"),
    locker = new Locker(4545, "127.0.0.1");

locker.on("reset", function() {
    console.log("Reset happened (is server running?)");
});

locker.on("error", function(error) {
    console.log("Catched error:", error);
});

//            name    wait  max   callback
locker.locked("five", 2000, 3000, function(error, callback) {
    if (error) {
        // lock failed
        callback(error);
        return;
    }

    // do whatever you want with your shared resource
    
    callback(undefined, {well: "done"});
});

PHP

Client for php.

Example:

require_once('Locker.php');

$Locker = new \Locker\Locker("127.0.0.1", 4545);

// Lock creation
$LockOne = $Locker->createLock('example');

// getting lock
$LockOne->acquire(200, 10000);
// doing very important stuff
echo 'Waiting for 5 seconds..'."\n";
sleep(5);
// releasing lock
$LockOne->release();

Python

Client for python

Example:

from pylocker import Locker

# create locker server connection
locker = Locker("127.0.0.1", 4545)

# create lock object with some nice name
lock = locker.create_lock("fuu")
# acquire lock, wait for it for 500ms if it's taken
lock.acquire(500, 200)
# do whatever you need for up to 200ms
# and release lock
lock.release()

Running

First create a dir for locker:

mkdir locker
cd locker
mkdir node_modules
npm install locker-server

Then create main server file (look at example/server.js) and save it as server.js:

(function() {
    var Locker = require("locker-server"),
        locker = new Locker();

    locker.listen(4545);
})();

Run it after all:

node server.js

Capacity

More performance tests to be done, but for now on my MacBook Air (Intel i5):

Clients count: 5
Different locks to request: 10000
Total locks to request: 50000
Lock work time: 1ms

Server CPU usage: 100%
Server RSS memory: 70-80M (no growth after 5M requests)
Responses per second: 15000-17000 (measuring every 5 seconds)

If you want more, shard your locks.

Testing

We use mocha testing framework for this package.

To run it after installation you should run the next command:

# after calling npm install locker-server
npm test locker-server

If you want to contribute — please test your code and make sure everything still works.