Open doingnz opened 1 year ago
You can increase the speed of the method to populate the dummy list by only calling GC.GetTotalMemory(true) once by putting the call outside the for loop, or not calling it.
private List<TemperatureTable> DummyList(int rows)
{
long totalMemory = GC.GetTotalMemory(true);
List <TemperatureTable> TempList = new List<TemperatureTable >();
for (int i = 0; i < rows; i++)
{
TemperatureTable dummy = new TemperatureTable() { ID = i, TemperatureCelcius = 30,
DateTime = DateTime.Now, TotalMemory = totalMemory };
TempList.Add(dummy);
}
return TempList;
}
As noted in the initial issue, you need to add property public long TotalMemory { get; set; }
to public class TemperatureTable
if returning the memory as a property (I added it to the Model saved to the database in the path that saves the temperature to have a record of the memory used at each save. However, as demonstrated by the HTTP GET endpoint that returns dummy data, the logging to SQLite and reading SQLIte don't contribute to the significant memory leak seen in Maple.
Note the dummy endpoint needs a parameter that set the number of records to return. e.g for 2000 records
http://192.168.2.112:5417/gettemperaturedummy/2000
Fetching 2000 records will work once. Some form of out of memory error will be raised on the next attempt... e.g.
Meadow StdOut: memalign returned null when requesting 1048576 bytes (1048576 alignment) -- out of memory?
Meadow StdOut: mono_os_mutex_trylock: pthread_mutex_trylock failed with "Error code '142'" (142)
Meadow will need to be restarted.
Requesting smaller number of returned records will let you do the request multiple times, till the memory is exhausted.
I think this needs to be re-tested on OS 1.6; preliminary tests have shown that we are much more reliable on Maple.
@halyssonJr we think this is fixed, can you validate, please?
I carried out a validation using the App provided by the user, however there was a problem with the allocation of 12k bytes and after that the application broke. I tested with OS v1.7.0.0
and v1.8.0.0
Meadow StdOut: Log level: Information
Meadow StdOut: Device is configured to use WiFi for the network interface
Meadow StdOut: Update Service is disabled.
Meadow StdOut: Health Metrics disabled.
Listening for Meadow Console output. Press Ctrl+C to exit
Meadow StdOut: MeadowApp: Connected to network: ip=192.168.4.37 port=5417
Meadow StdOut: SetClock(01/12/2024 10:02:29);
Meadow StdOut: Listening on http://192.168.4.37:5417/
Meadow StdOut: GET : /gettemperaturelogs --> GetTemperatureLogs
Meadow StdOut: GET : /gettemperaturepage/{page} --> GetTemperaturePage
Meadow StdOut: requestHandlers.Count: 1
Meadow StdOut: Starting up Maple HTTP Request listener.
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: Saving (26.0776556776556,01/12/2024 10:02:44)...
Meadow StdOut: SaveReading: Saving temperature reading to DB
Meadow StdOut: Could not allocate 12312 bytes
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::192.168.4.37, port: 17756
Meadow StdOut: Request received from 172.20.10.2:55458
Meadow StdOut: Received GET /gettemperaturepage/10 - Invoking gettemperaturepage
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: GetReadings: TotalCount=29 TotalPages=1 PageSize=50 CurrentPage=1
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: memalign returned null when requesting 65536 bytes (4096 alignme
Meadow StdOut: nt) -- out of memory?
Meadow StdOut: mono_os_mutex_trylock: pthread_mutex_trylock failed with "Error
Meadow StdOut: code '142'" (142)
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: mono_os_mutex_trylock: pthread_mutex_trylock failed with "Error
Meadow StdOut: code '142'" (142)
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Meadow StdOut: UDP Broadcast: Meadow::172.20.10.3, port: 17756
Gonna retest after several fixes in the queue land, think that this may be fixed with them.
The team is doing a lot of work optimizing memory usage - will retest and verify this issue soon
@halyssonJr I would like you to re-test this when you get the chance, please!
Describe the bug Application returns list of JSON serializable objects to Maple to send to HTTP client in response to HTTP GET results in a memory leak.
To Reproduce Steps to reproduce the behavior:
Add following methods to MeadowApp.cs to aid uniform data output
Add Console.WriteLine to GetTemperatureLogs() method to call above methods and output memory used.
Add additional end point that returns data without calling SQLite
Add similar console lines to the SaveReading method in DatabaseManager.cs to confirm no memory leak during saving
Expected behavior Total allocated Memory should not increase with each call to either endpoint. Note that the objects in the list returned to Maple would only be released after the data is serialised.
Screenshots Confirm that saving data to SQLite does not leak memory by checking does not increase at "done!" In this example the memory is +/- 1183864 (small variation ok)
Do HTTP Get to dummy end point that does not call SQLite to confirm the memory leak is in Maple and not the memory allocated at the "DTO" line and then at subsequent saves
Note at the next save and other saves that follow, some of the memory is released, but not all as total memory returns to +/- 1285256 and not near the original 1183864 above.
Doing additional HTTP GET will step up the allocated memory
and the additional memory is not released, even if the app runs for "long" time.
Developer tools (please complete the following information as best as you can):
Meadow (please complete the following information as best as you can): Connecting to Meadow on COM6 Meadow by Wilderness Labs Board Information Model: F7Micro Hardware version: F7FeatherV2 Device name: MeadowF7
Hardware Information Processor type: STM32F777IIK6 ID: 22-00-26-00-11-51-36-30-33-33-37-33 Serial number: 335D335F3036 Coprocessor type: ESP32 MAC Address - WiFi: 94:B9:7E:91:F4:0C
Firmware Versions OS: 0.9.4.0 Mono: 0.9.4.0 Coprocessor: 0.9.4.0
Done!
Additional context Uses Clima Hack Kit sample application as base.