aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.06k stars 573 forks source link

SQS has become much slower #5938

Closed zryenz5w closed 6 months ago

zryenz5w commented 6 months ago

Checkboxes for prior research

Describe the bug

The SQS service has become slower in the recent releases. Maybe since v3.507.0 because of the middleware-sdk-sqs update.

This is a breaking change for us, we ran in multiple Lambda timeouts because of this.

The middleware-sdk-sqs update also causes a new warning because we use the queueName instead of the queueUrl:

2024-03-20T12:36:21.945Z    868dee7b-147c-415b-9a7d-1bc86d2f9b04    WARN    TypeError [ERR_INVALID_URL]: Invalid URL
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at new NodeError (node:internal/errors:405:5)
    at new URL (node:internal/url:676:13)
    at /var/runtime/node_modules/@aws-sdk/middleware-sdk-sqs/dist-cjs/index.js:56:28
    at /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js:199:12
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /var/runtime/node_modules/@aws-sdk/middleware-sdk-sqs/dist-cjs/index.js:127:16
    at async /var/runtime/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
    ...
}

When switching from queueName to queueUrl the warning disappears and it is still working like before; but the performance issue remains.

SDK version number

@aws-sdk/client-sqs@^3.507.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node 18

Reproduction Steps

We have a class function that logs before and after the send command:

import { SendMessageCommand, SendMessageCommandInput, SQSClient } from '@aws-sdk/client-sqs';
// ...
private readonly _sqsClient = new SQSClient({});
// ...
async sendEmail(emailSendRequest: EmailSendRequest): Promise<void> {
    logger.info(`Received email send request ${emailSendRequest.subject}`);
    const input: SendMessageCommandInput = {
      QueueUrl: this._sendEmailQueueUrl,
      MessageBody: JSON.stringify(emailSendRequest),
    };

    const output = await this._sqsClient.send(new SendMessageCommand(input));

    logger.info(
      `Published email send request ${emailSendRequest.subject} to topic (message id is ${output.MessageId}).`
    );
  }

Observed Behavior

220 ms for the send command: image

559 ms for the send command: image

Note: the log between these info logs is the TypeError warning described above

Expected Behavior

Setting the sdk version back to v3.504.0 and it seems to work as expected.

11 ms for the send command: image

image

Possible Solution

No response

Additional Information/Context

No response

kuhe commented 6 months ago

Try setting useQueueUrlAsEndpoint=false on the client. It will be possible to use just the queue name in the QueueUrl field, but I recommend using the full URL.

new SQSClient({
  useQueueUrlAsEndpoint: false,
});

We had to add the check and warning because of confusion caused by potential conflict between the endpoint that can be set on the client, and the host URL of the QueueUrl field itself. useQueueUrlAsEndpoint: false avoids the check.

It shouldn't take 500 ms to parse a URL and compare its string value, so I think there's also the variable of AWS Lambda cold vs warm invocation potentially involved here.

zryenz5w commented 6 months ago

Thanks, setting useQueueUrlAsEndpoint: false seems to help if we continue using queueName. I also tested queueUrl again without this setting and it seems to end up with similar times.

Only the case queueName without useQueueUrlAsEndpoint: false leads to the TypeError and slows the request down. Maybe considering setting useQueueUrlAsEndpoint to true by default (for now) to avoid the breaking change for other users that still uses the queueName.

github-actions[bot] commented 5 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.