Parallel IO

Parallel IO

To improve performance you could run any number of queries in parallel.

For the sake of example let’s assume that each query takes this much time to execute:

500ms - insert-order
30ms - select-product-by-id
600ms - http-get-map
30ms - push-random-value-to-queue

If you run them one by one 500+30+600+30 api response will take 1160ms, but if you run them in parallel, response time of this query will be only 600ms

{
  "type": "javascript",
  "id": "parallel-io",
  "file": "parallel-io.js",
  "public": true,
  "params": []
}

let multiRunOutput = multiRun([
    {
        "query": "insert-order",
        "params": {
            "totalPrice": 100,
        }
    },
    {
        "query": "select-product-by-id",
        "params": {
            "id": "123",
        }
    },
    {
        "query": "http-get-map",
        "params": {
            "long": 1.23456,
            "lat": 2.3456,
        }
    },
    {
        "query": "push-random-value-to-queue",
        "params": {
            "random": "thisIsSomeRandomText"
        }
    },
])

console.log(JSON.stringify(multiRunOutput))

setStatusCode(200)
setResult(multiRunOutput)