Skip to content

Commit

Permalink
removed broadcastSubRequestBatchSize
Browse files Browse the repository at this point in the history
  • Loading branch information
f-w committed Dec 4, 2024
1 parent fb903fc commit a997056
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
15 changes: 2 additions & 13 deletions docs/docs/config/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,20 @@ The config items in the _value_ field are

## Broadcast Push Notification Task Concurrency

To achieve horizontal scaling, when a broadcast push notification request, hereby known as original request, is received, _NotifyBC_ divides subscribers into chunks and generates a HTTP sub-request for each chunk. The original request supervises the execution of sub-requests. The chunk size is defined by config _broadcastSubscriberChunkSize_. All subscribers in a sub-request chunk are processed concurrently when the sub-requests are submitted.
To achieve horizontal scaling, when a broadcast push notification request is received, _NotifyBC_ divides subscribers into chunks and submits a BullMQ job for each chunk. The chunk size is defined by config _broadcastSubscriberChunkSize_. All subscribers in a sub-request chunk are processed concurrently when the sub-requests are submitted.

The original request submits sub-requests back to (preferably load-balanced) _NotifyBC_ server cluster for processing. Sub-request submission is throttled by config _broadcastSubRequestBatchSize_. _broadcastSubRequestBatchSize_ defines the upper limit of the number of Sub-requests that can be processed at any given time.

As an example, assuming the total number of subscribers for a notification is 1,000,000, _broadcastSubscriberChunkSize_ is 1,000 and _broadcastSubRequestBatchSize_ is 10, _NotifyBC_ will divide the 1M subscribers into 1,000 chunks and generates 1,000 sub-requests, one for each chunk. The 1,000 sub-requests will be submitted back to _NotifyBC_ cluster to be processed. The original request will ensure at most 10 sub-requests are submitted and being processed at any given time. In fact, the only time concurrency is less than 10 is near the end of the task when remaining sub-requests is less than 10. When a sub-request is received by _NotifyBC_ cluster, all 1,000 subscribers are processed concurrently. Suppose each sub-request (i.e. 1,000 subscribers) takes 1 minute to process on average, then the total time to dispatch notifications to 1M subscribers takes 1,000/10 = 100min, or 1hr40min.

The default value for _broadcastSubscriberChunkSize_ and _broadcastSubRequestBatchSize_ are defined in _/src/config.ts_
The default value for _broadcastSubscriberChunkSize_ is defined in _/src/config.ts_

```ts
module.exports = {
notification: {
broadcastSubscriberChunkSize: 1000,
broadcastSubRequestBatchSize: 10,
},
};
```

To customize, create the config with updated value in file _/src/config.local.js_.

If total number of subscribers is less than _broadcastSubscriberChunkSize_, then no sub-requests are spawned. Instead, the main request dispatches all notifications.

::: tip How to determine the optimal value for <i>broadcastSubscriberChunkSize</i> and <i>broadcastSubRequestBatchSize</i>?
<i>broadcastSubscriberChunkSize</i> is determined by the concurrency capability of the downstream message handlers such as SMTP server or SMS service provider. <i>broadcastSubRequestBatchSize</i> is determined by the size of <i>NotifyBC</i> cluster. As a rule of thumb, set <i>broadcastSubRequestBatchSize</i> equal to the number of non-primary nodes in <i>NotifyBC</i> cluster.
:::

## Broadcast Push Notification Custom Filter Functions

::: warning Advanced Topic
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/miscellaneous/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ v6 introduced following backward incompatible changes

2. config `minTime` in `email.throttle` and `sms.Throttle` is replaced with `max` and `duration`. Effectively _minTime=duration/max_. By default `max` is 4 and `duration` is 1000, equivalent to default `minTime` of 250.

3. Terms for [node roles](../config/nodeRoles.md) have changed. If you defined environment variable _NOTIFYBC_NODE_ROLE_ with value _master_, remove the environment variable. If _NOTIFYBC_NODE_ROLE_ has value _slave_, change it to _secondary_. If you deployed NotifyBC using Helm, this change is taken care of.
3. Terms for [node roles](../config/nodeRoles.md) have changed. If you defined environment variable _NOTIFYBC_NODE_ROLE_ with value other than _slave_, remove the environment variable; otherwise change it to _secondary_. If you deployed NotifyBC using Helm, this change is taken care of.

4. config `notification.broadcastSubRequestBatchSize` is deprecated. If you defined it in _/src/config.local.js_, remove it.

## v4 to v5

Expand Down
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ const config: Record<string, any> = {
},
notification: {
broadcastSubscriberChunkSize: 1000,
broadcastSubRequestBatchSize: 10,
guaranteedBroadcastPushDispatchProcessing: true,
logSkippedBroadcastPushDispatches: false,
},
Expand Down
7 changes: 0 additions & 7 deletions test/notification.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ describe('POST /notifications', () => {
const origNotificationConfig = appConfig.notification;
const newNotificationConfig = merge({}, origNotificationConfig, {
broadcastSubscriberChunkSize: 1,
broadcastSubRequestBatchSize: 10,
});
appConfig.notification = newNotificationConfig;
const res = await client
Expand Down Expand Up @@ -779,7 +778,6 @@ describe('POST /notifications', () => {
const origNotificationConfig = appConfig.notification;
const newNotificationConfig = merge({}, origNotificationConfig, {
broadcastSubscriberChunkSize: 1,
broadcastSubRequestBatchSize: 10,
});
appConfig.notification = newNotificationConfig;

Expand Down Expand Up @@ -864,7 +862,6 @@ describe('POST /notifications', () => {
const origNotificationConfig = appConfig.notification;
const newNotificationConfig = merge({}, origNotificationConfig, {
broadcastSubscriberChunkSize: 1,
broadcastSubRequestBatchSize: 10,
});
appConfig.notification = newNotificationConfig;

Expand Down Expand Up @@ -915,7 +912,6 @@ describe('POST /notifications', () => {
const origNotificationConfig = appConfig.notification;
const newNotificationConfig = merge({}, origNotificationConfig, {
broadcastSubscriberChunkSize: 1,
broadcastSubRequestBatchSize: 10,
});
appConfig.notification = newNotificationConfig;

Expand Down Expand Up @@ -961,7 +957,6 @@ describe('POST /notifications', () => {
const origNotificationConfig = appConfig.notification;
const newNotificationConfig = merge({}, origNotificationConfig, {
broadcastSubscriberChunkSize: 1,
broadcastSubRequestBatchSize: 10,
});
appConfig.notification = newNotificationConfig;

Expand Down Expand Up @@ -1094,7 +1089,6 @@ describe('POST /notifications', () => {
const origNotificationConfig = appConfig.notification;
const newNotificationConfig = merge({}, origNotificationConfig, {
broadcastSubscriberChunkSize: 1,
broadcastSubRequestBatchSize: 10,
logSkippedBroadcastPushDispatches: true,
});
appConfig.notification = newNotificationConfig;
Expand Down Expand Up @@ -1358,7 +1352,6 @@ describe('POST /notifications', () => {
const origNotificationConfig = appConfig.notification;
const newNotificationConfig = merge({}, origNotificationConfig, {
broadcastSubscriberChunkSize: 1,
broadcastSubRequestBatchSize: 2,
guaranteedBroadcastPushDispatchProcessing: false,
});
appConfig.notification = newNotificationConfig;
Expand Down

0 comments on commit a997056

Please sign in to comment.