调用ExecuteQuerySegmented时获取下载速度

时间:2017-04-21 06:03:15

标签: c# azure azure-table-storage azure-tablequery

我知道ExecuteQuerySegmented针对Azure表存储运行查询。我想知道在调用ExecuteQuerySegmented时如何输出下载速度?类似的东西:

    var queryResult = table.ExecuteQuerySegmented(new TableQuery<TModel>(), token); 

//a decimal or double value below this line to get the download speed after the call to ExecuteQuerySegmented is executed.

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

据我所知,我们无法直接获得ExecuteQuerySegmented的下载速度。

这是一种解决方法,我们可以获得ExecuteQuerySegmented的平均下载速度。

我们可以使用&#34; System.Diagnostics.Stopwatch&#34; class获取table.ExecuteQuerySegmented方法的执行时间并使用&#34; System.Text.Encoding.Unicode.GetByteCount(由于使用json格式生成结果的azure存储的响应)以获得结果&#39; s &#34; table.ExecuteQuerySegmented&#34;。

的大小

最后,我们可以使用字节/秒来计算速度。

更多细节,您可以参考以下代码:

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
             "yourstorageaccount");

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Retrieve a reference to the table.
        CloudTable table = tableClient.GetTableReference("tablename");


        string filter = TableQuery.GenerateFilterCondition(
    "PartitionKey", QueryComparisons.Equal, "Aut");

        TableContinuationToken continuationToken = null;
        TableQuery<BookTest3> query = new TableQuery<BookTest3>().Where(filter);

        var watch = System.Diagnostics.Stopwatch.StartNew();
        var queryResult = table.ExecuteQuerySegmented(query, continuationToken).Results;
        watch.Stop();
        //get the execute time
        float seconds = watch.ElapsedMilliseconds/ 1000;
       //Serialize the object
       string s = JsonConvert.SerializeObject(queryResult);
       //get bytes
        float re =   System.Text.Encoding.Unicode.GetByteCount(s)/1000;
        Console.WriteLine(re/seconds);
        Console.Read();