Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worker-Threads not running in parallel #22207

Open
Fabianofski opened this issue Jan 31, 2024 · 0 comments
Open

Worker-Threads not running in parallel #22207

Fabianofski opened this issue Jan 31, 2024 · 0 comments
Labels
needs investigation requires further investigation before determining if it is an issue or not perf performance related

Comments

@Fabianofski
Copy link

Fabianofski commented Jan 31, 2024

Version: Deno 1.40.2

I'm currently doing a benchmark of Node.js, Deno and Bun when using Worker Threads.
I have a very simple implementation, which creates a certain number of worker threads which calculate the fibonacci number.

This is the code i use for Deno

/* main.js */
const numThreads = Deno.args[0] || 1;

console.log(`Starting ${numThreads} Threads in Deno!`);
for (let i = 0; i < numThreads; i++)
    new Worker(new URL('./worker.js', import.meta.url).href, {
        type: 'module',
    });
/* worker.js */
fibonacci(1000);

function fibonacci(n, memo = {}) {
    if (n <= 1) return n;
    if (memo[n]) return memo[n];

    memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo);
    return memo[n];
}
self.close();

I did my benchmark with
/usr/bin/time -v deno run --allow-read main.js <num-threads>
and plotted it to a graph:
y: real time x: number of threads
Screenshot_20240131_153205
y: user + sys time x: number of threads
Screenshot_20240131_153404
y: Maximum resident size (memory) x: number of threads
Screenshot_20240131_153439

So the real time and user+sys time is increasing linearly and the memory usage is just staying the same. This behavior seems weird to me. I would expect an increase in the memory usage and a similar graph to Node.js and Bun for real and user+sys time.

This led me to believe that there is some kind of bug in the worker threads API of Deno. However maybe the bug is in my code.
If you have any clue, please let me know.

Thanks!

@littledivy littledivy added perf performance related needs investigation requires further investigation before determining if it is an issue or not labels Jan 31, 2024
@littledivy littledivy self-assigned this Jan 31, 2024
@littledivy littledivy removed their assignment Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation requires further investigation before determining if it is an issue or not perf performance related
Projects
None yet
Development

No branches or pull requests

2 participants