This question might be related to another question I asked some time ago. However, the situation is now a bit different.
I'm currently developing an Android app with Xamarin that communicates via a Wi-Fi connection with some custom hardware containing a sensor. The job of my app is to retrieve the sensor data from the hardware and store it on the phone without displaying it (thus there is no rendering taking place). I would like to receive a continuous stream of data with equidistant temporal distances between all measurements. Unfortunately, this is not the case as the following graph, depicting the time it took to retrieve a measurement after another in milliseconds, clearly shows:
My initial guess was that those peaks (ranging up to 2500 ms) correlate with the garbage collection cycles and thus decided to experiment a bit. I tried the following combinations concerning the memory heap and GC algorithms so far:
- bridge implementation = tarjan; nursery size=256mb; soft heap limit=512mb
- bridge implementation = old; nursery size=256mb; soft heap limit=512mb
- bridge implementation = new; nursery size=256mb; soft heap limit=512mb
All combinations of those parameters lead to similar results. Concurrent GC is enabled. Do you have any further ideas what could cause those temporal peaks?
Update 1
The code I'm using still looks similar to the code I used in my previous question:
[...]
int timeout = 1000;
while (ShootContinuously) {
FrameCounter++;
CancellationToken cancellationToken = new CancellationToken();
var task = GetDataAndUpdateUIForContinuousShootingAsync(MyDisplayPlot, FrameCounter, StartTime, mainPage);
if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) == task) {
// Task completed within timeout.
// Consider that the task may have faulted or been canceled.
// We re-await the task so that any exceptions/cancellation is rethrown.
await task;
} else { // timeout/cancellation logic
Debug.WriteLine("Task is taking too long!");
await Client.DisconnectAndStopReadTaskAsync();
Client = null;
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
GC.WaitForPendingFinalizers();
Client = new MyClientSocket();
await Client.ConnectAndStartReadTaskAsync();
continue;
}
}
await Client.DisconnectAndStopReadTaskAsync();
The only difference is that I don't perform any UI updates any more.
Update 2
I sometimes see the following output:
> 04-10 18:17:12.501 D/Mono ( 8751): AOT: image 'System.IO.dll.so'
> not found: dlopen failed: library not found
> 04-10 18:17:12.503 D/Mono ( 8751): AOT: image
> '/Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/sdks/out/android-armeabi-v7a-release/lib/mono/aot-cache/arm/System.IO.dll.so'
> not found: dlopen failed: library not found
> 04-10 18:17:12.503 D/Mono ( 8751): Config attempting to
> parse: 'System.IO.dll.config'. 04-10 18:17:12.503 D/Mono ( 8751):
> Config attempting to parse:
> '/Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/sdks/out/android-armeabi-v7a-release/etc/mono/assemblies/System.IO/System.IO.config'.Loaded
> assembly: System.IO.dll [External]
Could this be related to my problem?