重复受限制的 DynamoDB 请求

2024-05-10php开发问题
6

本文介绍了重复受限制的 DynamoDB 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用适用于 PHP 的 AWS 开发工具包以编程方式与 DynamoDB 交互.

I am using the AWS SDK for PHP to interact programmatically with DynamoDB.

我想检测对 DynamoDB 的请求是否受到限制,以便在短暂延迟后发出另一个请求.

I would like to detect if a request to DynamoDB has been throttled so another request can be made after a short delay.

现在,我在假设未满足受限制的请求的情况下进行操作.亚马逊常见问题解答 建议在发生限流时返回 400 错误.

Right now, I am operating under the assumption that throttled requests are not fulfilled. Amazon FAQs suggest that a 400 error is returned when throttling occurs.

所以我目前的逻辑看起来像这样:

So I currently have logic that looks something like this:

for( $i=0; $i<10; $i++ ) {

    $response = $dynamodb->get_item($get_item_args);

    if( $response->isOK() ) {

        break;

    } elseif( $i < 9 ) {

        sleep(1);
    }
}

我想这可行,但它是一个 bit 愚蠢.特别是,它将重复所有失败的请求,而不仅仅是受限制的请求.如果出现不可解决的错误,我真的不想重复请求.

I suppose this works, but it is a bit dumb. In particular, it will repeat all failed requests, not just throttled requests. If there is a non-resolvable error, I really don't want to repeat the request.

为了更智能,我想在一个受限制的响应中查看唯一标识符(即特定错误消息).但就我的一生而言,我无法捕获(或在 Internet 上的任何地方找到)样本限制响应.

To make this smarter, I'd like to look inside a throttled response for a unique identifier (i.e. a specific error message). But for the life of me, I can't capture (or find anywhere on the internet) a sample throttled response.

补偿限制风险和最大限度提高满足请求的可能性的最佳方法是什么?

What is the best way to compensate for the risk of throttling and maximize the likelihood of a fulfilled request?

推荐答案

事实证明,AWS SDK 会自动重试受限制的请求,直到成功.所以我上面的努力是不必要的(因为我使用的是 AWS SDK for PHP).

It turns out, the AWS SDKs will automatically retry throttled requests until success. So my efforts above are unneeded (since I am using the AWS SDK for PHP).

处理 Amazon DynamoDB 中的错误 文档页面对 ProvisionedThroughputExceededException 错误说如下:

The Handling Errors in Amazon DynamoDB documentation page says the following for the ProvisionedThroughputExceededException error:

适用于 Amazon DynamoDB 的 AWS 开发工具包自动重试请求收到此异常.所以,你的请求最终成功了,除非请求太大或您的重试队列太大而无法完成.

The AWS SDKs for Amazon DynamoDB automatically retry requests that receive this exception. So, your request is eventually successful, unless the request is too large or your retry queue is too large to finish.

这篇关于重复受限制的 DynamoDB 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17