Changes

Jump to navigation Jump to search
1,418 bytes added ,  16:19, 27 March 2016
no edit summary
=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==
=Asynchronous Execution=
 
Asynchronous query execution is recommendable if a client does not, or cannot, wait until a request is fully processed. This is e. g. the case with web browsers, which will usually cancel a request after a specific timeout. In such cases, you can use asynchronous execution to trigger another server-side process, which will start the time-consuming process, and fetch the result later on as soon as it is available.
==async:eval==
|
* {{Code|async:eval("1+3")}} returns a query id, e.g. {{Code|Query-abc}}. The result can be retrieved via a second query in the same BaseX context: {{Code|async:result("Query-abc")}}<br />
* The following [[RESTXQ]] function will return the id of the query thread, which evaluates the query that has been specified in the body of a POST request:
<pre class='brush:xquery'>
declare %rest:POST("{$query}") %rest:path('/eval') function local:eval($query) {
async:eval($query)
};
</pre>
|}
|-
| '''Examples'''
| * The following [[RESTXQ]] function will either return the result of a previously started query or an error:<pre class='brush:xquery'>declare %rest:path('/result/{$id}') function local:result($id) { async:result($id)};</pre>* The following query returns demonstrates how the results of an asynchronously executed query can be returned in a single query. It will succeed, because both the main and Please note that this is not the common way how asynchronous query do not include write operations on concurrently execution is used databasesin practice:
<pre class='brush:xquery'>
let $query := async:eval('(1 to 10000000)[. = 1]')
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu