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

Memory leak #171

Open
3 tasks done
Tracked by #244
sirex opened this issue Feb 1, 2022 · 7 comments · Fixed by #314, #323 or #326
Open
3 tasks done
Tracked by #244

Memory leak #171

sirex opened this issue Feb 1, 2022 · 7 comments · Fixed by #314, #323 or #326
Assignees
Labels

Comments

@sirex
Copy link
Collaborator

sirex commented Feb 1, 2022

Server constantly runs out of memory, because of a memory leak. Here is server log:

image-2022-01-31-10-32-31-579

Currently --max-requests 1000 setting was set as a temporary workaround.

Memory leaks should be identified and eliminated.

@sirex
Copy link
Collaborator Author

sirex commented Mar 17, 2022

This also effects swap usage, changed --max-requests to 100, as a temporary fix.

image-2022-03-15-11-16-59-265

I could not find anything suspicious in logs, but it looks, that this might be caused by jsonl, csv or ascii download of a large dataset. Or a small dataset but with a very large number of columns.

@sirex sirex added the bug Something isn't working label Jun 23, 2022
@sirex sirex self-assigned this Jun 29, 2022
@sirex sirex added this to Palaikymas Oct 31, 2022
@sirex sirex removed this from Portalo plėtra Oct 31, 2022
@sirex sirex moved this to In Progress in Palaikymas Oct 31, 2022
@sirex sirex linked a pull request Nov 1, 2022 that will close this issue
@sirex sirex closed this as completed in #314 Nov 1, 2022
Repository owner moved this from In Progress to Done in Palaikymas Nov 1, 2022
@sirex sirex reopened this Nov 1, 2022
@sirex sirex moved this from Done to In Progress in Palaikymas Nov 8, 2022
@sirex sirex linked a pull request Nov 12, 2022 that will close this issue
Repository owner moved this from In Progress to Done in Palaikymas Nov 15, 2022
@sirex sirex linked a pull request Nov 15, 2022 that will close this issue
@sirex sirex reopened this Nov 24, 2022
@sirex sirex removed this from Palaikymas Mar 6, 2023
@sirex sirex removed their assignment May 21, 2024
@JuliusLADP
Copy link
Collaborator

1.System D serviso auto perkrovimas (auto Spinta pakėlimas) Arnoldas
2. Identifikuoti laikotarpius, kuriems ištraukti atminties overload'as ir išanalizuoti situaciją šiems epizodams (justinas)
3. Identifikuotų priežasčių pataisymas (Justinas)

Traceback analizė (log levelių suskirstymas pagal vartotojo) - yra jau užduotis priežiūra 119

@JustinasKen
Copy link
Contributor

JustinasKen commented Nov 5, 2024

Pasibandžiau lokaliai paleisti 100k užklausų, kurios tik atidarė duomenų rinkinių sąrašą, patikrinau atmintį:

prieš leidžiant užklausas:

                                    types |   # objects |   total size
========================================= | =========== | ============
                                      str |      134092 |     23.41 MB
                                     dict |       69741 |     21.07 MB
                                     code |       47779 |      8.19 MB
                                     type |        6524 |      5.92 MB
                                    tuple |       56788 |      3.48 MB
                                      set |        2753 |      1.77 MB
                                     list |       13509 |      1.23 MB
                                  weakref |       10104 |    710.44 KB
  sqlalchemy.sql.visitors.TraversibleType |         509 |    531.50 KB
                              abc.ABCMeta |         516 |    527.59 KB
                      function (__init__) |        3351 |    445.05 KB
    openpyxl.descriptors.MetaSerialisable |         415 |    431.21 KB
    geoalchemy2.functions._GeoGenericMeta |         410 |    426.02 KB
                                frozenset |        1021 |    407.87 KB

po 100k užklausų:

                                    types |   # objects |   total size
========================================= | =========== | ============
                                     dict |      279947 |     41.92 MB
                                      str |      134103 |     23.41 MB
                                     list |      223711 |     14.17 MB
              ruamel.yaml.docinfo.DocInfo |      213619 |      9.78 MB
                                     code |       47779 |      8.19 MB
                                     type |        6524 |      5.92 MB
                                    tuple |       56788 |      3.48 MB
                                      set |        2753 |      1.77 MB
                                  weakref |       10104 |    710.44 KB
  sqlalchemy.sql.visitors.TraversibleType |         509 |    531.50 KB
                              abc.ABCMeta |         516 |    527.59 KB
                      function (__init__) |        3351 |    445.05 KB
    openpyxl.descriptors.MetaSerialisable |         415 |    431.21 KB
    geoalchemy2.functions._GeoGenericMeta |         410 |    426.02 KB

