[e-lang] Seeking event loop concurrent solution to challenge problem
ihab.awad at gmail.com
ihab.awad at gmail.com
Thu Sep 24 00:27:18 EDT 2009
Hi folks,
The CommonJS group seeks to build a "common" (i.e., not just Web
pages) platform of JavaScript. In this thread, we asked ourselves what
to do about concurrency:
http://groups.google.com/group/commonjs/browse_thread/thread/fa20fc6a3649b3a
A lot of us are fans of shared-nothing event loop concurrency, so we
thought about using HTML5's "workers" as our starting point. However,
it seems that using these requires a bunch of boilerplate, some of
which may be automated, and some of which may not. I'd love to see
someone code the solution in E, say, and we could backtrack from
there.
Problem: A multi threaded Web server that serves up a hit count for a
single page.
Kris Zyp's shared memory solution, from the email thread, is:
var hits = 0;
var lock = new (require("concurrency")).Lock(); // This just loads a module
function incrementAndGetHits(){
lock.lock();
hits++;
lock.unlock();
return hits;
}
exports.app = function(env) { // Exported function that worker threads run
return {
status:200,
headers:{"content-type":"text/plain"},
body: "This page has been hit " + incrementAndGetHits() + " times";
};
}
Given that E was essentially built for shared-nothing event loop
concurrency, what does it look like in E?
Ihab
--
Ihab A.B. Awad, Palo Alto, CA
More information about the e-lang
mailing list