WebSQL Server is designed to leverage the increasingly available parallelism. In essence, parallel computing is composed of tasks executed in parallel, where a task is a unit of computation. Programmers need the ability to define, start/stop, and coordinate parallel tasks. JavaScript is suitable for parallel computing despite its single-threaded computing model. WebSQL Server integrates JavaScript with Generic Parallel Computing (GPC) API and enables JavaScript for parallel computing.
The following distinction is made between the concurrent/asynchronous and parallel JavaScript:
db("select ...", function(data) { ... });
fork
function by providing a file with JavaScript code. Parallel JavaScript is executed on a different JavaScript thread, but it could be the same JavaScript thread because it is based on the the underlying hardware capabilities (more core/processors - more parallelization).
fork("/RelativeFilePath.js", ...);The non-blocking
join
function allows to coordinate/merge parallel tasks.
join(mutex, function(state) { ... });The pair of operations,
fork
and join
, is an algorithmic framework.
In comparison to MapReduce, fork
is the map
phase and join
is the reduce
phase.
Programs written with the framework automatically scales with the increasing number of multicore processors and can be distributed also.
(function() { var exclusive = mutex(); var param1 = request.query("param1"); fork("/QueryDatabase.js", param1, exclusive, response); var param2 = request.query("param2"); fork("/QueryDatabase.js", param2, exclusive, response); var param3 = request.query("param3"); fork("/QueryDatabase.js", param3, exclusive, response); }());QueryDatabase.js
(function() { db("select * from aTable where Something = '" + $args[0] + "'", function(data) { try { var json = "{\"Items\":[0"; data.forEach(function(item) { json += ","; json += item.Somevalue; }); json += "]}"; var exclusive = $args[1]; join(exclusive, function(state) { response.write(json); if( state.counter == 3 ) { response.end(); } }); } catch (err) { var exclusive = $args[1]; join(exclusive, function(state) { response.write(err); if( state.counter == 3 ) { response.end(); } }); } }); }());
The Web-based IDE gives the ability to traverse the execution flow of parallel tasks:
Queueing Time:
time spend waiting in the thread pool queue before this task could be processed (in milliseconds).Cumulative Time:
the total serial computation time of this task and all its descendant tasks (in milliseconds).Absolute Time:
the difference between the end time of the last descendant task and the beginning time of this task (in milliseconds).Parallel Ratio:
the speedup of the parallel execution.