Some clients like ‘nats’ are supposed to work with a singleton connection instance.
To open one connection per workflow(trigger) does not scale.
n8n uses internally the DI pattern to create and query singleton service instances
with the help of ‘typedi’
But usage of the main ‘typedi’ container seams scoped inside the plugin-workflow.
n8n need to provide the possibility for plugins to register, host and query
global singletons from the DI container
My try on it, it creates singleton connection for a single workflow,
but not a singleton per credential instance
import { IAllExecuteFunctions, ICredentialDataDecryptedObject } from 'n8n-workflow';
import { Service } from 'typedi';
import { natsConnectionOptions } from './common';
import { JetStreamOptions, NatsConnection, connect } from 'nats';
import { defaultJsOptions } from 'nats/lib/jetstream/jsbaseclient_api';
type ConnectionEntry = {
id: string,
connection: NatsConnection,
refCount: number,
timer?: string | number | NodeJS.Timeout,
}
const idleTimeout = 180_000
@Service({ global: true })
export class NatsService {
private connections = new Map<string, ConnectionEntry>()
private registry = new FinalizationRegistry(this.releaseConnection)
This file has been truncated. show original
Reference issue:
Hello,
I would like to integrate an OPC UA trigger in n8n that returns values of a monitored item when they are available. Each trigger node should listen for a specified OPC UA item and then trigger the workflow.
However, I see a scalability issue for which I cannot find a solution. OPC UA servers only allow a limited number of parallel clients and sessions (normally 50 or 100). For this reason, a single session is usually used for many monitored items (can be more than 100). As far as I can …
n8n
February 6, 2024, 9:14am
2
It looks like your topic is missing some important information. Could you provide the following if applicable.
n8n version:
Database (default: SQLite):
n8n EXECUTIONS_PROCESS setting (default: own, main):
Running n8n via (Docker, npm, n8n cloud, desktop app):
Operating system:
This is not a bug/issue report, but to make the n8n bot happy
n8n version: 1.27.2
Database (default: SQLite): postgres
n8n EXECUTIONS_PROCESS setting (default: own, main): default
Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
Operating system: linux32-64
Perhaps @marcus from our node engineering team can shed some light on this one?
Still unresolved.
My code works fine, but it creates singletons for each workflow instance.
Most likely the workflows instances are created in executed in some kind sandbox environment of nodejs and I am no expert in nodejs features.
system
Closed
May 29, 2024, 8:41am
7
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.