smorhaim
smorhaim

Reputation: 798

How to reduce connection latency with AWS SQS?

When connecting to AWS SQS using AWS SDK, there seems to be a noticeable delay.

It is not so important when starting up a service to consume messages since after a 3-7 second delay on the first connection, the messages start flowing at a good speed -

BUT, when publishing messages it is a big problem. For example a user web request takes a few extra seconds to complete because of the connection to AWS is waiting to publish the message. This defeats the purpose of sending a message out in order to defer the wait time to a background job.

Is this a problem fixed with DNS? Networking? Or is it an AWS SQS setting? My web app is not in AWS network not sure if thats an issue.

Simple publishing a message code:

$aws = \Aws\Common\Aws::factory(/* array with connection settings */);
$client = $aws->get('Sqs');
$queue = $client->getQueueUrl(['QueueName' => $queue]);

// This takes 3 - 5 seconds every time its called.
$res = $this->client->sendMessage([
    'QueueUrl' => $queue['QueueUrl'],
    'MessageBody' => json_encode($request)
 ]);

Upvotes: 2

Views: 4768

Answers (3)

Surya Prakash Patel
Surya Prakash Patel

Reputation: 731

With the introduction of VPC Endpoints for SQS service, you can cut down the latency problems and anything related to connectivity as AWS internally uses AWS PrivateLink or simply saying AWS Internal network backbone to establish connectivity and data transfer between instance in your VPC and SQS than using traditional internet. It is also easy to set up and not a disruptive change as it just resolves the DNS name of SQS endpoint like sqs.eu-central-1.amazonaws.com to private IP. In case, if some issue with private link due to a configuration change or any other, then AWS automatically resolves to usual public IP (which uses the internet)

you can find more details here : AWS SQS service endpoint

Upvotes: 1

A. Sharma
A. Sharma

Reputation: 56

One trick that has helped me in reducing the latency in SQS is to use the Queue URL directly instead of building it from the API. Also using http instead of https would significantly bring down the latency. For me it was nearly a 20 ms impact .

Of course you might tradeoff between security and portability but if performance is a concern than this might help.

Upvotes: 1

0x90
0x90

Reputation: 6259

SQS has shown very low latency during our usage. However, our logic runs on EC2 instances.

Most likely, there is significant latency between your servers and SQS. Either use SQS in a region physically closer to your servers or move your application's logic onto EC2 or Lambda.

I'd recommend writing a simple test application before you do a migration to rule out issues in your business logic.

Upvotes: 3

Related Questions