Performance: Queue consumers (processors)
MEDIUM IMPACT
This affects how fast queued tasks are processed and how much CPU and memory the server uses during processing.
import { Processor, Process } from '@nestjs/bull'; import { Job } from 'bull'; @Processor('email') export class EmailProcessor { @Process() async handleEmail(job: Job) { await this.sendEmailAsync(job.data); } async sendEmailAsync(data: any) { // non-blocking async email sending return new Promise(resolve => setTimeout(() => { console.log('Email sent', data); resolve(true); }, 100)); } }
import { Processor, Process } from '@nestjs/bull'; import { Job } from 'bull'; @Processor('email') export class EmailProcessor { @Process() async handleEmail(job: Job) { // heavy synchronous task for (let i = 0; i < 1e8; i++) { // blocking loop } console.log('Email sent', job.data); } }
| Pattern | CPU Usage | Event Loop Blocking | Memory Usage | Verdict |
|---|---|---|---|---|
| Synchronous heavy task | High CPU spike | Blocks event loop | Stable | [X] Bad |
| Asynchronous non-blocking task | Balanced CPU | No blocking | Stable | [OK] Good |
| Concurrency = 1 | Low CPU utilization | No blocking | Stable | [!] OK |
| Concurrency > 1 | Better CPU utilization | No blocking | Stable | [OK] Good |
| Growing cache without cleanup | Moderate CPU | No blocking | Memory leak | [X] Bad |
| No cache or cleared cache | Moderate CPU | No blocking | Stable memory | [OK] Good |