Azure 表存储重试策略问题
关于将 RetryPolicy 与表存储一起使用的几个问题,
是否最好的做法是尽可能使用 RetryPolicy,因此尽可能使用 ctx.SaveChangeWithRetries() 而不是 ctx.SaveChanges()?
例如,当您使用 RetryPolicy 时,
ctx.RetryPolicy = RetryPolicies.Retry(5, TimeSpan.FromSeconds(1));
人们通常对 retryCount 和 TimeSpan 使用什么值?我看到 5 次重试和 1 秒 TimeSpan 是一个流行的选择,但是 5 次重试,每次 1 秒会不会太长?
谢谢你,
雷。
A couple questions on using RetryPolicy with Table Storage,
Is it best practice to use RetryPolicy whenever you can, hence use ctx.SaveChangeWithRetries() instead of ctx.SaveChanges() accordingly whenever you can?
When you do use RetryPolicy, for example,
ctx.RetryPolicy = RetryPolicies.Retry(5, TimeSpan.FromSeconds(1));
What values do people normally use for the retryCount and the TimeSpan? I see 5 retries and 1 second TimeSpan are a popular choice, but would 5 retries 1 second each be too long?
Thank you,
Ray.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这很大程度上取决于您的应用和要求。 ATS 的超时错误很少发生,因此如果重试策略到位不会有什么坏处,并且无论如何都很少使用。但如果发生了可疑的事情,它可能会让您免于调试奇怪的错误。
现在,我建议您一开始就完全不要启用 RetryPolicy,而是进行跟踪,以便您可以看到 ATS 持久性的任何问题。一旦稳定下来,设置 RetryPolicy 可能是解决 ATS 端的一些运行时故障的好主意。只要确保您没有用 RetryPolicy 掩盖自己的问题即可。
I think this is highly dependent on your application and requirements. The timeout errors to ATS happen so rarely that if a retry policy will not hurt to have in place and would be rarely utilized anyway. But if something fishy is happening, it may save yourself from having to debug weird errors.
Now, I would suggest that in the beginning you do not enable the RetryPolicy at all and have tracing instead so that you can see any issues with persistence to ATS. Once you're stabilized, putting a RetryPolicy maybe good idea to work around some runtime glitches on the ATS side. Just make sure you're not masking your own problems with RetryPolicy.
如果您的客户端像网页一样面向用户,您可能希望使用线性重试,每次重试之间等待时间较短(毫秒),如果您的客户端实际上是非面向用户的后端服务等,那么您很可能想要使用指数重试,以免表存储服务过载,以防表存储服务由于高负载而已经给出 5xx 错误。
使用最新的 Azure 存储客户端 SDK,如果未通过 TableRequestOptions 在表请求中定义任何重试策略,则使用默认重试策略,即指数重试。 sdk 总共会重试 3 次它认为可重试的错误,如果所有重试都失败,则总共需要大约 20 秒。
If your client is user facing like a web page you would probably like to use a linear retry with short waits (milliseconds) in between each retry, if your client is actually a non user facing backend service etc. then you would most likely want to use Exponential retries in order not to overload the table storage service in case it is already giving 5xx errors due to high load for instance.
Using the latest Azure Storage client SDK, if you do not define any retry policy in your table requests via the TableRequestOptions, then the default retry policy is used which is the Exponential retry. The sdk makes 3 retries in total for the errors that it deems retriable and this in total takes more or less 20 seconds if all retries fail.