Skip to content

Commit 2b98cab

Browse files
committed
Bump version to v1.0.6: README refinements
1 parent 6530d4f commit 2b98cab

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# zero-backpressure-semaphore-typescript
1+
<h2 align="middle">zero-backpressure-semaphore-typescript</h2>
22

33
The `ZeroBackpressureSemaphore` class implements a semaphore for Node.js projects, allowing users to limit the number of concurrently executing jobs.
44
This implementation does not queue pending jobs, thereby eliminating backpressure. As a result, users have better control over memory footprint, which enhances performance by reducing garbage-collector overhead.
@@ -48,13 +48,13 @@ This semaphore variant excels in eliminating backpressure when dispatching multi
4848

4949
Here, the start time of each job is crucial. Since a pending job cannot start its execution until the semaphore allows, there is no benefit to adding additional jobs that cannot start immediately. The `startExecution` method communicates the job's start time to the caller (resolves as soon as the job starts), which enables to create a new job as-soon-as it makes sense.
5050

51-
For example, consider an application managing 100,000 IoT sensors that require hourly data aggregation. To mitigate server load, a semaphore can be employed to limit the number of concurrent data aggregation tasks.
52-
Rather than pre-creating 100,000 jobs (one for each sensor), which could potentially overwhelm the Node.js task queue and induce backpressure, the system should adopt a **just-in-time** approach. This means creating a sensor aggregation job only when the semaphore indicates availability, thereby optimizing resource utilization and maintaining system stability.
51+
For example, consider an application managing 1M IoT sensors that require hourly data aggregation. To mitigate server load, a semaphore can be employed to limit the number of concurrent data aggregation tasks.
52+
Rather than pre-creating 1M jobs (one for each sensor), which could potentially overwhelm the Node.js task queue and induce backpressure, the system should adopt a **just-in-time** approach. This means creating a sensor aggregation job only when the semaphore indicates availability, thereby optimizing resource utilization and maintaining system stability.
5353

5454
Note: method `waitTillAllExecutingJobsAreSettled` can be used to perform post-processing, after all jobs have completed. It complements the typical use-cases of `startExecution`.
5555

5656
```ts
57-
import { SemaphoreJob, ZeroBackpressureSemaphore } from 'zero-backpressure-semaphore-ts';
57+
import { ZeroBackpressureSemaphore } from 'zero-backpressure-semaphore-typescript';
5858

5959
const maxConcurrentAggregationJobs = 24;
6060
const sensorAggregationSemaphore = new ZeroBackpressureSemaphore<void>(maxConcurrentAggregationJobs);
@@ -64,7 +64,7 @@ async function aggregateSensorsData(sensorUIDs: ReadonlyArray<string>) {
6464
// Until the semaphore can start aggregating data from the current sensor, it won't make
6565
// sense to add more jobs, as such will induce unnecessary backpressure.
6666
await sensorAggregationSemaphore.startExecution(
67-
async (): Promise<void> => aggregateSensorData(uid)
67+
(): Promise<void> => handleDataAggregation(uid)
6868
);
6969
}
7070
// Note: at this stage, jobs might be still executing, as we did not wait for
@@ -74,6 +74,10 @@ async function aggregateSensorsData(sensorUIDs: ReadonlyArray<string>) {
7474
await sensorAggregationSemaphore.waitTillAllExecutingJobsAreSettled();
7575
console.info(`Finished aggregating data from ${sensorUIDs.length} IoT sensors`);
7676
}
77+
78+
async function handleDataAggregation(sensorUID): Promise<void> {
79+
// Business logic for aggregating data from a single sensor.
80+
}
7781
```
7882

7983
## 2nd use-case: Single Job Execution
@@ -85,7 +89,7 @@ For example, consider fetching data from an external resource within a route han
8589
The concurrency limit for such operations is typically set based on external constraints (e.g., reducing the chances of being throttled) or the desire to limit network resource usage.
8690

8791
```ts
88-
import { SemaphoreJob, ZeroBackpressureSemaphore } from 'zero-backpressure-semaphore-ts';
92+
import { SemaphoreJob, ZeroBackpressureSemaphore } from 'zero-backpressure-semaphore-typescript';
8993

9094
type UserInfo = Record<string, string>;
9195

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zero-backpressure-semaphore-typescript",
3-
"version": "1.0.5",
4-
"description": "A classic semaphore with modern API, inspired by the RAII idiom, offering backpressure control for enhanced efficiency",
3+
"version": "1.0.6",
4+
"description": "A classic semaphore with modern API, inspired by the RAII idiom. It features backpressure control for enhanced efficiency, and includes a built-in method to gracefully await the completion of all currently executing jobs.",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/ori88c/zero-backpressure-semaphore-typescript.git"
@@ -23,10 +23,12 @@
2323
"lock",
2424
"async",
2525
"job",
26+
"task",
2627
"concurrency",
2728
"backpressure",
2829
"limit",
29-
"rate-limiter",
30+
"schedule",
31+
"executor",
3032
"nodejs",
3133
"typescript",
3234
"ts"

0 commit comments

Comments
 (0)