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

Use Connection: keep-alive to improve application performance #2571

Open
milancermak opened this Issue Mar 8, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@milancermak
Copy link

milancermak commented Mar 8, 2019

By default, NodeJS sets Connection: close and not Connection: keep-alive HTTP header which results in sub-optimal performance. Instead of reusing an already established connection between the client and the service, a new one has to be created for every operation.

It has been reported before (#146), recently publicized by an AWS Serverless Hero and it's also recommended by AWS for DynamoDB when using encryption at rest. DynamoDB itself responds with a Connection: keep-alive header.

Even though all these examples pertain to DynamoDB, I imagine other services will benefit from this change as well. For what it's worth, boto3, the official AWS SDK for Python does not explicitly set a Connection: close header.

Please consider setting keep-alive header the on the SDK level so that going forward, the whole community can benefit from this improvement.

@srchase

This comment has been minimized.

Copy link
Contributor

srchase commented Mar 19, 2019

Changing the default behavior here could introduce issues for existing users of the SDK. If this were enabled by default, it would require a major version bump.

It is possible to enable keep-alive through configuration.

That can be done on the global config:

const AWS = require('aws-sdk')
const https = require('https');
const agent = new https.Agent({
  keepAlive: true
})

AWS.config.update({
  httpOptions: {
    agent: agent
  }
})

Or on a per-client basis:

const AWS = require('aws-sdk')
const https = require('https');
const agent = new https.Agent({
  keepAlive: true
});

const DDB = new AWS.DynamoDB({
  httpOptions: {
    agent: agent
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.