@@ -464,7 +464,8 @@ For installation information, see the [Node-oracledb Installation Instructions][
464
464
- 16.1.3 [Net Service Names for Connection Strings](#tnsnames)
465
465
- 16.1.4 [JDBC and Oracle SQL Developer Connection Strings](#notjdbc)
466
466
- 16.2 [Connections, Threads, and Parallelism](#numberofthreads)
467
- - 16.2.1 [Parallelism on a Connection](#parallelism)
467
+ - 16.2.1 [Connections and Worker Threads](#workerthreads)
468
+ - 16.2.2 [Parallelism on Each Connection](#parallelism)
468
469
- 16.3 [Connection Pooling](#connpooling)
469
470
- 16.3.1 [Connection Pool Sizing](#conpoolsizing)
470
471
- 16.3.2 [Connection Pool Closing and Draining](#conpooldraining)
@@ -1409,7 +1410,7 @@ concurrent statements on a connection by design. Also some application modules
1409
1410
may have the expectation that node-oracledb will handle any necessary
1410
1411
connection usage serialization.
1411
1412
1412
- For more discussion, see [Parallelism on a Connection](#parallelism).
1413
+ For more discussion, see [Parallelism on Each Connection](#parallelism).
1413
1414
1414
1415
This property was added in node-oracledb 5.2.
1415
1416
@@ -9618,11 +9619,30 @@ const connection = await oracledb.getConnection(
9618
9619
9619
9620
### <a name="numberofthreads"></a> 16.2 Connections, Threads, and Parallelism
9620
9621
9621
- If you open more than four connections, such as via increasing
9622
- [`poolMax`](#proppoolpoolmax), you should increase the number of worker threads
9623
- available to node-oracledb. A thread pool that is too small can cause
9624
- connection requests to fail with the error *NJS-040: connection request
9625
- timeout* or *NJS-076: connection request rejected*.
9622
+ To scale and optimize your applications it is useful to understand how
9623
+ connections interact with Node.js worker threads, and to know that each
9624
+ connection can only execute one database operation at a time.
9625
+
9626
+ #### <a name="workerthreads"></a> 16.2.1 Connections and Worker Threads
9627
+
9628
+ Node.js has four background worker threads by default (not to be confused with
9629
+ the newer user space worker_threads module). If you open more than four
9630
+ [standalone connections](#connectionhandling) or pooled connections, such as by
9631
+ increasing [`poolMax`](#proppoolpoolmax), then you should increase the number
9632
+ of worker threads available to node-oracledb.
9633
+
9634
+ A worker thread pool that is too small can cause a decrease in application
9635
+ performance, can cause [deadlocks][22], or can cause connection requests to
9636
+ fail with the error *NJS-040: connection request timeout* or *NJS-076:
9637
+ connection request rejected*.
9638
+
9639
+ A Node.js worker thread is used by each connection to execute a database
9640
+ statement. Each thread will wait until all [round-trips](#roundtrips) between
9641
+ node-oracledb and the database for the statement are complete. When an
9642
+ application handles a sustained number of user requests, and database
9643
+ operations take some time to execute or the network is slow, then all available
9644
+ threads may be held in use. This prevents other connections from beginning
9645
+ work and stops Node.js from handling more user load.
9626
9646
9627
9647
The thread pool size should be equal to, or greater than, the maximum number of
9628
9648
connections. If the application does database and non-database work
@@ -9648,7 +9668,8 @@ Or, on Windows:
9648
9668
. . .
9649
9669
```
9650
9670
9651
- With these, you can start your application with `npm start`.
9671
+ With these, you can start your application with `npm start`. This will allow
9672
+ up to 10 connections to be actively excuting SQL statements in parallel.
9652
9673
9653
9674
On non-Windows platforms, the value can also be set inside the application. It
9654
9675
must be set prior to any asynchronous Node.js call that uses the thread pool:
@@ -9661,14 +9682,14 @@ process.env.UV_THREADPOOL_SIZE = 10
9661
9682
// ... rest of code
9662
9683
```
9663
9684
9664
- If you set `UV_THREADPOOL_SIZE` too late, the setting will be ignored and the
9665
- default thread pool size of 4 will still be used. Note that
9685
+ If you set `UV_THREADPOOL_SIZE` too late in the application, or try to set it
9686
+ this way on Windows, then the setting will be ignored and the default thread
9687
+ pool size of 4 will still be used. Note that
9666
9688
[`pool.getStatistics()`](#poolgetstatistics) and
9667
9689
[`pool.logStatistics()`](#poollogstatistics) can only give the value of the
9668
9690
variable, not the actual size of the thread pool created. On Linux you can use
9669
- `pstack` to see how many threads are actually running. Note Node.js will
9670
- create a small number of threads in addition to the expected number of worker
9671
- threads.
9691
+ `pstack` to see how many threads are actually running. Node.js will create a
9692
+ small number of threads in addition to the expected number of worker threads.
9672
9693
9673
9694
The '[libuv][21]' library used by Node.js 12.5 and earlier limits the number of
9674
9695
threads to 128. In Node.js 12.6 onward the limit is 1024. You should restrict
@@ -9677,15 +9698,7 @@ i.e. [`poolMax`](#createpoolpoolattrspoolmax), to a value lower than
9677
9698
`UV_THREADPOOL_SIZE`. If you have multiple pools, make sure the sum of all
9678
9699
`poolMax` values is no larger than `UV_THREADPOOL_SIZE`.
9679
9700
9680
- Node.js worker threads executing database statements on a connection will wait
9681
- until [round-trips](#roundtrips) between node-oracledb and the database are
9682
- complete. When an application handles a sustained number of user requests, and
9683
- database operations take some time to execute or the network is slow, then all
9684
- available threads may be held in use. This prevents other connections from
9685
- beginning work and stops Node.js from handling more user load. Increasing the
9686
- number of worker threads may improve throughput and prevent [deadlocks][22].
9687
-
9688
- #### <a name="parallelism"></a> 16.2.1 Parallelism on a Connection
9701
+ #### <a name="parallelism"></a> 16.2.2 Parallelism on Each Connection
9689
9702
9690
9703
Oracle Database can only execute operations one at a time on each connection.
9691
9704
Examples of operations include `connection.execute()`,
@@ -10242,9 +10255,9 @@ blocking (for up to [`queueTimeout`](#propdbqueuetimeout) seconds) while
10242
10255
waiting an available pooled connection. It lets you see when the pool is too
10243
10256
small.
10244
10257
10245
- You may also experience *NJS-040* or *NJS-076* errors if your application is not
10246
- correctly closing connections, or [UV_THREADPOOL_SIZE](#numberofthreads) is too
10247
- small.
10258
+ You may also experience *NJS-040* or *NJS-076* errors if your application is
10259
+ not correctly closing connections, or if [UV_THREADPOOL_SIZE](#numberofthreads)
10260
+ is too small.
10248
10261
10249
10262
#### <a name="connpoolmonitor"></a> 16.3.5 Connection Pool Monitoring
10250
10263
@@ -12245,7 +12258,7 @@ Connections can handle one database operation at a time. Other
12245
12258
database operations will block. Structure your code to avoid starting
12246
12259
parallel operations on a connection. For example avoid using
12247
12260
`async.parallel` or `Promise.all()` which call each of their items in parallel,
12248
- see [Parallelism on a Connection](#parallelism).
12261
+ see [Parallelism on Each Connection](#parallelism).
12249
12262
12250
12263
After all database calls on the connection complete, the application
12251
12264
should use the [`connection.close()`](#connectionclose) call to
0 commit comments