Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-2679

Update JavaScript driver to support processing messages as a stream

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.5.1
    • 3.6.0, 3.5.3
    • javascript
    • None

    Description

      The JavaScript driver's _handleMessage receives messages from the gremlin server and stores each message in an object associated with the handler for the specific request. Currently, the driver waits until all the data is available from the gremlin server before allowing further processing of it.

      However, this can lead to cases where a lot of memory is required to hold onto the results before any processing can take place. If we had the abilty to process results as they come in from the gremlin server we could reduce memory in some cases

      If you are open to it I would like to submit a PR where submit can take an optional callback which is run on each set of data returned from the gremlin server, rather than waiting for the entire result set.

      The following examples assume that you have 100 vertices in your graph.

      current behaviour:

      const result = await client.submit("g.V()")
      console.log(result.toArray()) // 100 - all the vertices in your graph
      

      proposed addition

      await client.submit("g.V()", {}, { batchSize: 25 }, (data) => {
        console.log(data.toArray().length) // 25 - this callback will be called 4 times (100 / 25 = 4)
      })
      

      If the optional callback is not provided then the default behaviour is unchanged

      I have the changes running locally and the overall performance is unchanged, queries run about the same as they used to, however, for some specific queries memory usage has dropped considerably.

      With the process-on-message strategy the memory usage will be related to how large the batchSize is rather than the final result set. Using the default of 64 and testing some specific cases we have I can get the memory to go from 1.2gb to 10mb.

      Attachments

        Activity

          People

            jorgebg Jorge Bay
            tkolanko Tom Kolanko
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: