Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverting to legacy ES client behavior where maxSockets = Infinity #113644

Merged
merged 6 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/core/server/elasticsearch/client/client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ describe('parseClientOptions', () => {
);
});

it('specifies `headers.maxSockets` Infinity and `keepAlive` true by default', () => {
const config = createConfig({});

expect(parseClientOptions(config, false)).toEqual(
expect.objectContaining({
agent: {
keepAlive: true,
maxSockets: Infinity,
},
})
);
});

describe('basic options', () => {
it('`customHeaders` option', () => {
const config = createConfig({
Expand Down Expand Up @@ -76,11 +89,21 @@ describe('parseClientOptions', () => {
);
});

it('`keepAlive` option', () => {
expect(parseClientOptions(createConfig({ keepAlive: true }), false)).toEqual(
expect.objectContaining({ agent: { keepAlive: true } })
);
expect(parseClientOptions(createConfig({ keepAlive: false }), false).agent).toBeUndefined();
describe('`keepAlive option`', () => {
it('`keepAlive` is true', () => {
const options = parseClientOptions(createConfig({ keepAlive: true }), false);
expect(options.agent).toHaveProperty('keepAlive', true);
});

it('`keepAlive` is false', () => {
const options = parseClientOptions(createConfig({ keepAlive: false }), false);
expect(options.agent).toHaveProperty('keepAlive', false);
});

it('`keepAlive` is undefined', () => {
const options = parseClientOptions(createConfig({}), false);
expect(options.agent).toHaveProperty('keepAlive', true);
});
});

it('`sniffOnStart` options', () => {
Expand Down
9 changes: 4 additions & 5 deletions src/core/server/elasticsearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export function parseClientOptions(
// do not make assumption on user-supplied data content
// fixes https://github.com/elastic/kibana/issues/101944
disablePrototypePoisoningProtection: true,
agent: {
maxSockets: Infinity,
Copy link
Contributor

@mshustov mshustov Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from #112756 (comment)

When Kibana's communication with Elasticsearch occurs over TLS, there's rather significant overhead in establishing the TLS socket.
Therefore, if there's a stampeding herd of outbound requests to Elasticsearch
we can end up in a situation where we try to create so many new TLS sockets at the same time that we end up getting TLS handshake timeouts.
In these situations, it can be beneficial to set maxSockets to a lower number,
so that we don't try to establish so many new TLS sockets and we do HTTP request queueing in Kibana.

If we expect that masxSockets: Inifinity might affect performance for a TLS connection,
maybe we can set a fixed limit for them?

agent: {
      maxSockets: config.ssl ? 512 : 1024

Copy link
Contributor Author

@kobelb kobelb Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I suggested making maxSockets configurable, we don't know the optimal setting here. The optimal setting here depends on at least the following:

  • long requests to Elasticsearch
  • bursty behavior
  • CPU speed
  • operating system settings

I don't think we should artificially cap this setting to just 512 or 1024.

keepAlive: config.keepAlive ?? true,
},
};

if (config.pingTimeout != null) {
Expand All @@ -73,11 +77,6 @@ export function parseClientOptions(
? config.sniffInterval
: getDurationAsMs(config.sniffInterval);
}
if (config.keepAlive) {
clientOptions.agent = {
keepAlive: config.keepAlive,
};
}

if (!scoped) {
if (config.username && config.password) {
Expand Down