assignment-user-matcher 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +67 -69
- package/LICENCE +53 -0
- package/README.md +187 -149
- package/docs/README.md +362 -65
- package/docs/classes/default.md +107 -81
- package/docs/interfaces/User.md +16 -5
- package/docs/modules.md +21 -21
- package/package.json +2 -2
- package/src/matcher.class.ts +262 -93
- package/tests/matcher.test.ts +85 -16
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# `assignment-user-matcher`: Lightning-Fast, Tag-Based User & Assignment Matching
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/assignment-user-matcher)
|
|
4
|
-
[](https://github.com/ViljarVoidula/assignment-user-matcher/actions/workflows/npm-publish.yml)
|
|
5
|
+
|
|
5
6
|
<!-- Add other badges if you have them, e.g., build status, test coverage -->
|
|
6
7
|
|
|
7
8
|
**Tired of inefficiently assigning tasks or struggling to connect the right users with the right work? `assignment-user-matcher` is a specialized Node.js library designed for high-performance, near real-time matching of a smaller pool of users to a large volume of assignments, primarily based on shared tags and priority.**
|
|
@@ -12,9 +13,9 @@ It leverages the speed and efficiency of Redis to deliver a robust solution perf
|
|
|
12
13
|
|
|
13
14
|
In many applications, from customer service platforms to internal task management systems, the core challenge remains the same: how do you quickly and accurately assign incoming work (assignments) to the best available person (user)? This becomes particularly complex when dealing with:
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
- **Large volumes of incoming assignments:** Tasks can pile up quickly, demanding immediate attention.
|
|
17
|
+
- **Real-time requirements:** Users expect instant responses, and assignments need prompt handling.
|
|
18
|
+
- **Varying skill sets and priorities:** Not all users are equipped for all tasks, and some assignments are more critical than others.
|
|
18
19
|
|
|
19
20
|
Traditional matching systems can become bottlenecks, leading to delays, suboptimal pairings, and frustrated users or customers.
|
|
20
21
|
|
|
@@ -24,27 +25,28 @@ Traditional matching systems can become bottlenecks, leading to delays, suboptim
|
|
|
24
25
|
|
|
25
26
|
**Key Features:**
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
- **Tag-Based Matching:** Intelligently connect users and assignments based on an intersection of descriptive tags (e.g., skills, language, department).
|
|
29
|
+
- **Priority-Aware:** Ensure that high-priority assignments are surfaced and processed first.
|
|
30
|
+
- **Redis-Powered:** Utilizes Redis for its in-memory data structures, enabling blazing-fast lookups and operations.
|
|
31
|
+
- **Optimized for Specific Scenarios:** Excels where a smaller group of users handles a large number of assignments.
|
|
32
|
+
- **User Backlog Management:** Prevents users from being overwhelmed by limiting the number of assignments they can be tentatively matched with.
|
|
32
33
|
|
|
33
34
|
## Why `assignment-user-matcher`?
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
- 🚀 **Speed:** Designed for near real-time performance, ensuring assignments are matched and delivered swiftly.
|
|
37
|
+
- 🎯 **Accuracy:** Improves the quality of matches by considering relevant tags and priorities.
|
|
38
|
+
- ⚙️ **Efficiency:** Optimizes resource allocation, ensuring users are working on the most appropriate and urgent tasks.
|
|
39
|
+
- 😌 **Improved Experience:** Leads to faster response times for customers and a more streamlined workflow for users.
|
|
40
|
+
- 💡 **Scalable (for its niche):** Handles a large throughput of assignments efficiently.
|
|
40
41
|
|
|
41
42
|
## Core Concepts: How It Works
|
|
42
43
|
|
|
43
44
|
`assignment-user-matcher` operates on a few key principles:
|
|
44
45
|
|
|
45
46
|
1. **Users and Assignments Have Tags:**
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
- **Users:** Each user is defined by an ID and a set of `tags` representing their skills, capabilities, or any other relevant attributes (e.g., `['english', 'billing_support', 'tier_1']`).
|
|
49
|
+
- **Assignments:** Each assignment has an ID, `tags` describing its requirements (e.g., `['english', 'billing_inquiry']`), and a `createdAt` timestamp (or a custom priority score) to determine its urgency.
|
|
48
50
|
|
|
49
51
|
2. **Matching via Tag Intersection:**
|
|
50
52
|
The core matching logic finds users whose tags have a common intersection with an assignment's tags.
|
|
@@ -62,11 +64,11 @@ Traditional matching systems can become bottlenecks, leading to delays, suboptim
|
|
|
62
64
|
|
|
63
65
|
`assignment-user-matcher` is particularly well-suited for:
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
- **📞 Call Centers:** Routing incoming calls (assignments) to the agent (user) with the right language skills, product knowledge, and availability.
|
|
68
|
+
- **🎫 Customer Support Ticketing:** Assigning new support tickets to support agents based on their expertise (e.g., "technical_issue," "api_support") and the ticket's urgency.
|
|
69
|
+
- **🗄️ Back-Office Operations:** Distributing tasks like data entry, document verification, or claims processing to available staff members based on task type and employee skills.
|
|
70
|
+
- **🚗 Gig Economy Platforms (Niche):** Matching available service providers to incoming customer requests where the provider pool is managed and assignments are plentiful (e.g., a dispatch system for a fleet of delivery drivers).
|
|
71
|
+
- ** Leads Distribution:** Assigning sales leads to representatives based on territory, product specialization, or lead score.
|
|
70
72
|
|
|
71
73
|
## Getting Started
|
|
72
74
|
|
|
@@ -89,53 +91,53 @@ import AssignmentMatcher from 'assignment-user-matcher'; // or `import { Assignm
|
|
|
89
91
|
import { createClient } from 'redis';
|
|
90
92
|
|
|
91
93
|
async function runExample() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const assignmentMatcher = new AssignmentMatcher(redisClient, {
|
|
100
|
-
redisPrefix: 'exampleApp:', // Good practice to namespace your Redis keys
|
|
101
|
-
maxUserBacklogSize: 5, // Max 5 assignments per user backlog
|
|
102
|
-
enableDefaultMatching: true
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Add a user
|
|
106
|
-
await assignmentMatcher.addUser({
|
|
107
|
-
id: 'agent_007',
|
|
108
|
-
tags: ['english', 'technical_support', 'vip_clients'],
|
|
109
|
-
});
|
|
110
|
-
console.log("User 'agent_007' added.");
|
|
111
|
-
|
|
112
|
-
// Add an assignment
|
|
113
|
-
await assignmentMatcher.addAssignment({
|
|
114
|
-
id: 'ticket_12345',
|
|
115
|
-
tags: ['english', 'technical_support'],
|
|
116
|
-
createdAt: new Date().getTime(), // Use current time for priority
|
|
117
|
-
});
|
|
118
|
-
console.log("Assignment 'ticket_12345' added.");
|
|
119
|
-
|
|
120
|
-
// Run the matching process
|
|
121
|
-
// This will attempt to match pending assignments to available users
|
|
122
|
-
console.log('Running matching process...');
|
|
123
|
-
await assignmentMatcher.matchUsersAssignments();
|
|
94
|
+
// Connect to your Redis instance
|
|
95
|
+
const redisClient = createClient({
|
|
96
|
+
// url: 'redis://your-redis-host:6379' // Optional: specify Redis URL if not default
|
|
97
|
+
});
|
|
98
|
+
await redisClient.connect();
|
|
99
|
+
console.log('Connected to Redis.');
|
|
124
100
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
101
|
+
const assignmentMatcher = new AssignmentMatcher(redisClient, {
|
|
102
|
+
redisPrefix: 'exampleApp:', // Good practice to namespace your Redis keys
|
|
103
|
+
maxUserBacklogSize: 5, // Max 5 assignments per user backlog
|
|
104
|
+
enableDefaultMatching: true,
|
|
105
|
+
});
|
|
128
106
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
107
|
+
// Add a user
|
|
108
|
+
await assignmentMatcher.addUser({
|
|
109
|
+
id: 'agent_007',
|
|
110
|
+
tags: ['english', 'technical_support', 'vip_clients'],
|
|
111
|
+
});
|
|
112
|
+
console.log("User 'agent_007' added.");
|
|
134
113
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
114
|
+
// Add an assignment
|
|
115
|
+
await assignmentMatcher.addAssignment({
|
|
116
|
+
id: 'ticket_12345',
|
|
117
|
+
tags: ['english', 'technical_support'],
|
|
118
|
+
createdAt: new Date().getTime(), // Use current time for priority
|
|
119
|
+
});
|
|
120
|
+
console.log("Assignment 'ticket_12345' added.");
|
|
121
|
+
|
|
122
|
+
// Run the matching process
|
|
123
|
+
// This will attempt to match pending assignments to available users
|
|
124
|
+
console.log('Running matching process...');
|
|
125
|
+
await assignmentMatcher.matchUsersAssignments();
|
|
126
|
+
|
|
127
|
+
// Check current assignments for the user
|
|
128
|
+
const userAssignments = await assignmentMatcher.getCurrentAssignmentsForUser('agent_007');
|
|
129
|
+
console.log(`Assignments for 'agent_007':`, userAssignments);
|
|
130
|
+
|
|
131
|
+
if (userAssignments && userAssignments.length > 0) {
|
|
132
|
+
console.log(`User 'agent_007' is matched with assignment '${userAssignments[0].id}'.`);
|
|
133
|
+
} else {
|
|
134
|
+
console.log(`User 'agent_007' has no assignments currently.`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Clean up (optional, depending on your Redis setup)
|
|
138
|
+
// await redisClient.flushDb(); // Be careful with this in production!
|
|
139
|
+
await redisClient.quit();
|
|
140
|
+
console.log('Disconnected from Redis.');
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
runExample().catch(console.error);
|
|
@@ -149,26 +151,26 @@ The main class provided is `AssignmentMatcher`.
|
|
|
149
151
|
|
|
150
152
|
Creates a new `AssignmentMatcher` instance.
|
|
151
153
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
- `redisClient`: An initialized and connected `redis` client instance (version 4+).
|
|
155
|
+
- `options` (Optional): Configuration options for the matcher. See [Options](#options) below.
|
|
154
156
|
|
|
155
157
|
### `addUser(user: User): Promise<void>`
|
|
156
158
|
|
|
157
159
|
Adds or updates a user in the system.
|
|
158
160
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
- `user`: An object representing the user.
|
|
162
|
+
- `id: string`: Unique identifier for the user.
|
|
163
|
+
- `tags: string[]`: Array of tags associated with the user.
|
|
162
164
|
|
|
163
165
|
### `addAssignment(assignment: Assignment): Promise<void>`
|
|
164
166
|
|
|
165
167
|
Adds a new assignment to be matched.
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
- `assignment`: An object representing the assignment.
|
|
170
|
+
- `id: string`: Unique identifier for the assignment.
|
|
171
|
+
- `tags: string[]`: Array of tags required for the assignment.
|
|
172
|
+
- `createdAt: number`: Timestamp (e.g., `new Date().getTime()`) indicating when the assignment was created. Used for default prioritization (older assignments get higher priority). Can be influenced by `prioritizationFunction`.
|
|
173
|
+
- `priority?: number | string`: Optional explicit priority. If `prioritizationFunction` is used, this might be an input to it.
|
|
172
174
|
|
|
173
175
|
### `matchUsersAssignments(): Promise<void>`
|
|
174
176
|
|
|
@@ -178,7 +180,7 @@ Triggers the matching process. This method iterates through pending assignments
|
|
|
178
180
|
|
|
179
181
|
Retrieves the current list of assignments that a user is tentatively matched with (i.e., in their backlog).
|
|
180
182
|
|
|
181
|
-
|
|
183
|
+
- `userId: string`: The ID of the user.
|
|
182
184
|
|
|
183
185
|
### `removeUser(userId: string): Promise<void>`
|
|
184
186
|
|
|
@@ -198,46 +200,44 @@ You can pass an options object to the `AssignmentMatcher` constructor:
|
|
|
198
200
|
|
|
199
201
|
```typescript
|
|
200
202
|
type Options = {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
assignmentId?: string
|
|
240
|
-
) => Promise<[number, number]>;
|
|
203
|
+
// How many of the highest-priority assignments to consider in one matching batch.
|
|
204
|
+
// A larger batch might find more matches but could be slower.
|
|
205
|
+
relevantBatchSize?: number; // Default: 50
|
|
206
|
+
|
|
207
|
+
// Prefix for all Redis keys used by this library. Useful for namespacing
|
|
208
|
+
// if you use the same Redis instance for multiple applications or purposes.
|
|
209
|
+
redisPrefix?: string; // Default: '' (empty string)
|
|
210
|
+
|
|
211
|
+
// The maximum number of assignments a user can have in their "tentative" backlog.
|
|
212
|
+
// Once a user reaches this limit, they won't be matched with new assignments
|
|
213
|
+
// until some are completed or removed.
|
|
214
|
+
maxUserBacklogSize?: number; // Default: 9
|
|
215
|
+
|
|
216
|
+
// Whether to enable the default tag-based matching logic.
|
|
217
|
+
// If set to false, you MUST provide a custom `matchingFunction`.
|
|
218
|
+
enableDefaultMatching?: boolean; // Default: true
|
|
219
|
+
|
|
220
|
+
// A custom function to determine the priority of an assignment.
|
|
221
|
+
// The function receives assignment objects (or undefined if fewer than 3 are available for comparison)
|
|
222
|
+
// and should return a numerical priority score. Higher scores mean higher priority.
|
|
223
|
+
// Useful if `createdAt` is not sufficient for your prioritization needs.
|
|
224
|
+
prioritizationFunction?: (...args: (Assignment | undefined)[]) => Promise<number>;
|
|
225
|
+
|
|
226
|
+
// A custom function to determine if a user can be matched with an assignment
|
|
227
|
+
// and the "cost" or "rank" of that match.
|
|
228
|
+
// If `enableDefaultMatching` is true, this function can augment or override the default logic.
|
|
229
|
+
// If `enableDefaultMatching` is false, this function is solely responsible for matching.
|
|
230
|
+
// It should return a tuple: `[matchRank, userCost]`.
|
|
231
|
+
// - `matchRank`: A score indicating the quality of the match (higher is better).
|
|
232
|
+
// A rank of 0 or less means no match.
|
|
233
|
+
// - `userCost`: A score indicating the "cost" of assigning this task to this user
|
|
234
|
+
// (lower is better, used for tie-breaking among users).
|
|
235
|
+
matchingFunction?: (
|
|
236
|
+
user: User,
|
|
237
|
+
assignmentTags: string[],
|
|
238
|
+
assignmentPriority: number | string, // This is the score from prioritizationFunction or createdAt
|
|
239
|
+
assignmentId?: string,
|
|
240
|
+
) => Promise<[number, number]>;
|
|
241
241
|
};
|
|
242
242
|
```
|
|
243
243
|
|
|
@@ -246,7 +246,6 @@ type Options = {
|
|
|
246
246
|
The following example demonstrates adding multiple users and assignments and then measures the performance of the matching process.
|
|
247
247
|
|
|
248
248
|
```javascript
|
|
249
|
-
#!/usr/bin/env ./node_modules/.bin/ts-node-script
|
|
250
249
|
// Save this as example.ts and ensure you have ts-node and typescript installed
|
|
251
250
|
// npm install -D ts-node typescript
|
|
252
251
|
// Then run: ./example.ts
|
|
@@ -259,7 +258,7 @@ async function bootstrap(userCount: number, assignmentCount: number) {
|
|
|
259
258
|
await redisClient.connect();
|
|
260
259
|
// It's good practice to clear keys for a fresh test run,
|
|
261
260
|
// but be VERY careful with flushDb in production.
|
|
262
|
-
|
|
261
|
+
await redisClient.flushDb();
|
|
263
262
|
|
|
264
263
|
|
|
265
264
|
const assignmentMatcher = new AssignmentMatcher(redisClient, {
|
|
@@ -274,7 +273,7 @@ async function bootstrap(userCount: number, assignmentCount: number) {
|
|
|
274
273
|
for (let i = 0; i < userCount; i++) {
|
|
275
274
|
await assignmentMatcher.addUser({
|
|
276
275
|
id: `user_${i}`,
|
|
277
|
-
tags: ['tag1', 'tag2', `unique_skill_${i %
|
|
276
|
+
tags: ['tag1', 'tag2', `unique_skill_${i % 5}`], // Varied tags with smaller modulo for more matches
|
|
278
277
|
});
|
|
279
278
|
}
|
|
280
279
|
|
|
@@ -282,55 +281,79 @@ async function bootstrap(userCount: number, assignmentCount: number) {
|
|
|
282
281
|
for (let i = 0; i < assignmentCount; i++) {
|
|
283
282
|
await assignmentMatcher.addAssignment({
|
|
284
283
|
id: `assignment_${i}`,
|
|
285
|
-
tags: ['tag1', `unique_skill_${i %
|
|
284
|
+
tags: ['tag1', `unique_skill_${i % 5}`], // Ensure more matches
|
|
286
285
|
createdAt: new Date().getTime() + i, // Stagger creation time slightly
|
|
287
286
|
});
|
|
288
287
|
}
|
|
289
288
|
console.log('Setup complete.');
|
|
290
289
|
|
|
291
|
-
// --- Performance Measurement for Matching ---
|
|
290
|
+
// --- Performance Measurement for Initial Matching ---
|
|
291
|
+
console.log('Performing initial matching...');
|
|
292
292
|
performance.mark('match-start');
|
|
293
293
|
await assignmentMatcher.matchUsersAssignments();
|
|
294
294
|
performance.mark('match-end');
|
|
295
|
-
const matchMeasure = performance.measure('Matching Process', 'match-start', 'match-end');
|
|
296
|
-
console.log(`
|
|
297
|
-
|
|
298
|
-
// ---
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
295
|
+
const matchMeasure = performance.measure('Initial Matching Process', 'match-start', 'match-end');
|
|
296
|
+
console.log(`Initial matching execution time: ${matchMeasure.duration.toFixed(2)}ms`);
|
|
297
|
+
|
|
298
|
+
// --- Log initial assignments for all users ---
|
|
299
|
+
console.log('\nInitial assignments for users:');
|
|
300
|
+
for (let i = 0; i < userCount; i++) {
|
|
301
|
+
const userAssignments = await assignmentMatcher.getCurrentAssignmentsForUser(`user_${i}`);
|
|
302
|
+
console.log(`User 'user_${i}' has ${userAssignments.length} assignments.`);
|
|
303
303
|
}
|
|
304
|
-
performance.mark('current-assignment-end');
|
|
305
|
-
const currentTaskMeasure = performance.measure(
|
|
306
|
-
'Retrieving User Assignments (for 5 users)',
|
|
307
|
-
'current-assignment-start',
|
|
308
|
-
'current-assignment-end'
|
|
309
|
-
);
|
|
310
|
-
console.log(`Current assignment retrieval time: ${currentTaskMeasure.duration.toFixed(2)}ms`);
|
|
311
304
|
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
305
|
+
// --- Simulate completing assignments ---
|
|
306
|
+
console.log('\nSimulating users completing assignments...');
|
|
307
|
+
for (let i = 0; i < userCount; i++) {
|
|
308
|
+
// Only process for the first 15 users
|
|
309
|
+
if (i >= 15) break;
|
|
310
|
+
|
|
311
|
+
// Get the current assignments for this user
|
|
312
|
+
const userAssignments = await assignmentMatcher.getCurrentAssignmentsForUser(`user_${i}`);
|
|
313
|
+
|
|
314
|
+
if (userAssignments.length > 0) {
|
|
315
|
+
// Simulate completing half of the assignments
|
|
316
|
+
const assignmentsToComplete = userAssignments.slice(0, Math.ceil(userAssignments.length / 2));
|
|
317
|
+
console.log(`User 'user_${i}' completing ${assignmentsToComplete.length} assignments...`);
|
|
318
|
+
|
|
319
|
+
// Remove these assignments from the user's queue
|
|
320
|
+
for (const assignmentId of assignmentsToComplete) {
|
|
321
|
+
await redisClient.sRem(assignmentMatcher.redisPrefix + `user:user_${i}:assignments`, `assignment:${assignmentId}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// --- Perform another matching after completion ---
|
|
327
|
+
console.log('\nPerforming second matching after assignment completion...');
|
|
328
|
+
performance.mark('rematch-start');
|
|
329
|
+
await assignmentMatcher.matchUsersAssignments();
|
|
330
|
+
performance.mark('rematch-end');
|
|
331
|
+
const rematchMeasure = performance.measure('Second Matching Process', 'rematch-start', 'rematch-end');
|
|
332
|
+
console.log(`Second matching execution time: ${rematchMeasure.duration.toFixed(2)}ms`);
|
|
333
|
+
|
|
334
|
+
// --- Final check of assignments for all users ---
|
|
335
|
+
console.log('\nFinal assignments for users:');
|
|
336
|
+
for (let i = 0; i < userCount; i++) {
|
|
337
|
+
if (i >= 15) break; // Only show for the first 15 users
|
|
338
|
+
const userAssignments = await assignmentMatcher.getCurrentAssignmentsForUser(`user_${i}`);
|
|
339
|
+
console.log(`User 'user_${i}' now has ${userAssignments.length} assignments.`);
|
|
317
340
|
}
|
|
318
341
|
|
|
319
342
|
console.log(
|
|
320
343
|
`
|
|
321
344
|
Summary:
|
|
322
|
-
Users: ${userCount}
|
|
345
|
+
Users: ${userCount} (simulated 15 users completing assignments)
|
|
323
346
|
Assignments: ${assignmentCount}
|
|
324
|
-
Matching Duration: ${matchMeasure.duration.toFixed(2)}ms
|
|
325
|
-
|
|
347
|
+
Initial Matching Duration: ${matchMeasure.duration.toFixed(2)}ms
|
|
348
|
+
Second Matching Duration: ${rematchMeasure.duration.toFixed(2)}ms`
|
|
326
349
|
);
|
|
327
350
|
|
|
328
351
|
await redisClient.quit();
|
|
329
352
|
}
|
|
330
353
|
|
|
331
354
|
// Adjust these numbers to test different scales
|
|
332
|
-
const USER_COUNT =
|
|
333
|
-
const ASSIGNMENT_COUNT =
|
|
355
|
+
const USER_COUNT = 30;
|
|
356
|
+
const ASSIGNMENT_COUNT = 150000;
|
|
334
357
|
|
|
335
358
|
bootstrap(USER_COUNT, ASSIGNMENT_COUNT)
|
|
336
359
|
.then(() => {
|
|
@@ -343,11 +366,26 @@ bootstrap(USER_COUNT, ASSIGNMENT_COUNT)
|
|
|
343
366
|
});
|
|
344
367
|
```
|
|
345
368
|
|
|
369
|
+
### Example Performance Results
|
|
370
|
+
|
|
371
|
+
When running the above example with 30 users and 150,000 assignments, you might see results similar to this:
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
Summary:
|
|
375
|
+
Users: 30 (simulated 15 users completing assignments)
|
|
376
|
+
Assignments: 150000
|
|
377
|
+
Initial Matching Duration: 3.83ms
|
|
378
|
+
Second Matching Duration: 0.83ms
|
|
379
|
+
Performance test finished.
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
This demonstrates the library's impressive performance even with large numbers of assignments and shows how subsequent matching operations can be even faster after initial assignment distribution.
|
|
383
|
+
|
|
346
384
|
## Important Considerations (Disclaimer)
|
|
347
385
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
386
|
+
- **Optimized for a Specific Use Case:** `assignment-user-matcher` is primarily designed and optimized for scenarios with a **relatively small set of active users processing a large volume of incoming assignments** (e.g., call centers, customer support teams, back-office operations). While it might work for other scenarios, its performance characteristics are best suited for this model.
|
|
387
|
+
- **Redis Dependency:** This library requires a running Redis instance. Ensure your Redis server is adequately provisioned for your workload.
|
|
388
|
+
- **Near Real-Time, Not Instantaneous:** While fast, the matching process involves Redis operations and logic execution. "Near real-time" means it's quick, but not strictly instantaneous with nanosecond precision. The `matchUsersAssignments()` method needs to be called periodically or triggered by events (e.g., new assignment, user becomes available) to perform matching.
|
|
351
389
|
|
|
352
390
|
## Contributing
|
|
353
391
|
|