Coder Social home page Coder Social logo

Comments (13)

numtel avatar numtel commented on August 25, 2024 9

Any word on this? Do I need to do anything to use a connection pool or is it automatic? How is this still open after 3 years?

from elasticsearch-js.

wbyoung avatar wbyoung commented on August 25, 2024 1

@spalger I've just come across this as well and after poking through the source, it appears that the connection pool that's implemented is a pool of connections to nodes in the Elasticsearch cluster, one per host, is that correct?

More to the point: it's not a pool of open keep-alive connections for each host to avoid the cost of establishing the HTTP connection to a host to begin with as is typically meant by connection pooling in the context of database connections. Is that true?

If one did want pooling, for instance, using generic-pool, does this seem appropriate (and does pooling these clients make sense if there may be multiple concurrent code paths that work with Elasticsearch):

import elasticsearch from 'elasticsearch';
import { createPool } from 'generic-pool';

const pool = createPool({ create, destroy }, {
  max: 40,
  min: 4,
  idleTimeoutMillis: 1000,
});

async function create(): Promise<elasticsearch.Client> {
  const client = new elasticsearch.Client({
    host: 'localhost:9200',
    log: 'trace',
    apiVersion: '5.0',
  });

  // ensure connection has been created
  await client.ping({ requestTimeout: 1000 });

  return client;
}

function destroy(client: elasticsearch.Client): Promise<void> {
  client.close(); // no way to tell when connects are actually closed

  return Promise.resolve();
}

from elasticsearch-js.

spalger avatar spalger commented on August 25, 2024 1

@wbyoung the connection pool implemented in the client does not actually pool sockets as one might expect (naming was chosen before I implemented the standard Elasticsearch client design). That said the HttpConnection object, the default connection class used in node.js, creates a unique agentkeepalive agent that has a pool of keepalive sockets for that es host/connection/node

from elasticsearch-js.

spalger avatar spalger commented on August 25, 2024

Reconnection will happen automatically, after the deadTimeout. There are several other configuration options applicable to the connection pool detailed in the configuration section.

You're right though, I do need to write more about the overall design and what is and isn't handled by the module.

from elasticsearch-js.

chirag04 avatar chirag04 commented on August 25, 2024

@spenceralger It says coming soon under connection pool in the configuration section.

from elasticsearch-js.

pspeter3 avatar pspeter3 commented on August 25, 2024

+1 This would be very helpful if it is necessary

from elasticsearch-js.

jaredhirsch avatar jaredhirsch commented on August 25, 2024

+1, please document the client pool behavior. Relates to #165

from elasticsearch-js.

nijikokun avatar nijikokun commented on August 25, 2024

For the love of god document this 👍

from elasticsearch-js.

mfrye-intuit avatar mfrye-intuit commented on August 25, 2024

Please document this ASAP. We just wasted so much time trying to build our own pool.

from elasticsearch-js.

delvedor avatar delvedor commented on August 25, 2024

Hi! I'm closing this due to inactivity, if it is still an issue, please feel free to reopen! :)

from elasticsearch-js.

sibelius avatar sibelius commented on August 25, 2024

@wbyoung can you provide a more complete example of using generic-pool ?

from here #16 (comment)

from elasticsearch-js.

wbyoung avatar wbyoung commented on August 25, 2024

@sibelius not better than what's above… it's been 6 years and I'm no longer working on the project that used this. Your best bet would probably be the docs for geberic-pool.

from elasticsearch-js.

sibelius avatar sibelius commented on August 25, 2024

it will create 1 elastic search client per pool ?

from elasticsearch-js.

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.