Changes

Jump to navigation Jump to search
1,373 bytes removed ,  11:26, 26 June 2016
no edit summary
All functions in this module are assigned to the <code><nowiki>http://basex.org/modules/async</nowiki></code> namespace, which is statically bound to the {{Code|async}} prefix. Errors will be bound to the same prefix.
 
=Parallelized Execution=
 
Parallel query execution is recommendable if you have various calls that require a lot of time, but cannot be sped up by rewriting the code. This is e. g. the case if external URLs are called. If you are parallelizing local data reads (such as accessing a database), your single-threaded query will usually be faster, because parallelized access to disk data will often lead to randomized access patterns, which can hardly be optimized by your HD or SSD.
 
==async:fork-join==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|async:fork-join|$functions as function(*)*|item()*}}
|-
|'''Summary'''
|This function executes the supplied (non-updating) functions in parallel.
|-
| '''Examples'''
|
* The following function sleeps in parallel; it will be finished in 1 second if your system has at least 2 cores:
<pre class='brush:xquery'>
async:fork-join(
for $i in 1 to 2
return function() { prof:sleep(1000) }
)
</pre>
* In the following query, up to four URLs will be requested in parallel:
<pre class='brush:xquery'>
let $funcs :=
for $segment in 1 to 4
let $url := 'http://url.com/path' || $segment
return function() { http:send-request((), $url) }
return async:fork-join($funcs)
</pre>
|-
|'''Errors'''
|{{Error|unexpected|#Errors}} an unexpected error occurred while running a query or function in a separate thread.
|}
=Asynchronous Execution=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu