You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add BatchController for performant document writing (#679)
This PR introduce a new advanced class to process documents per batch without modifying existing code.
The `BatchController` extends the `DocumentController` except that the following methods are replaced by their batch equivalent:
- create => mCreate
- replace => mReplace
- createOrReplace => mCreateOrReplace
- update => mUpdate
- get => mGet
- exists => mGet
- delete => mDelete
You only need to replace the `sdk.document.XXX` call by `batchController.XXX`:
```
await sdk.document.create('test', 'test', { name: 'aschen' });
const batchController = new BatchController(sdk);
await batchController.create('test', 'test', { name: 'aschen' });
```
The actual drawback is that the error management won't be the same because the `BatchController` with throw generic errors if something went wrong and not Kuzzle specifics errors with appropriate error codes.
This class is an overload of the document controller and can be switched "as-is" in your code.
14
+
15
+
It allows to group API actions into batches to significantly increase performances.
16
+
17
+
The following methods will be executed by batch using
18
+
m* actions:
19
+
- create => mCreate
20
+
- replace => mReplace
21
+
- createOrReplace => mCreateOrReplace
22
+
- update => mUpdate
23
+
- get => mGet
24
+
- exists => mGet
25
+
- delete => mDelete
26
+
27
+
::: warning
28
+
Standard API errors will not be available.
29
+
Except for the `services.storage.not_found` error.
30
+
:::
31
+
32
+
By default, the BatchController sends a batch of documents every 10ms. This can be configured when instantiating the BatchController through the `options.interval` constructor parameter.
33
+
34
+
::: info
35
+
Depending on your workload, you may want to increase the timer interval to execute bigger batches.
36
+
A bigger interval will also mean more time between two batches and potentially degraded performances.
37
+
The default value of 10ms offers a good balance between batch size and maximum delay between two batches and should be suitable for most situations.
Except for the `services.storage.not_found` error.
60
+
:::
61
+
62
+
By default, the BatchController send a batch of document every 10ms. This can be configured when instantiating the BatchController through the `options.interval`[constructor](/sdk/js/7/core-classes/batch-controller/constructor) parameter.
63
+
64
+
::: info
65
+
Depending on your load, you may want to increase the timer interval to execute bigger batch.
66
+
A bigger interval will also mean more time between two batch and potentialy degraded performances.
67
+
The default value of 10ms offer a good balance between batch size and maximum delay between two batch and should be suitable for most situations.
0 commit comments