Code Monkey home page Code Monkey logo

Comments (5)

jasnell avatar jasnell commented on June 1, 2024 1

Worker threads in general have a ready event, yes. In Piscina, runTask() will not attempt to dispatch tasks to workers until after the worker signal they are ready.

from piscina.

metcoder95 avatar metcoder95 commented on June 1, 2024 1

Hey! Kind of late to the party but I believe the use case is interesting.
You want to do a warm-up of the threads, so they are ready beforehand (e.g. warm it up before starting to receive requests, similar to warming up the cache).

I agree with @jasnell that a ready might not be useful, but we already have minThreads at hand that can be used as a baseline, and Piscina ensures those minimum workers are available before starting processing tasks.

from piscina.

meixg avatar meixg commented on June 1, 2024

Worker threads in general have a ready event, yes. In Piscina, runTask() will not attempt to dispatch tasks to workers until after the worker signal they are ready.

I know that Piscina use worker's ready event inside,
but maybe we need a ready event from Piscina.

start server -> wait all threads ready (use minThreads) -> server listen()

from piscina.

jasnell avatar jasnell commented on June 1, 2024

Sorry for the later response. I'm not sure a ready event for piscina is useful, to be honest. Tasks are queued until there's a worker available and there's really no reason an application should have to wait to use the worker pool. Can you expand a bit on the use case?

from piscina.

meixg avatar meixg commented on June 1, 2024

When using on a server, the first few response will be too slow.
this happens especially when we have a big service, and the server restarts a lot per day (because of code iteration).
if we have a ready event, we can make some server restart first,wait ready,then restart others.

anyway, this maybe a extreme case.

I found a trick way to do this:

async function initThread() {
    let threadNum = 10;
    let tasks = [];
    while (threadNum--) {
        // just init, thread can use `isWarmup`
        tasks.push(piscina.runTask({ isWarmup: true }));
    }
    await Promise.all(tasks);
}

from piscina.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.