如何使用AWS SQS减少连接延迟? [英] How to reduce connection latency with AWS SQS?

查看:306
本文介绍了如何使用AWS SQS减少连接延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AWS开发工具包连接到AWS SQS时,似乎会出现明显的延迟.

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

启动服务以消费消息时并不重要,因为在第一次连接延迟3-7秒之后,消息开始以良好的速度流动-

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 -

但是,发布消息时这是一个大问题.例如,由于与AWS的连接正在等待发布消息,因此用户Web请求需要花费几秒钟的时间才能完成.这无法达到发送消息以延迟后台作业等待时间的目的.

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.

这是DNS修复的问题吗?联网?还是AWS SQS设置?我的Web应用程序不在AWS网络中,不确定这是否是一个问题.

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.

简单地发布消息代码:

$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)
 ]);

推荐答案

SQS在使用过程中显示出非常低的延迟.但是,我们的逻辑在EC2实例上运行.

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

您的服务器和SQS之间很可能存在大量延迟.在物理上更靠近服务器的区域中使用SQS,或者将应用程序的逻辑转移到EC2或Lambda上.

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.

这篇关于如何使用AWS SQS减少连接延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