permit using pipelining option at query level

pipelining documentation
This commit is contained in:
rusher
2018-03-23 14:27:00 +01:00
parent 02967cfe8f
commit fdc2db9118
7 changed files with 68 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

View File

@ -0,0 +1,45 @@
## Option "pipelining"
With traditional synchronous drivers, queries are send one by one, waiting for result before sending next one.
Communication with server following a requestresponse messaging pattern.
That is not very effective when having to request many query at the same time.
Node.js is efficient because of asynchrone concept, let's follow this rules.
Pipelining is "optimistic send": Connector will send queries one after another, preserving FIFO order.
This is particularly efficient when client is distant from server.
#### Example :
create a basket with 3 items
```javascript
connection.beginTransaction();
connection.query("INSERT INTO BASKET(customerId) values (?)", [1], (err, res) => {
//must handle error if any
const basketId = res.insertId;
try {
connection.query("INSERT INTO BASKET_ITEM(basketId, itemId) values (?, ?)", [basketId, 100]);
connection.query("INSERT INTO BASKET_ITEM(basketId, itemId) values (?, ?)", [basketId, 101]);
connection.query("INSERT INTO BASKET_ITEM(basketId, itemId) values (?, ?)", [basketId, 102], (err) => {
//must handle error if any
connection.commit();
});
} catch (err) {
connection.rollback();
//handle error
}
});
```
#### Network exchanges :
<p align="center">
<img src="./misc/pipelining.png">
</p>
Using standard client-server protocol (aka "ping-pong"), driver communicate with database following a requestresponse messaging pattern.
When sending a command, connector won't send any until response is available from input socket.
Using option "pipelining", commands are send by bulk, saving network latency.
The Inconvenient is that if an error occur on first/second command, following command are already send to database.
In that sense that pipelining is "optimistic".

View File

@ -103,7 +103,7 @@ default: false
* `timezone`: string. force using indicated timezone, not current node.js timezone. possible value are 'Z' (fot UTC), 'local' or '±HH:MM' format
* `nestTables`: boolean/string. resultset are presented by table to avoid results with colliding fields. default: false
* `rowsAsArray`: boolean. default rows are defined as a JSON object. when active row is an array. default false
* `pipelining`: boolean. will send query one by one, but without waiting the results of previous entry. default true
* `pipelining`: boolean. will send query one by one, but without waiting the results of previous entry ([detail information](/documentation/pipelining.md)). default true
## Query
`connection.query(sql[, values][,callback])`