ApplicationInsights-dotnet
ApplicationInsights-dotnet copied to clipboard
Improve channel performance by serializing telemetry directly to stream to be used in Transmission
The JsonSerializer used to serialize Telemetry currently uses a MemoryStream to write serialized data to. This is then converted to a byte[], and stored inside Transmission. https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Microsoft.ApplicationInsights/Extensibility/Implementation/JsonSerializer.cs#L64
This byte[] is then converted again to a new MemoryStream, for writing to network. https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Microsoft.ApplicationInsights/Channel/Transmission.cs#L165
Proposing to avoid this conversions back and forth - modify JsonSerializer to write to just a MemoryStream and modify Transmission to use the same stream to write to network. This should avoid unwanted memory allocations/GC etc and boost performance.
@cijothomas , based on the milestones mentioned above, can we assume that v2.14 already fixes that? Thanks
The milestone for this is "Future", means this is not done.
This also leads to GC pressure when used in server applications. We are currently going through a process of optimising memory allocations to reduces numbers of GCs and are now at the point that all our own memory allocations are dwarfed by Application Insights allocations. Some screen shots from JetBrains dotMemory. This is after just logging like 1000 events.
System.Byte[] allocations:

System.Char[] allocations:

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.
Looks like links are broken, but the usage of MemoryStream is still there. https://github.com/microsoft/ApplicationInsights-dotnet/blob/19a3ecf77bebd7bbcffb6ca553b920016a412ed4/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/JsonSerializer.cs#L53
https://github.com/microsoft/ApplicationInsights-dotnet/blob/19a3ecf77bebd7bbcffb6ca553b920016a412ed4/BASE/src/Microsoft.ApplicationInsights/Channel/Transmission.cs#L175
Should I try to fix this ?
This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.