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

Design question: how to handle long computations in a node? #452

Open
florian-ts3d opened this issue Nov 13, 2024 · 2 comments
Open

Design question: how to handle long computations in a node? #452

florian-ts3d opened this issue Nov 13, 2024 · 2 comments

Comments

@florian-ts3d
Copy link

Hello, I'm trying to see what efforts would be needed to port to V3 and look at the changes I've done in the core logic so far: I was wondering what would be the best strategy to handle long computations? Right now the UI hangs if anything takes a long time to compute in a node.

Example: just add a Sleep of 10 seconds in one of the compute() function in the calculator example to see what I'm experiencing.

In my previous implementation I created WorkerNodeDataModels and workers but I'm not sure it's the best strategy (what happens when you have multiple inputs, what do you do with current long computation, etc etc...) and was wondering if this is something you thought about?

@paceholder
Copy link
Owner

Hello,

I never tried to work-around similar cases.
Maybe you could spawn a thread when your node is about to compute something and observe the fishish of the thread?

#include <QCoreApplication>
#include <QtConcurrent>
#include <QFuture>
#include <QFutureWatcher>
#include <QDebug>

void longTask() {
    qDebug() << "Task started on thread:" << QThread::currentThread();
    QThread::sleep(5); // Simulate long-lasting task
}

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    QFuture<void> future = QtConcurrent::run(longTask);

    QFutureWatcher<void> watcher;
    QObject::connect(&watcher, &QFutureWatcher<void>::finished, [&]() {
        qDebug() << "Task completed on thread:" << QThread::currentThread();
        app.quit();
    });

    watcher.setFuture(future);

    return app.exec();
}

Isn't it what you did before?
Or didn't I get you actual problem with the version 3?

Thanks
Dimitry

@florian-ts3d
Copy link
Author

Yes this is more or less the solution I came with with version 2, but I was struggling to decide what to do with input data that was coming when a task is executed.

  • Should I ignore it (I will not get the final result described by the graph I believe)
  • Should I create a FIFO on the node to process each request (will take too long)
  • Should I cancel the current task (if possible) and create a new one (might be the best choice for the ones I can cancel)

It becomes even more complex when these nodes have multiple inputs (A,B,C), so each update of each input triggers a new computation that is actually not the one you expect, but that could be a valid one to compute in theory.
Just for initialization it could generate these 3 tuple of data to execute, if A' is new data, then B', then C':
A',B,C
A',B',C
A',B',C'

This can become a big bottleneck as just to load an initial .flow tree, some nodes are updated 16 times in some scenarios I have for example. I was wondering if there was some best practice that I might have missed that you might know.

Thanks for the heavy work on this project :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants