【问题标题】:Bad performance when filtering Azure logs - WCF Data Services filters筛选 Azure 日志时性能不佳 - WCF 数据服务筛选器
【发布时间】:2016-10-29 09:20:41
【问题描述】:

Azure 诊断正在将 Windows 事件推送到存储表“WADWindowsEventLogsTable”中。

我想使用 VisualStudio(2015) 和 CloudExplorer 查询这个存储表。

由于这张表的内容很大,我无限期地等待结果..

这是一个查询示例:

EventId eq 4096 and Timestamp gt datetime'2016-06-24T08:20:00' and Timestamp lt datetime'2016-06-24T10:00:00'

我想这个查询是正确的?

是否存在提高性能的方法?

  • 过滤结果列?
  • 只返回前 X 个结果?
  • 其他有用的提示?

我知道更好的方法是编写脚本;例如使用 Python,但我想尽可能多地使用 UI..


(编辑)跟随 Gaurav Mantri 回答我使用这个小 C# 程序来构建我的查询。答案很快,解决了我最初的性能问题:

   static void Main(string[] args)
    {
        string startDate = "24 June 2016 8:20:00 AM";
        string endDate   = "24 June 2016 10:00:00 AM";

        string startPKey = convertDateToPKey(startDate);
        string endPKey   = convertDateToPKey(endDate);
        Debug.WriteLine("(PartitionKey gt '" + startPKey + "'"
            + " and PartitionKey le '" + endPKey +"')"
            + " and (EventId eq 4096)"
            );
    }

    private static string convertDateToPKey(string myDate)
    {
        System.DateTime dt = System.Convert.ToDateTime(myDate);
        long dt2ticks = dt.Ticks;
        string ticks = System.Convert.ToString(dt2ticks);
        return "0" + ticks;
    }

注意:对于像我这样正在寻找如何将结果导出到 CSV 文件的人来说,您应该知道这个图标是您的答案(它不是“撤消”;)):

【问题讨论】:

    标签: wcf azure visual-studio-2015 azure-table-storage


    【解决方案1】:

    在您的查询中,您正在过滤未编入索引的 Timestamp 属性(仅编入索引的 PartitionKeyRowKey 属性)。因此,您的查询正在进行全表扫描(即从第一条记录到找到匹配记录的时间),因此未进行优化。

    为了避免全表扫描,请在查询中使用PartitionKey。在WADWindowsEventLogsTable 的情况下,PartitionKey 本质上表示以刻度为单位的日期/时间值。您需要做的是将要获取数据的日期/时间范围转换为刻度,在其前面添加 0,然后在查询中使用它。

    所以你的查询应该是这样的:

    (PartitionKey gt 'from date/time value in ticks prepended with 0' and PartitionKey le 'to date/time value in ticks prepended with 0') and (EventId eq 4096)
    

    我前段时间写了一篇关于它的博客文章,您可能会觉得有用:http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/

    【讨论】:

      猜你喜欢
      • 2011-08-09
      • 2013-06-02
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2018-01-14
      • 2018-04-02
      • 1970-01-01
      相关资源
      最近更新 更多