筛选 Azure 日志时性能不佳 - WCF 数据服务筛选器
Bad performance when filtering Azure logs - WCF Data Services filters
Azure 诊断正在将 Windows 事件推送到存储 table "WADWindowsEventLogsTable"。
我想使用 VisualStudio(2015) 和 CloudExplorer.
查询此存储 Table
因为这个table内容很丰富,我一直在等待结果..
这是一个查询示例:
EventId eq 4096 and Timestamp gt datetime'2016-06-24T08:20:00' and Timestamp lt datetime'2016-06-24T10:00:00'
我想这个查询是正确的?
是否存在提高性能的方法?
- 过滤结果列 ?
- return 只有 TOP 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 文件的人,您应该知道这个图标就是您的答案(它不是 'undo' ;)) :
在您的查询中,您正在过滤未编入索引的 Timestamp
属性(仅编入索引 PartitionKey
和 RowKey
属性)。因此,您的查询正在进行完整的 table 扫描(即从第一条记录到找到匹配记录的时间),因此未进行优化。
为了避免完全 table 扫描,请在您的查询中使用 PartitionKey
。在 WADWindowsEventLogsTable
的情况下,PartitionKey
本质上代表 date/time 值(单位为刻度)。您需要做的是将要获取数据的 date/time 范围转换为刻度,在其前面添加一个 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)
我前段时间写了一篇关于它的博客post,你可能会觉得有用:http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/
Azure 诊断正在将 Windows 事件推送到存储 table "WADWindowsEventLogsTable"。
我想使用 VisualStudio(2015) 和 CloudExplorer.
查询此存储 Table因为这个table内容很丰富,我一直在等待结果..
这是一个查询示例:
EventId eq 4096 and Timestamp gt datetime'2016-06-24T08:20:00' and Timestamp lt datetime'2016-06-24T10:00:00'
我想这个查询是正确的?
是否存在提高性能的方法?
- 过滤结果列 ?
- return 只有 TOP 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 文件的人,您应该知道这个图标就是您的答案(它不是 'undo' ;)) :
在您的查询中,您正在过滤未编入索引的 Timestamp
属性(仅编入索引 PartitionKey
和 RowKey
属性)。因此,您的查询正在进行完整的 table 扫描(即从第一条记录到找到匹配记录的时间),因此未进行优化。
为了避免完全 table 扫描,请在您的查询中使用 PartitionKey
。在 WADWindowsEventLogsTable
的情况下,PartitionKey
本质上代表 date/time 值(单位为刻度)。您需要做的是将要获取数据的 date/time 范围转换为刻度,在其前面添加一个 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)
我前段时间写了一篇关于它的博客post,你可能会觉得有用:http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/