I've been using the typescript client and wondered about the sniffing behaviour using the following code:
const client = new Client({
nodes: [ "http://localhost:9200" ],
sniffOnStart: true,
sniffOnConnectionFault: true,
});
client.on('sniff', (err, result) => {
console.log("### SNIFF", err, result)
})
client.on('response', (err, result) => {
console.log("### REQUEST", err, result)
})
const health = await client.cluster.health();
console.log("### HEALTH FINISHED")
// wait a little more until sniffing is logged...
await new Promise(f => setTimeout(f, 2000));
The health will be finished, before the sniffing is done. I suppose that this is expected, but wanted to ensure.
If the master nodes are used as initial nodes to connect to a cluster, then for a few possibly hundred milliseconds (until the sniffing is done and the connection pool is updated) those will be hit with a search request.
Is there any possibility to wait for the sniffing to finish and only then be ready or is everyone good with putting a little load on the initial discovery nodes that are very likely be master nodes?
Answering myself a little here. One could alleviate the issue by waiting for the first sniff to finish before becoming ready - as I don't know if that sniff will always finish (or I maybe attached to it too late as there is no lifecycle, I also added a dumb two second timeout for this)
I think it'd be best not to do this: ideally if you have dedicated master nodes then they're not even visible to clients. Instead I'd suggest starting with (a reasonable guess at) the nodes you actually want to use for client traffic. If it's tricky to make such a guess in your environment then consider some other layer of abstraction (e.g. round-robin DNS or a reverse proxy load balancer) to support you through the sniffing phase.
Having your application wait until sniffing is complete also seems ok, but also consider whether it's worth worrying about. You shouldn't be starting up clients very often, so a little misdirected load during the initial sniffing phase shouldn't be more than a tiny fraction of the total.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.