Concurrent, Parallel, Distributed

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:

Callback functions are concurrent/asynchronous. They are executed on the same JavaScript thread where they were originated. db ( , function( data ) { ... });

Parallel JavaScript is initiated with the 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 ( , ...); 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.

Example:

(function() { var exclusive = mutex (); var param1 = request . query ( ); fork ( , param1 , exclusive , response ); var param2 = request . query ( ); fork ( , param2 , exclusive , response ); var param3 = request . query ( ); fork ( , param3 , exclusive , response ); }());

(function() { db ( + $args [0] + , function( data ) { try { var json = ; 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 (); } }); } }); }());

Debugging 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).

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).

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).

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.

See Also:

Reduction/MapReduce

JavaScript API Reference