我有一个 AWS 应用程序,它从几个不同的 AMI 启动和终止许多 EC2 实例。
我开始通过 ruby api 收到此错误,超出请求限制。我相信大多数帐户的限制约为每小时 2,000 个。但在查看了我知道要检查的所有日志后,我找不到任何接近如此高的使用率的证据。
有没有办法从 Amazon 获取我正在执行的 EC2 API 查询的统计信息?
是否有任何其他技巧或好方法来确定我的过度使用,或者导致错误的原因?
I have an AWS app which starts up and terminates many EC2 instances from a few different AMI's.
I'm beginning to get this error, via the ruby api, Request limit exceeded. The limit is around 2,000 per hour for most accounts I believe. But I can't find any evidence of our usage that's anywhere near this high, after looking through all the logs I know to check.
Is there a way to get an accounting from Amazon of what EC2 API queries I'm making?
Are there any other tricks or good ways to nail down my excessive use, or what's causing the error?
发布评论
评论(1)
您可以通过 AWS.config 启用 aws-sdk gem 的日志记录。只需传入 ruby Logger 的实例即可。
您可能会遇到这样的情况:运行 n+1 查询以从 EC2 资源获取属性。下面是一个示例:
执行 1 个请求来获取每个实例的 id,然后每个实例执行 1 个请求来获取其状态。您可以通过在 memoize 块内运行代码来改进这一点:
您还可以使用 AWS.start_memoizing(和 AWS.stop_memoizing)来包围更大的代码区域。我强烈建议阅读这篇关于集合在 aws-sdk 中如何工作的博客文章:http://aws.typepad.com/aws/2012/01/how-collections-work-in-the-aws-sdk-for-ruby.html
You can enable logging for the aws-sdk gem via AWS.config. Just pass in an instance of a ruby Logger.
You are likely running into a situation where it is running n+1 queries to fetch attributes from your EC2 resources. Here is an example:
1 request is performed to fetch the ids of each instances and then 1 request is performed per instance to get its status. You can improve this by running your code inside a memoize block:
You can also use AWS.start_memoizing (and AWS.stop_memoizing) to surround larger areas of code. I stronly suggest reading this blog article about how collections work in the aws-sdk: http://aws.typepad.com/aws/2012/01/how-collections-work-in-the-aws-sdk-for-ruby.html