英文:
How to increase performance for send message to AWS Queue
问题
我正在使用Spring Boot 2.2.0.RELEASE
,当我将数据发送到AmazonSqs时,会有300-500毫秒的延迟。也许是我做错了什么。我的代码如下所示:
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.
}
}
如何减少这种延迟?
英文:
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?
答案1
得分: 1
Amazon SQS队列可以提供非常高的吞吐量。如果您不使用FIFO队列,则消息数量没有限制。将消息从您的Spring Boot应用程序发送到SQS队列的延迟取决于诸如区域、网络带宽等其他因素。
如果您在印度的本地计算机上运行Spring Boot应用程序,而您的SQS队列区域位于欧洲,那么会存在一定的延迟。
为了提高性能,请尝试将Spring Boot应用程序部署在与您的SQS队列相同区域的EC2实例中。
您还可以尝试使用VPC终端节点连接到SQS队列,它将使用AWS私有网络发送消息,从而提供良好的性能。
我建议更好的方法是使用Lambda发送消息到SQS队列,这可以为您提供最大的性能。
还要验证您的SQS队列配置。检查设置的默认可见性超时、接收消息等待时间、传递延迟等值。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论