Skip to content

Commit f3d049a

Browse files
authored
Merge pull request #109517 from bwren/am-query-optimize
Azure Monitor query optimization update
2 parents 037a872 + 5e55054 commit f3d049a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

articles/azure-monitor/log-query/query-optimization.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.subservice: logs
55
ms.topic: conceptual
66
author: bwren
77
ms.author: bwren
8-
ms.date: 02/28/2019
8+
ms.date: 03/30/2019
99

1010
---
1111

@@ -152,6 +152,21 @@ Heartbeat
152152
> [!NOTE]
153153
> This indicator presents only CPU from the immediate cluster. In multi-region query, it would represent only one of the regions. In multi-workspace query, it might not include all workspaces.
154154
155+
### Avoid full XML and JSON parsing when string parsing works
156+
Full parsing of an XML or JSON object may consume high CPU and memory resources. In many cases, when only one or two parameters are needed and the XML or JSON objects are simple, it is easier to parse them as strings using the [parse operator](/azure/kusto/query/parseoperator) or other [text parsing techniques](/azure/azure-monitor/log-query/parse-text). The performance boost will be more significant as the number of records in the XML or JSON object increases. It is essential when the number of records reaches tens of millions.
157+
158+
For example, the following query will return exactly the same results as the queries above without performing full XML parsing. Note that it makes some assumptions on the XML file structure such as that FilePath element comes after FileHash and none of them has attributes.
159+
160+
```Kusto
161+
//even more efficient
162+
SecurityEvent
163+
| where EventID == 8002 //Only this event have FileHash
164+
| where EventData !has "%SYSTEM32" //Early removal of unwanted records
165+
| parse EventData with * "<FilePath>" FilePath "</FilePath>" * "<FileHash>" FileHash "</FileHash>" *
166+
| summarize count() by FileHash, FilePath
167+
| where FileHash != "" // No need to filter out %SYSTEM32 here as it was removed before
168+
```
169+
155170

156171
## Data used for processed query
157172

0 commit comments

Comments
 (0)