简体   繁体   English

使用ASP.NET使用Azure Tables进行实时数据存储

[英]Real time data storage with Azure Tables using ASP.NET

I am using a Lab View application to simulate a test running, which would post a JSON string to my ASP.NET application. 我正在使用Lab View应用程序来模拟测试运行,该测试会将JSON字符串发布到我的ASP.NET应用程序中。 Within the ASP.NET application I format the data with the proper partition and row keys, then send it to Azure Table Storage. 在ASP.NET应用程序中,我使用适当的分区和行键来格式化数据,然后将其发送到Azure表存储。

The problem that I am having is that after what seems like a random amount of time (ie 5 minutes, 2 hours, 5 hours), the data fails to be saved into Azure. 我遇到的问题是,在经过一段随机的时间(即5分钟,2小时,5小时)之后,数据无法保存到Azure中。 I am try to catch any exceptions within the ASP.NET application and send the error message back to the Lab View app and the Lab View app is also catching any exceptions in may encounter so I can trouble shoot where the issue is occurring. 我试图在ASP.NET应用程序中捕获任何异常,然后将错误消息发送回Lab View应用程序,并且Lab View应用程序还捕获了可能遇到的任何异常,因此我可以在发生问题的地方进行故障排除。

The only error that I am able to catch is a Timeout Error 56 in the Lab View program. 我能够捕获的唯一错误是Lab View程序中的超时错误56 My question is, does anyone have an idea of where I should be looking for the root cause of this? 我的问题是,是否有人知道我应该在哪里寻找此问题的根本原因? I do not know where to begin. 我不知道从哪里开始。

EDIT: 编辑:

I am using a table storage writer that I found here to do batch operations with retries. 我正在使用一个表存储写入器,在这里找到它可以进行重试的批处理操作。

You need to check whether an exception is transient or not. 您需要检查异常是否是暂时的。 As Peter said on his comment, Azure Storage client already implements a retry policy. 正如Peter在评论中所说,Azure存储客户端已经实现了重试策略。 You can also wrap your code with another retry code (eg using polly) or you should change the default policy associated to Azure Storage Client. 您还可以使用其他重试代码包装代码(例如,使用polly),或者应更改与Azure存储客户端关联的默认策略。

The constructor for exponential retry policy is below: 指数重试策略的构造函数如下:

public ExponentialRetry(TimeSpan deltaBackoff, int maxAttempts)

when you (or the library you use to be exact) instantiate this as RetryPolicy = new ExponentialRetry(TimeSpan.FromMilliseconds(2),100) you are basically setting the max attempts as 100 which means you may end up waiting up to around 2^100 milliseconds (there is some more math behind this but just simplifying) for each of your individual batch requests to fail on the client side until the sdk gives up retrying. 当您(或您使用的确切库)将其实例化为RetryPolicy = new ExponentialRetry(TimeSpan.FromMilliseconds(2),100)时,基本上将最大尝试次数设置为100,这意味着您可能最终要等待大约2 ^对于每个单独的批处理请求,每个100毫秒(这背后还有一些数学运算,但只是简化了)在客户端失败,直到sdk放弃重试。

The other issue with that code is it executes batch requests sequentially and synchronously, that has multiple bad effects, first, all subsequent batch requests are blocked by the current batch request, second your cores are blocked waiting on I/O operations, third it has no exception handling so if one of the batch operations throw an exception, the method bails out and would not continue any further processing other batch requests. 该代码的另一个问题是,它顺序且同步地执行批处理请求,这具有多个不良影响,首先,所有后续批处理请求均被当前的批处理请求阻止,其次,您的内核被阻止等待I / O操作,第三,它具有没有异常处理,因此,如果批处理操作之一引发异常,则该方法将失败,并且不会继续任何其他批处理请求的进一步处理。

My recommendation, do not use that library, batch operations are fairly straight forward. 我的建议是,不要使用该库,批处理操作相当简单。 The default retry policy if you do not explicitly define is the exponential retry policy anyways with sensible default parameters (does 3 retries) so you do not even need to define your own retry object. 如果未明确定义,则默认重试策略始终是具有合理默认参数的指数重试策略(执行3次重试),因此您甚至不需要定义自己的重试对象。 For best scalability and throughput run your batch operations async (and concurrently). 为了获得最佳的可伸缩性和吞吐量,请异步(并发)运行批处理操作。

As to why things fail, when you write your own api, catch the StorageException and check the http status code on the exception itself. 至于失败的原因,当您编写自己的api时,请捕获StorageException并检查异常本身的http状态代码。 You could be getting throttled by azure as one of the possibilities but it is hard to say without further debugging or you providing the http status code for the failed batch operations to us. 作为一种可能,您可能会被蔚蓝扼制住,但是如果不进行进一步调试,或者将失败的批处理操作的http状态代码提供给我们,很难说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM