Giter VIP home page Giter VIP logo

Comments (1)

George-Payne avatar George-Payne commented on September 27, 2024 1

Hi @FeepingCreature, thanks for the issue.

I suspect there's a timing issue where the client tries to start up a batch connection for every event.

Yep, that's exactly what is happening, the cache of batch streams is only populating after the connection was made (which is async) so as you were initiating multiple requests in the same event loop, it was initiating the creation each time.

I've changed caching logic to cache a promise of a batch append stream, so it only gets created once.

This uncovered another issue that the backpressure logic was assuming that only one call was using the stream at a time, so was flooding the connection after the first flush. I've also fixed that.

You can find the PR here: #305


PerformanceTestNodeJsGrpc

If you want to eek out some more performance, using batching will give you the best performance:

For 100,000 events (after #305):

Code in issue
const {
    EventStoreDBClient,
    jsonEvent,
} = require("@eventstore/db-client");

const client = EventStoreDBClient.connectionString('esdb://localhost:2113?tls=false')
const streamName = "PerformanceTestNodeJsGrpc";
const numberOfEvents = 100_000;

function oneKiloByteEvent() {
    return jsonEvent({
        type: "AnyEventType",
        data: {
            value: 'A'.repeat(904)
        },
    });
}

(async () => {
    try {
        var requests = [];
        for (var i = 0; i < numberOfEvents; i++) {
            requests.push(client.appendToStream(streamName, [oneKiloByteEvent()]));
        }
        await Promise.all(requests);
        console.log('Done.');
    } catch (e) {
        console.log(`append failed: ${e}`);
    }
})();

Takes about 38s

Batches of 200, awaiting each call
const { EventStoreDBClient, jsonEvent } = require("@eventstore/db-client");

const client = EventStoreDBClient.connectionString(
  "esdb://localhost:2113?tls=false"
);
const streamName = "PerformanceTestNodeJsGrpc";
const numberOfEvents = 100_000;
const batchSize = 200;

function oneKiloByteEvent() {
  return jsonEvent({
    type: `event`,
    data: {
      value: "A".repeat(904),
    },
  });
}

(async () => {
  try {
    for (let i = 0; i < numberOfEvents / batchSize; i++) {
      await client.appendToStream(
        streamName,
        Array.from({ length: batchSize }, oneKiloByteEvent),
        {
          deadline: 10_000_000,
        }
      );
    }
    console.log('Done.');
  } catch (e) {
    console.log(`append failed: ${e}`, e);
  }

  await client.dispose();
})();

Takes about 8s

from eventstore-client-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.