Running a flow triggered via HTTP concurrently

I am sorry if that has been answered somewhere else already, I haven't found exactly what I need via search.

Let's say I'm building a flow that starts with an http-in node so that the flow can be triggered via an HTTP endpoint.

Inside of the flow, there is some data processing such as reading from/writing to a database, sending notifications, etc.

Currently, with just http-in -> json -> delay (for testing purposes) -> http-out, if I trigger the flow in multiple browser tables, they all run sequentially so that the second invocation waits until the first one finishes.

I understand that most likely this is due to how Node.js works, but is there any way to have parallel instances of the same flow?

To explain better the usecase: a flow for me is a template for a pipeline which can be run by multiple users at the same time, and it would be unfortunate to run all instances one at a time.

Thanks!

Do you mean it is waiting for the http out to complete before accepting the next http in? That should not happen.

This is not true.

GIF demonstrating async (non sequential) operation

WindowsTerminal_QSZVo8nuxo

demo flow

[{"id":"10db3e6940831566","type":"http in","z":"65608a30f8a8cec4","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":470,"y":600,"wires":[["fe98d449ecd63dc1","5150a9b9cf5c5f16"]]},{"id":"fe98d449ecd63dc1","type":"function","z":"65608a30f8a8cec4","name":"function 4","func":"msg.payload = \"You specified a delay of \" + msg.req.query.delay + \"ms\"\n\nmsg.delay = msg.req.query.delay\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":600,"wires":[["b680ee84852ef304"]]},{"id":"cab6ead2adc71b78","type":"http response","z":"65608a30f8a8cec4","name":"","statusCode":"","headers":{},"x":930,"y":600,"wires":[]},{"id":"b680ee84852ef304","type":"delay","z":"65608a30f8a8cec4","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":770,"y":600,"wires":[["cab6ead2adc71b78"]]},{"id":"5150a9b9cf5c5f16","type":"debug","z":"65608a30f8a8cec4","name":"debug 197","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":680,"wires":[]}]
[
    {
        "id": "106100fc7cbdc224",
        "type": "http in",
        "z": "ae2f93afd21df814",
        "name": "test-flow",
        "url": "test-flow",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 100,
        "y": 360,
        "wires": [
            [
                "7f2b789a8ae3ed50"
            ]
        ]
    },
    {
        "id": "56cfb5bbb2f7b604",
        "type": "http response",
        "z": "ae2f93afd21df814",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 790,
        "y": 340,
        "wires": []
    },
    {
        "id": "7f2b789a8ae3ed50",
        "type": "json",
        "z": "ae2f93afd21df814",
        "name": "",
        "property": "req.query",
        "action": "",
        "pretty": false,
        "x": 350,
        "y": 360,
        "wires": [
            [
                "9e7cd1649a3338e3"
            ]
        ]
    },
    {
        "id": "9e7cd1649a3338e3",
        "type": "delay",
        "z": "ae2f93afd21df814",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 560,
        "y": 360,
        "wires": [
            [
                "56cfb5bbb2f7b604"
            ]
        ]
    }
]

Here is mine. Maybe, I just created the flow in a stupid way, but my second tab does wait for the first one to complete with this setup.

Let me clarify (see the flow JSON above).

What happens is that if I have two tabs where I trigger /test-flow at the same time, the second one finishes in 10 seconds, not in 5-6 as if waiting for the first one to finish first.

The example suggested by @Steve-Mcl, however, works but I don't understand why mine doesn't now :slight_smile:

Try setting your delay node to a random time, then you may see that the second http request can finish before the first.

Yeah, that makes sense, but I still don't understand what happens in my simple example above.

If I deploy the flow and then trigger it in 3 tabs in a row, the last one will get a response in ~15 seconds. I do not expect exactly 5 seconds, this is all concurrent, I understand, but they seem to be running sequentially which makes me think (baed on the example above that works differently) that something is clearly wrong in my flow.

That maybe the browser executing each tab concurrently as they are calling same page. Try in different browsers and/or different devices.

Okay, this even sounds strange, but it's subjectively worse when the delay is fixed.
In your example, if I run 2 CURLs or browser tabs with delay=5000, one of them finishes in ~5s, but the second one takes about 10s. Is that expected?

It seems that you're right. Running 1 with curl and 1 in the browser works as expected. Weird. Looks like some browser special behavior. Thanks everyone for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.