- Create a lockname.pid file.
- Readdir, looking for lockname.* files:
- If found file pid is < our pid, and it is alive/not stale, FAIL and unlink our lockfile
- If we make it through, we have the lock, continue.
// This the code in the npm multi-stage branch that removes a package directory. | |
function removeDir (pkg, log, next) { | |
var modpath = path.join(path.dirname(pkg.path), '.' + path.basename(pkg.path) + '.MODULES') | |
// Preserve any modules installed in this package, if any | |
fs.rename(path.join(pkg.path, 'node_modules'), modpath, unbuildPackage) | |
function unbuildPackage (renameEr) { | |
npm.commands.unbuild(pkg.path, true, renameEr ? andRemoveEmptyParents(pkg.path) : moveModulesBack) |
LINE: | |
for (;;) { | |
statements; | |
last LINE if $foo; | |
next LINE if /^#/; | |
statements; | |
} |
function thingy(cb) | |
doAsyncThing("arg1", "arg2", "argn", andWarnOnError(log, cb)) | |
} | |
function andWarnOnError (log, cb) { | |
return function (er, result) { | |
if (er) { | |
log.warn("install", "Couldn't install optional dependency:", er.message) | |
log.verbose("install", er.stack) | |
} |
"use strict" | |
var EventEmitter = require("events").EventEmitter | |
var util = require("util") | |
var Tracker = exports.Tracker = function (done,todo) { | |
this.workDone = done || 0 | |
this.workTodo = todo || 0 | |
} | |
util.extend(Tracker, EventEmitter) |
var stream = require('stream'); | |
var DuplexCombination = require('duplex-combination'); | |
function dosomething() { | |
var input = new stream.PassThrough(); | |
var output = new stream.PassThrough(); | |
var combined = new DuplexCombination(output,input) | |
output.write('two'); | |
input.pipe(output); |
var stream = require('stream'); | |
function dosomething() { | |
var out = new stream.PassThrough(); | |
out.write('two'); | |
return out; | |
} | |
var source = new stream.PassThrough() | |
We're just issuing an echo here, which is the simplest command in the Gearman protocol. You send an echo packet to the server, the server responds back with what you sent it. The numbers here give a sense of how much overhead different approaches are adding.
The test here is with the word "ping". Substantially larger payloads are likely to be interesting, along with measures on time-to-first packet in the reply, as the node.js implementation is streaming end-to-end and will start replying before the original echo request actually completes. This also means that the entire echo body never need be held in memory.
-
Client, server in one process, no packet encode/decode:
echo: 4.07 wallclock secs @ 12289.63/s (n=50000)
-
Client, server in one process, stream stubs:
"use strict"; | |
var streamify = require('stream-array'); | |
var GearmanPacket = require('./gearman-packet'); | |
var through = require('through2'); | |
// Showing off the round tripping | |
// Below is are the example packets from the Gearman protocol docs, plus an admin command | |
// Notice how you can intermix these all without any issues | |
streamify([ |
var soon = process.nextTick; | |
require('domain').create() | |
.on('error', function(E){ console.log("All is well soon") }) | |
.run(function() { | |
soon(function(){ throw new Error() }) | |
}); | |
// We expect "All is well soon" to be logged | |
// Instead we get: | |
/* |