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

Multiple instance/runtime running at same time? #419

Open
linonetwo opened this issue Sep 1, 2023 · 1 comment
Open

Multiple instance/runtime running at same time? #419

linonetwo opened this issue Sep 1, 2023 · 1 comment

Comments

@linonetwo
Copy link

I'm trying to understand how swarm control work in noflo-nodejs.

exports.startGraph = (graphPath, runtime, settings) => exports
.loadGraph({
graph: graphPath,
})
.then((graphInstance) => {
const graph = graphInstance;
graph.name = graph.name || path.basename(graphPath, path.extname(graphPath));
const graphName = `${settings.namespace}/${graph.name}`;
return runtime.graph.registerGraph(graphName, graph)
.then(() => runtime // eslint-disable-line no-underscore-dangle
.network._startNetwork(graph, graphName, 'none'))
.then(() => {
runtime.runtime.setMainGraph(graphName);
return runtime;
});
});

Here seems there is only one runtime in the nodejs server? And this singleton runtime will only have one main graph as setMainGraph is used.

So this make it seems that noflo-nodejs can only run a graph at one time, but it doesn't, so how does it do?

Background: I'm trying to run multiple graph at background in my app that embeds noflo.

@linonetwo
Copy link
Author

GPT4:

You're right in noting that the code snippet you provided suggests that a single graph is being set as the main graph for a given runtime. However, this doesn't imply that only one graph can run at a time. Let's break down some concepts:

  1. Runtime vs. Network: The runtime in NoFlo refers to the environment in which NoFlo is operating. For noflo-nodejs, this environment is Node.js. Within a runtime, you can have multiple NoFlo networks, and each network can be running a different graph or even the same graph with different input data. The runtime.runtime.setMainGraph(graphName); simply sets the main graph for that runtime, but it doesn't prevent other graphs from executing.

  2. Starting Multiple Graphs: If you want to run multiple graphs concurrently, you can instantiate and start multiple networks. Each graph would have its own state, data flow, and lifecycle. They'll all share the same event loop due to Node.js's single-threaded nature, but they can operate concurrently because of the non-blocking I/O model.

  3. Swarm Control: While the term "swarm" is generally associated with distributed systems (like Docker Swarm), in the context of noflo-nodejs, it may not relate to running multiple graphs across multiple systems. If you're looking to run multiple graphs in parallel within the same Node.js process, you'd be more concerned about managing multiple networks.

  4. noflo-nodejs Purpose: The noflo-nodejs tool is primarily designed as a runtime for executing NoFlo graphs within a Node.js environment. If you're looking to extend its functionality or customize its behavior, you might need to delve deeper into its internals, understand how it manages networks, and make necessary modifications or extensions.

For your specific use case, where you want to run multiple graphs in the background of your app:

  • You can start multiple networks for each graph you want to run. This allows you to have multiple flows operating concurrently.
  • If you want a higher degree of control and isolation, consider running multiple instances of noflo-nodejs (or your NoFlo app) in separate Node.js processes or even in separate containers. This would enable better resource allocation and management.

However, if you're looking for a built-in "swarm" feature or functionality in noflo-nodejs that inherently allows distributed execution of graphs across multiple systems, such a feature wasn't present as of my last update in 2021. You would need to implement such functionality yourself or look into other tools and platforms that provide distributed processing capabilities.

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

1 participant