zeromq.js icon indicating copy to clipboard operation
zeromq.js copied to clipboard

High CPU usage on Dish / Draft

Open bergmorten opened this issue 9 months ago • 3 comments

**When waiting for messages with the UDP dish it consumes a lot of CPU

import { Dish } from 'zeromq/draft';
import { cpuUsage } from 'process';

const group = 'demo';
async function run() {
  const dish = new Dish();
  dish.join(group);
  await dish.bind('udp://127.0.0.1:3000');

  console.log('Subscriber connected to port 3000');

 // same issue with for await (const [msg, {group}] of dish) 
  while (true) {
    const [message] = await dish.receive();
    console.log('received message:', message.toString());
  }
}

const startUsage = cpuUsage();
const printUsage = () => {
  const usage = cpuUsage(startUsage);

  console.log(`CPU Usage: `, usage);
};

setInterval(printUsage, 1000);

run();

Tested on

  • OS: Windows, node 20
  • ZeroMQ.js version: 6.3.0

bergmorten avatar Mar 13 '25 14:03 bergmorten

Maybe related to #429

bergmorten avatar Mar 13 '25 14:03 bergmorten

Can you try with the latest version instead of 6.0.0?

aminya avatar Mar 13 '25 17:03 aminya

Sorry that was a typo, I'm using latest 6.3.0

bergmorten avatar Mar 13 '25 18:03 bergmorten