@JustinasKen
Copy link
Contributor

Pasibandžiau lokaliai paleisti 100k užklausų, kurios tik atidarė duomenų rinkinių sąrašą, patikrinau atmintį:

prieš leidžiant užklausas:

                                    types |   # objects |   total size
========================================= | =========== | ============
                                      str |      134092 |     23.41 MB
                                     dict |       69741 |     21.07 MB
                                     code |       47779 |      8.19 MB
                                     type |        6524 |      5.92 MB
                                    tuple |       56788 |      3.48 MB
                                      set |        2753 |      1.77 MB
                                     list |       13509 |      1.23 MB
                                  weakref |       10104 |    710.44 KB
  sqlalchemy.sql.visitors.TraversibleType |         509 |    531.50 KB
                              abc.ABCMeta |         516 |    527.59 KB
                      function (__init__) |        3351 |    445.05 KB
    openpyxl.descriptors.MetaSerialisable |         415 |    431.21 KB
    geoalchemy2.functions._GeoGenericMeta |         410 |    426.02 KB
                                frozenset |        1021 |    407.87 KB

po 100k užklausų:

                                    types |   # objects |   total size
========================================= | =========== | ============
                                     dict |      279947 |     41.92 MB
                                      str |      134103 |     23.41 MB
                                     list |      223711 |     14.17 MB
              ruamel.yaml.docinfo.DocInfo |      213619 |      9.78 MB
                                     code |       47779 |      8.19 MB
                                     type |        6524 |      5.92 MB
                                    tuple |       56788 |      3.48 MB
                                      set |        2753 |      1.77 MB
                                  weakref |       10104 |    710.44 KB
  sqlalchemy.sql.visitors.TraversibleType |         509 |    531.50 KB
                              abc.ABCMeta |         516 |    527.59 KB
                      function (__init__) |        3351 |    445.05 KB
    openpyxl.descriptors.MetaSerialisable |         415 |    431.21 KB
    geoalchemy2.functions._GeoGenericMeta |         410 |    426.02 KB

Ši problema atsiranda dėl ruamel.yaml bibliotekos 0.18.4 versijos.
Norint, kad nesikartotu reikia limituoti šios bibliotekos versiją iki 0.18.4.

@JustinasKen
Copy link
Contributor

JustinasKen commented Nov 11, 2024

Atlikau platesnį memory leak testavimą.

Bandžiau:

GET all: json, html, jsonl, csv, rdf, ascii
GET one
changelog
pagination
POST
POST su Errors
count()
summary: numeric, time

Leaks:
html - kraunant file paths, kuriamas naujas ExitStack context.

Lėtai veikia:
summary, csv, rdf
Imant įrašus (kai jų yra labai daug), puslapiai, kurie yra arčiau duomenų pabaigos, smarkiai suletėja.

Galimos vietos, kurios sunaudoja atmintį:
html grąžina TemplateResponse, kuris galimai užkrauna visus pateiktu duomenis į atmintį.
summary visada sukuria iki 100 įrašų buckets
manifest render užkrauna viską į atmintį prieš grąžinant (šis funkcionalumas teoriškai dar nėra naudojamas, prisidėjo su inspect API).

summary valgo labai daug duomenų bazės atminties, lokaliai pasibandžiau
15M įrašų padaryti time summary, duomenų bazės virtualiuos mašinos atminties panaudojimas tai užklausai pakilo iš 6GB į 21GB.
Reikia pakeisti summary ARRAY_AGG į kokį nors kitą sprendimą, kuris neužkrauna visko į atmintį.

@JustinasKen
Copy link
Contributor

html memory leak tvarkymo task - #954
summary duomenų bazės atminties sunaudojimo tvarkymo task - #955

@sirex
Copy link
Collaborator Author

sirex commented Nov 11, 2024

html grąžina TemplateResponse, kuris galimai užkrauna visus pateiktu duomenis į atmintį.

Taip viską užkrauna į atmintį, tačiau html atveju yra enforcintas _limit, reikėtu patikrinti ar jis veikia ir neduodi nurodyti didesnio _limit, nei tarkim 100, tada bus apsaugota, kad nesunaudotu daugiau atminties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants