Skip to content

Commit 8af28bb

Browse files
committed
Explicitly mention avoiding Promise.all
1 parent 9cb4fe0 commit 8af28bb

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

doc/api.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ For installation information, see the [Node-oracledb Installation Instructions][
370370
- 14.2.2 [Embedded Connect Descriptor Strings](#embedtns)
371371
- 14.2.3 [Net Service Names for Connection Strings](#tnsnames)
372372
- 14.2.4 [JDBC and Oracle SQL Developer Connection Strings](#notjdbc)
373-
- 14.3 [Connections and Number of Threads](#numberofthreads)
373+
- 14.3 [Connections, Threads, and Parallelism](#numberofthreads)
374374
- 14.4 [Connection Pooling](#connpooling)
375375
- 14.4.1 [Connection Pool Sizing](#conpoolsizing)
376376
- 14.4.2 [Connection Pool Closing and Draining](#conpooldraining)
@@ -7206,7 +7206,7 @@ const connection = await oracledb.getConnection(
72067206
);
72077207
```
72087208

7209-
### <a name="numberofthreads"></a> 14.3 Connections and Number of Threads
7209+
### <a name="numberofthreads"></a> 14.3 Connections, Threads, and Parallelism
72107210

72117211
If you open more than four connections, such as via
72127212
increasing [`poolMax`](#proppoolpoolmax), you should increase the
@@ -7246,21 +7246,26 @@ This prevents other connections from beginning work and stops Node.js
72467246
from handling more user load. Increasing the number of worker threads
72477247
may improve throughput and prevent [deadlocks][22].
72487248

7249-
As well as correctly setting the thread pool size, structure your code
7250-
to avoid starting parallel operations on a connection. For example,
7251-
instead of using `async.parallel` or `async.each()` which call each
7252-
of their items in parallel, use `async.series` or `async.eachSeries()`.
7253-
When you use parallel calls on a connection, the queuing ends up being
7254-
done in the C layer via a mutex. However libuv is not aware that a
7255-
connection can only do one thing at a time - it only knows when it has
7256-
background threads available and so it sends off the work to be done.
7257-
If your application runs operations in parallel on a connection, you
7258-
could use more than one background thread (perhaps all of them) and
7259-
each could be waiting on the one before it to finish its "execute". Of
7260-
course other users or transactions cannot use the threads at
7261-
that time either. When you use methods like `async.series` or
7262-
`async.eachSeries()`, the queuing is instead done in the main
7263-
JavaScript thread.
7249+
#### Parallelism on a Connection
7250+
7251+
Structure your code to avoid parallel operations on a single connection. For
7252+
example, do not use `Promise.all`. Instead consider, for example, using a basic
7253+
`for` loop and `async` to iterate through each action. Also, instead of using
7254+
`async.parallel` or `async.each()` which call each of their items in parallel,
7255+
use `async.series` or `async.eachSeries()`. Code will not run faster when
7256+
parallel calls are used with a single connection since each connection can only
7257+
ever execute one statement at a time. Statements will still be executed
7258+
sequentially.
7259+
7260+
When you use parallel calls on a single connection, queuing of each call is done
7261+
in the C layer via a mutex. However libuv is not aware that a connection can
7262+
only do one thing at a time - it only knows when it has background threads
7263+
available and so it sends off the work to be done. If your application runs
7264+
operations in parallel on a connection, you could use more than one background
7265+
thread (perhaps all of them) and each could be waiting on the one before it to
7266+
finish its "execute". Of course other users or transactions cannot use the
7267+
threads at that time either. When you use methods like `async.series` or
7268+
`async.eachSeries()`, the queuing is instead done in the main JavaScript thread.
72647269

72657270
### <a name="connpooling"></a> 14.4 Connection Pooling
72667271

0 commit comments

Comments
 (0)