Skip to content

feat_: implement low memory mode with garbage collection logging #6549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

qfrank
Copy link
Contributor

@qfrank qfrank commented Apr 23, 2025

logging output example:

2025-04-23T10:28:34.419Z	INFO	mobile/status.go:2473	Before garbage collection	{"heap_alloc_mb": 37, "heap_objects": 303490, "sys_mb": 143}
2025-04-23T10:28:34.452Z	INFO	mobile/status.go:2486	After garbage collection	{"heap_alloc_mb": 31, "heap_objects": 237563, "sys_mb": 143, "freed_mb": 5, "objects_freed": 65927, "released_mb": 45}

close relate issue 6547

relate mobile PR

@qfrank qfrank self-assigned this Apr 23, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a low memory mode by invoking garbage collection and logging pre‑ and post‑GC memory statistics.

  • Introduces a thread-safe mechanism to throttle GC execution to once every 30 seconds.
  • Adds functions SwitchToLowMemoryMode and gc to encapsulate the GC trigger and logging logic.
Comments suppressed due to low confidence (2)

mobile/status.go:2460

  • [nitpick] The function name 'gc' might be confused with the standard library function runtime.GC. Consider renaming it to a more descriptive name like 'runGarbageCollection' to avoid ambiguity.
gc()

mobile/status.go:2492

  • The calculation for 'released_mb' uses (after.HeapReleased - before.HeapReleased). Verify that this reflects the intended meaning; if the intention is to log the memory released, the subtraction order may need to be reversed.
zap.Int64("released_mb", int64(after.HeapReleased-before.HeapReleased)/1024/1024),

@status-im-auto
Copy link
Member

status-im-auto commented Apr 23, 2025

Jenkins Builds

Click to see older builds (47)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 1f77850 #1 2025-04-23 10:40:23 ~2 min ios 📦zip
✔️ 1f77850 #1 2025-04-23 10:40:32 ~3 min android 📦aar
✔️ 1f77850 #1 2025-04-23 10:41:34 ~4 min macos 📦zip
✔️ 1f77850 #1 2025-04-23 10:42:39 ~5 min macos 📦zip
✔️ 1f77850 #1 2025-04-23 10:43:13 ~5 min windows 📦zip
✔️ 1f77850 #1 2025-04-23 10:43:50 ~6 min linux 📦zip
✔️ 1f77850 #1 2025-04-23 10:47:43 ~10 min tests-rpc 📄log
✔️ 1f77850 #1 2025-04-23 11:13:32 ~35 min tests 📄log
✔️ a3423f9 #2 2025-04-23 10:43:25 ~2 min ios 📦zip
✔️ a3423f9 #2 2025-04-23 10:43:36 ~2 min android 📦aar
✔️ a3423f9 #2 2025-04-23 10:45:36 ~3 min macos 📦zip
✔️ a3423f9 #2 2025-04-23 10:47:21 ~4 min windows 📦zip
✔️ a3423f9 #2 2025-04-23 10:47:56 ~5 min macos 📦zip
✔️ a3423f9 #2 2025-04-23 10:49:07 ~5 min linux 📦zip
✔️ a3423f9 #2 2025-04-23 10:56:11 ~8 min tests-rpc 📄log
✔️ a3423f9 #2 2025-04-23 11:49:07 ~35 min tests 📄log
✔️ af2d7c9 #3 2025-05-09 11:15:46 ~3 min android 📦aar
✔️ af2d7c9 #3 2025-05-09 11:16:04 ~3 min ios 📦zip
✔️ af2d7c9 #3 2025-05-09 11:17:56 ~5 min macos 📦zip
✔️ af2d7c9 #3 2025-05-09 11:17:58 ~5 min macos 📦zip
✔️ af2d7c9 #3 2025-05-09 11:18:35 ~5 min linux 📦zip
✔️ af2d7c9 #3 2025-05-09 11:21:55 ~9 min windows 📦zip
✔️ af2d7c9 #3 2025-05-09 11:23:24 ~10 min tests-rpc 📄log
✖️ af2d7c9 #3 2025-05-09 11:49:07 ~36 min tests 📄log
✔️ a5be759 #4 2025-05-09 11:20:43 ~2 min android 📦aar
✔️ a5be759 #4 2025-05-09 11:21:02 ~3 min ios 📦zip
✔️ a5be759 #4 2025-05-09 11:23:03 ~5 min macos 📦zip
✔️ a5be759 #4 2025-05-09 11:23:11 ~5 min macos 📦zip
✔️ a5be759 #4 2025-05-09 11:24:33 ~5 min linux 📦zip
✔️ a5be759 #4 2025-05-09 11:26:13 ~4 min windows 📦zip
✔️ a5be759 #4 2025-05-09 11:33:11 ~9 min tests-rpc 📄log
✔️ a5be759 #4 2025-05-09 12:24:38 ~35 min tests 📄log
✔️ 1cbcf0d #5 2025-05-19 11:29:28 ~3 min android 📦aar
✔️ 1cbcf0d #5 2025-05-19 11:30:38 ~4 min ios 📦zip
✔️ 1cbcf0d #5 2025-05-19 11:31:38 ~5 min macos 📦zip
✔️ 1cbcf0d #5 2025-05-19 11:32:00 ~5 min windows 📦zip
✔️ 1cbcf0d #5 2025-05-19 11:32:23 ~5 min linux 📦zip
✔️ 1cbcf0d #5 2025-05-19 11:32:31 ~5 min macos 📦zip
✔️ 1cbcf0d #5 2025-05-19 11:37:16 ~10 min tests-rpc 📄log
✔️ 1cbcf0d #5 2025-05-19 12:05:28 ~38 min tests 📄log
✔️ ab7c27a #6 2025-05-19 11:36:31 ~3 min android 📦aar
✔️ ab7c27a #6 2025-05-19 11:37:05 ~3 min macos 📦zip
✔️ ab7c27a #6 2025-05-19 11:37:44 ~4 min windows 📦zip
✔️ ab7c27a #6 2025-05-19 11:38:40 ~5 min macos 📦zip
✔️ ab7c27a #6 2025-05-19 11:39:24 ~5 min linux 📦zip
✔️ ab7c27a #6 2025-05-19 11:39:33 ~6 min ios 📦zip
✖️ ab7c27a #6 2025-05-19 11:46:56 ~9 min tests-rpc 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 6f8401f #7 2025-05-19 11:50:39 ~3 min android 📦aar
✔️ 6f8401f #7 2025-05-19 11:50:47 ~3 min ios 📦zip
✔️ 6f8401f #7 2025-05-19 11:51:51 ~4 min windows 📦zip
✔️ 6f8401f #7 2025-05-19 11:52:40 ~5 min macos 📦zip
✔️ 6f8401f #7 2025-05-19 11:52:47 ~5 min macos 📦zip
✔️ 6f8401f #7 2025-05-19 11:53:22 ~5 min linux 📦zip
✔️ 6f8401f #7 2025-05-19 11:59:00 ~11 min tests-rpc 📄log
✔️ 6f8401f #6 2025-05-19 12:40:18 ~34 min tests 📄log
✔️ e174de4 #8 2025-05-20 10:43:41 ~3 min android 📦aar
✔️ e174de4 #8 2025-05-20 10:44:17 ~3 min ios 📦zip
✔️ e174de4 #8 2025-05-20 10:45:56 ~5 min windows 📦zip
✔️ e174de4 #8 2025-05-20 10:46:04 ~5 min macos 📦zip
✔️ e174de4 #8 2025-05-20 10:46:16 ~5 min macos 📦zip
✔️ e174de4 #8 2025-05-20 10:47:44 ~7 min linux 📦zip
✔️ e174de4 #8 2025-05-20 10:52:07 ~11 min tests-rpc 📄log
✔️ e174de4 #7 2025-05-20 11:16:51 ~36 min tests 📄log

Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.41%. Comparing base (0813124) to head (e174de4).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6549      +/-   ##
===========================================
- Coverage    60.44%   60.41%   -0.04%     
===========================================
  Files          848      848              
  Lines       104995   105027      +32     
===========================================
- Hits         63466    63450      -16     
- Misses       33953    33976      +23     
- Partials      7576     7601      +25     
Flag Coverage Δ
functional 25.76% <0.00%> (-0.22%) ⬇️
unit 58.31% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
api/geth_backend.go 55.69% <100.00%> (+0.69%) ⬆️
mobile/status.go 12.23% <100.00%> (+0.32%) ⬆️

... and 34 files with indirect coverage changes

@igor-sirotin
Copy link
Collaborator

@qfrank is this draft, or should we review?

@qfrank qfrank force-pushed the frank/chore/low-memory branch 2 times, most recently from af2d7c9 to a5be759 Compare May 9, 2025 11:17
@qfrank qfrank marked this pull request as ready for review May 9, 2025 11:17
@qfrank
Copy link
Contributor Author

qfrank commented May 9, 2025

@qfrank is this draft, or should we review?

ready to review :) @igor-sirotin

@qfrank qfrank force-pushed the frank/chore/low-memory branch from a5be759 to 1cbcf0d Compare May 19, 2025 11:26
Copy link
Contributor

@osmaczko osmaczko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious how often and under which circumstances you trigger this endpoint from mobile. Have you considered using GOMEMLIMIT instead?

@qfrank
Copy link
Contributor Author

qfrank commented May 20, 2025

I am curious how often and under which circumstances you trigger this endpoint from mobile.

It depends on onTrimMemory|onLowMemory to trigger this endpoint.

Have you considered using GOMEMLIMIT instead?

Not yet, what's the suitable mem value for limiting? Any idea? @osmaczko

@osmaczko
Copy link
Contributor

I am curious how often and under which circumstances you trigger this endpoint from mobile.

It depends on onTrimMemory|onLowMemory to trigger this endpoint.

Makes sense, that's great android provides such callback already.

Have you considered using GOMEMLIMIT instead?

Not yet, what's the suitable mem value for limiting? Any idea? @osmaczko

Good question. This needs to be evaluated from the mobile side. The appropriate value should come from observing the app’s runtime behavior under varying conditions, particularly by tracking metrics like average HeapInuse.

If onTrimMemory, triggered by the Android system itself, is effective, then GOMEMLIMIT may be unnecessary. Android likely has a more accurate signal than the Go runtime for deciding when to trim memory, since it has visibility into both system context and app state.

@qfrank
Copy link
Contributor Author

qfrank commented May 20, 2025

This needs to be evaluated from the mobile side. The appropriate value should come from observing the app’s runtime behavior under varying conditions, particularly by tracking metrics like average HeapInuse.

I tried to fix populate-db tool, generated lots of data, args like:

--added-contacts
300
--contacts
300
--public-chats
0
--one-to-one-chats
100
--number-of-messages
10000

and then profile the behavior of status-go, do you think if it's worth continue? @osmaczko

@osmaczko
Copy link
Contributor

This needs to be evaluated from the mobile side. The appropriate value should come from observing the app’s runtime behavior under varying conditions, particularly by tracking metrics like average HeapInuse.

I tried to fix populate-db tool, generated lots of data, args like:

--added-contacts
300
--contacts
300
--public-chats
0
--one-to-one-chats
100
--number-of-messages
10000

and then profile the behavior of status-go, do you think if it's worth continue? @osmaczko

would first observe how onTrimMemory -> ReleaseOSMemory performs. Most likely, GOMEMLIMIT will be unnecessary. So I think it's worth continuing, just to see how or if your approach works.

@qfrank qfrank force-pushed the frank/chore/low-memory branch from 6f8401f to e174de4 Compare May 20, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants