Skip to content

Difficulties with long running candle pulling growing memory and bandwidth #70

Description

@gbarton

Description

I have a loop where ideally every hour or so I pull the latest daily candle info for all symbols. I was creating a loop through batches of all symbols, subscribing for say 30 seconds, then unsubscribing and moving onto the next batch. I had to stop this as I was constantly growing in ram usage before I would OOM at 8GB and restart the container.

Digging into the code a little (with ai help) I see that unsubscribe does not remove candle subscriptions:

File: quote-streamer.js:82-90

 unsubscribe(streamerSymbols) {
      streamerSymbols.forEach(symbol => {
          ALL_EVENT_TYPES.forEach(type => {
              this.dxLinkFeed.removeSubscriptions({ type, symbol });
          });
      });
 }

Where ALL_EVENT_TYPES is defined as:

  const ALL_EVENT_TYPES = [
      MarketDataSubscriptionType.Quote,
      MarketDataSubscriptionType.Trade,
      MarketDataSubscriptionType.Summary,
      MarketDataSubscriptionType.Profile,
      MarketDataSubscriptionType.Greeks,
      MarketDataSubscriptionType.Underlying
  ];

Candle does not seem to be something that ever gets unsubscribed from.

I thought I would be clever and just shutdown the streamer and create a new one, but that also grew ram at a steady rate, digging into this I found that disconnect() doesn't seem to ever close the underlying socket. I saw constantly increasing bandwidth usage which I suspect is from previous sockets still sending even if there is no event listener attached to them anymore.

File: quote-streamer.js:68-74

 disconnect() {
     if (_.isNil(this.dxLinkFeed)) {
         return;
     }
     this.eventListeners.forEach(listener => this.removeEventListener(listener));
     this.dxLinkFeed = null;  // ← Just nulls the reference, does NOT close the socket
 }

Thoughts/ideas? Thanks in advance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions