Skip to content
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

decrease the memory footprint of request/reply procedure #262

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

Conversation

VladoLavor
Copy link
Collaborator

@VladoLavor VladoLavor commented Jan 23, 2025

See issue #254

Instead of allocating new temporary request/reply objects for each message call and then leaving them for GC to collect, put them into sync.Pool instead. The follow-up call can pick previously allocated request/reply from the pool.

This approach is supposed to decrease the total number of allocations and STWs due to the GC runs.

Signed-off-by: Vladimir Lavor [email protected]

Signed-off-by: Vlado Lavor <[email protected]>
@VladoLavor VladoLavor self-assigned this Feb 20, 2025
@VladoLavor VladoLavor requested review from ondrej-fabry and a team February 20, 2025 11:08
@VladoLavor
Copy link
Collaborator Author

Providing test results using the API memory benchmark (GoVPP + borrowed from Frouter). The API RPS tends to fluctuate but seems to be improved in most measurements. The memory footprint is decreased as demonstrated by example results below.

Full results can be found in attached files:
govpp_api_memory_rps_perf_current_code.txt
govpp_api_memory_rps_perf_patched.txt

Simple API:

Current code

┌──────────────────────────────────────────────────┐
│ Simple API 1000000 calls                         │
├──────────────────────────────────────────────────┤
│ Time: 47.252972943s                              │
│ ~API calls: 1000000                              │
│ Rate per second: 21,162                          │ <--
│ Result: PASSED                                   │
├────────────────┬────────────────┬────────────────┤
│                │    Measured    │    Threshold   │
├────────────────┼────────────────┼────────────────┤
│ Total alloc    │      744.12 MB │        1.20 GB │ <--
│ Memory Freed   │      743.11 MB │                │
│ Heap alloc     │        1.01 MB │          10 MB │
│ Objects alloc  │     13,498,928 │                │ <--
│ Obj freed      │     13,481,554 │                │
│ Objects remain │         17,374 │        200,000 │
│ Num goroutines │             11 │                │
└────────────────┴────────────────┴────────────────┘

Patched

┌──────────────────────────────────────────────────┐
│ Simple API 1000000 calls                         │
├──────────────────────────────────────────────────┤
│ Time: 41.480308176s                              │
│ ~API calls: 1000000                              │
│ Rate per second: 24,107                          │ <--
│ Result: PASSED                                   │
├────────────────┬────────────────┬────────────────┤
│                │    Measured    │    Threshold   │
├────────────────┼────────────────┼────────────────┤
│ Total alloc    │      680.42 MB │        1.20 GB │ <--
│ Memory Freed   │      678.03 MB │                │
│ Heap alloc     │        2.40 MB │          10 MB │
│ Objects alloc  │     12,500,734 │                │ <--
│ Obj freed      │     12,457,508 │                │
│ Objects remain │         43,226 │        200,000 │
│ Num goroutines │             13 │                │
└────────────────┴────────────────┴────────────────┘

Frouter2 configuration:

Current code

┌──────────────────────────────────────────────────┐
│ Frouter2 API 40000 iterations:                   │
├──────────────────────────────────────────────────┤
│ Time: 2m32.136766488s     Iterations: 40000      │
│ ~API calls: 1000000                              │
│ Rate per second: 6,573                           │ <--
│ Result: PASSED                                   │
├────────────────┬────────────────┬────────────────┤
│                │    Measured    │    Threshold   │
├────────────────┼────────────────┼────────────────┤
│ Total alloc    │      963.11 MB │        1.50 GB │ <--
│ Memory Freed   │      961.68 MB │                │
│ Heap alloc     │        1.44 MB │          10 MB │
│ Objects alloc  │     20,943,174 │                │ <--
│ Obj freed      │     20,912,491 │                │
│ Objects remain │         30,683 │        200,000 │
│ Num goroutines │             11 │                │
└────────────────┴────────────────┴────────────────┘

Patched

┌──────────────────────────────────────────────────┐
│ Frouter2 API 40000 iterations:                   │
├──────────────────────────────────────────────────┤
│ Time: 2m25.913932796s     Iterations: 40000      │
│ ~API calls: 1000000                              │
│ Rate per second: 6,853                           │ <--
│ Result: PASSED                                   │
├────────────────┬────────────────┬────────────────┤
│                │    Measured    │    Threshold   │
├────────────────┼────────────────┼────────────────┤
│ Total alloc    │      840.59 MB │        1.50 GB │ <--
│ Memory Freed   │      835.62 MB │                │
│ Heap alloc     │        4.96 MB │          10 MB │
│ Objects alloc  │     19,025,199 │                │ <--
│ Obj freed      │     18,913,016 │                │
│ Objects remain │        112,183 │        200,000 │
│ Num goroutines │             13 │                │
└────────────────┴────────────────┴────────────────┘

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.

1 participant