简体   繁体   中英

How to increase performance for send message to AWS Queue

I'm using Spring boot 2.2.0.RELEASE and when I send data to AmazonSqs I have delay 300-500ms. Maybe I do something wrong. My code looks like the following:

public class MySender {
    private final QueueMessagingTemplate queueMessagingTemplate;
    private AmazonSQSAsync amazonSqsAsync;

    public MySender(AmazonSQSAsync amazonSqsAsync) {
        this.amazonSqsAsync = amazonSqsAsync;
        this.queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs);
    }

    public void send(String queue, String msg) {
        ...
        Message<String> message = MessageBuilder.withPayload(msg)
                                                .setHeader("MyHeader", "val");
        long startSending = System.currentTimeMillis();
        queueMessagingTemplate.send(queue, message);
        System.out.println("Sending time: " + (System.currentTimeMillis() - startSending));
        // and this I get sending message time 300 - 500ms.
    }
}

How can I reduce this delay?

Amazon SQS queues can deliver very high throughput. If you are not using FIFO queue, then there is no limit for number of messages. The delay in sending messages to SQS queue from your spring boot application depends on number of other factors like region, network bandwidth

If you are running your spring boot application in your local machine in India and your SQS queue region is in Europe for example, then there will be a latency.

To improve performance, try deploying your spring boot application in EC2 instance in the same region of your SQS queue.

You can also try using vpc endpoint to connect to SQS queue which will use aws private network to send messages and it will give you good performance

I would suggest the better way to use lambda to send message to SQS queue which can give you maximum performance.

Also validate the configuration of your SQS queue.Check the values set for Default visibility timeout, Receive message wait time, Delivery delay

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM