Skip to content

Connection pool cache #54

@javi11

Description

@javi11

First of all, nice work with the library ;).

I encountered a case where I have a lot of open subscriptions and for each subscriptor I have a new Datasources instance.
So in this case there is a connection pool for subscriptor with some memory usage let's say 2 mb. That memory is multiplying for every subscriptor.
Summarising the connection pool is not reused for same hosts with the implementation that is currently putted on place.

Do you think it will make sense to do a connection pool cache?

In my service I end up doing something like this:

const poolCache = new Map<string, Pool>()

class HTTPDataSource extends ApolloHTTPDataSource<Context> {
  public globalOptions?: HTTPDataSourceOptions
  constructor(baseUrl: string, options: HTTPDataSourceOptions = {}) {
    if (!options.pool) {
      options.pool = poolCache.get(baseUrl)
    }
    if (!options.pool || options.pool.closed || options.pool.destroyed) {
      options.pool = new Pool(baseUrl, options?.clientOptions)
      poolCache.set(baseUrl, options.pool)
    }
    super(baseUrl, options)
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions