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 observed. #646

Open
SameeCodeMan opened this issue Apr 8, 2023 · 1 comment
Open

Memory leak observed. #646

SameeCodeMan opened this issue Apr 8, 2023 · 1 comment

Comments

@SameeCodeMan
Copy link

SameeCodeMan commented Apr 8, 2023

Modified the sample_server program to add 2M counters.
During addition, the memory seems constant which is ok.
During curl, there is some memory being allocated as Private and not getting cleared. This keeps increasing with each curl and then the container runs out of memory.

SAMPLE SERVER code:

  Exposer exposer{"127.0.0.1:8080"};

  // create a metrics registry
  // @note it's the users responsibility to keep the object alive
  auto registry = std::make_shared<Registry>();

  // add a new counter family to the registry (families combine values with the
  // same name, but distinct label dimensions)
  //
  // @note please follow the metric-naming best-practices:
  // https://prometheus.io/docs/practices/naming/
  auto& test_gauge = BuildGauge()
                             .Name("test_gauge")
                             .Help("Test gauge")
                             .Register(*registry);

  const char *labels[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
  printf("Start adding data\n");
  clock_t start_time = clock();

  for(int i=0;i<200000;i++)
  {
      for(int j=0;j<10;j++)
      {
          std::string str = std::to_string(i);
          auto &tg = test_gauge.Add({{"label1",str}, {"label2",labels[j]}});
          tg.Set(i);
      }

  }

  printf("End adding data\n");
  clock_t end_time = clock();
  double duration = (double)(end_time - start_time) / CLOCKS_PER_SEC;
  printf("duration: %f\n",duration);

  // ask the exposer to scrape the registry on incoming HTTP requests
  exposer.RegisterCollectable(registry);

MEMORY LEAK:

1. Memory, After metrics data is added (Run sample_server):

[root@node1 samee]# ./mem_check.sh
numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                     33.00            0.00           **33.00**
----------------  --------------- --------------- ---------------
Total                      673.94            0.00          673.94
top output
top - 15:05:08 up 1 day,  1:21,  6 users,  load average: 13.00, 13.41, 13.27
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.6 us,  0.3 sy,  0.0 ni, 97.1 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
MiB Mem : 160344.0 total,  61327.9 free,  88731.8 used,  10284.4 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  69854.7 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0  862412 689980   4404 S   0.0   0.4   0:10.47 sample_server
4077508 root      20   0  862412 689980   4404 S   0.0   0.4   0:00.00 civetweb-worker
4077509 root      20   0  862412 689980   4404 S   0.0   0.4   0:00.00 civetweb-worker
4077510 root      20   0  862412 689980   4404 S   0.0   0.4   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007facb4000000     132       8       8 rw---   [ anon ]
00007facb4021000   65404       0       0 -----   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000     132       8       8 rw---   [ anon ]
00007facbc021000   65404       0       0 -----   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192       8       8 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192       8       8 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1248       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1320       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB          862416  690120  685652
Wed Apr  5 15:05:08 IST 2023

2. Memory, during curl(1st) execution:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                   1222.94            0.00         **1222.94**
----------------  --------------- --------------- ---------------
Total                     1863.88            0.00         1863.88
top output
top - 15:06:12 up 1 day,  1:22,  6 users,  load average: 11.81, 12.98, 13.13
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.9 us,  0.9 sy,  0.0 ni, 97.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem : 160344.0 total,  60087.0 free,  89971.0 used,  10286.0 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  68615.5 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 2023436   1.8g   4532 S   0.0   1.2   0:10.47 sample_server
4077508 root      20   0 2023436   1.8g   4532 S   0.0   1.2   0:00.00 civetweb-worker
4077509 root      20   0 2023436   1.8g   4532 S   0.0   1.2   0:13.36 civetweb-worker
4077510 root      20   0 2023436   1.8g   4532 S   0.0   1.2   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac44000000   57348   57348   57348 rw---   [ anon ]
00007fac47801000    8188       0       0 -----   [ anon ]
00007fac4c000000  131072  131072  131072 rw---   [ anon ]
00007fac54000000   65536   65536   65536 rw---   [ anon ]
00007fac5ad57000  281252  281252  281252 rw---   [ anon ]
00007fac6c000000  131072  131072  131072 rw---   [ anon ]
00007fac74000000   65536   65536   65536 rw---   [ anon ]
00007fac8c000000  131072  131072  131072 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007faca24d7000   93340   93340   93340 rw---   [ anon ]
00007facb4000000     132       8       8 rw---   [ anon ]
00007facb4021000   65404       0       0 -----   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192       8       8 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         2023440 1908616 1904020
Wed Apr  5 15:06:12 IST 2023

3. Memory, after curl(1st) completed:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                    353.25            0.00          **353.25**      <- what is stored here?
----------------  --------------- --------------- ---------------
Total                      994.19            0.00          994.19
top output
top - 15:06:59 up 1 day,  1:23,  6 users,  load average: 11.56, 12.79, 13.06
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  3.5 us,  0.3 sy,  0.0 ni, 96.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem : 160344.0 total,  60959.9 free,  89096.7 used,  10287.4 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  69489.7 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 1190092 994.1m   4532 S   0.0   0.6   0:10.47 sample_server
4077508 root      20   0 1190092 994.1m   4532 S   0.0   0.6   0:00.00 civetweb-worker
4077509 root      20   0 1190092 994.1m   4532 S   0.0   0.6   0:13.96 civetweb-worker
4077510 root      20   0 1190092 994.1m   4532 S   0.0   0.6   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac8c000000  131072   65668   65668 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007facb4000000     132       8       8 rw---   [ anon ]
00007facb4021000   65404       0       0 -----   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192       8       8 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         1190096 1018056 1013460
Wed Apr  5 15:06:59 IST 2023

4. Memory, during curl(2nd) execution:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                   1543.06            0.00         **1543.06**
----------------  --------------- --------------- ---------------
Total                     2184.00            0.00         2184.00
top output
top - 15:09:07 up 1 day,  1:25,  6 users,  load average: 13.01, 12.84, 13.04
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.9 us,  0.6 sy,  0.0 ni, 96.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem : 160344.0 total,  59764.4 free,  90288.7 used,  10290.9 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  68297.7 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:10.47 sample_server
4077508 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:13.37 civetweb-worker
4077509 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:13.96 civetweb-worker
4077510 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac34000000  122884  122884  122884 rw---   [ anon ]
00007fac3b801000    8188       0       0 -----   [ anon ]
00007fac3c000000   65536   65536   65536 rw---   [ anon ]
00007fac42d57000  281252  281252  281252 rw---   [ anon ]
00007fac54000000  131072  131072  131072 rw---   [ anon ]
00007fac5c000000  131072  131072  131072 rw---   [ anon ]
00007fac64000000   65536   65536   65536 rw---   [ anon ]
00007fac7c000000  131072  131072  131072 rw---   [ anon ]
00007fac84000000  131072  131072  131072 rw---   [ anon ]
00007fac8c000000  131072   65668   65668 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007faca24d7000   93340   93340   93340 rw---   [ anon ]
00007facb4000000   65536   65524   65524 rw---   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192      20      20 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         2351120 2236420 2231824
Wed Apr  5 15:09:07 IST 2023

5. Memory, after curl(2nd) completed:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                    673.38            0.00          **673.38**     <- can see this growing !!!
----------------  --------------- --------------- ---------------
Total                     1314.31            0.00         1314.31
top output
top - 15:09:12 up 1 day,  1:25,  6 users,  load average: 13.25, 12.89, 13.06
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.4 us,  0.2 sy,  0.0 ni, 98.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem : 160344.0 total,  60649.0 free,  89403.9 used,  10291.1 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  69182.5 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 1517772   1.3g   4532 S   0.0   0.8   0:10.47 sample_server
4077508 root      20   0 1517772   1.3g   4532 S   0.0   0.8   0:13.94 civetweb-worker
4077509 root      20   0 1517772   1.3g   4532 S   0.0   0.8   0:13.96 civetweb-worker
4077510 root      20   0 1517772   1.3g   4532 S   0.0   0.8   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac64000000   65536     132     132 rw---   [ anon ]
00007fac7c000000  131072  131072  131072 rw---   [ anon ]
00007fac84000000  131072  131072  131072 rw---   [ anon ]
00007fac8c000000  131072   65668   65668 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007facb4000000   65536   65524   65524 rw---   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192      20      20 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         1517776 1345860 1341264
Wed Apr  5 15:09:12 IST 2023

6. Memory, during curl(3rd) execution:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                   1543.06            0.00         **1543.06**
----------------  --------------- --------------- ---------------
Total                     2184.00            0.00         2184.00
top output
top - 15:10:48 up 1 day,  1:26,  6 users,  load average: 15.88, 13.92, 13.41
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  3.2 us,  1.0 sy,  0.0 ni, 95.8 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
MiB Mem : 160344.0 total,  59746.8 free,  90303.5 used,  10293.7 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  68283.0 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:10.47 sample_server
4077508 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:13.94 civetweb-worker
4077509 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:26.91 civetweb-worker
4077510 root      20   0 2351116   2.1g   4532 S   0.0   1.4   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac34000000  122884  122884  122884 rw---   [ anon ]
00007fac3b801000    8188       0       0 -----   [ anon ]
00007fac3c000000   65536   65536   65536 rw---   [ anon ]
00007fac42d57000  281252  281252  281252 rw---   [ anon ]
00007fac54000000  131072  131072  131072 rw---   [ anon ]
00007fac5c000000  131072  131072  131072 rw---   [ anon ]
00007fac64000000   65536     132     132 rw---   [ anon ]
00007fac7c000000  131072  131072  131072 rw---   [ anon ]
00007fac84000000  131072  131072  131072 rw---   [ anon ]
00007fac8c000000  131072  131072  131072 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007faca24d7000   93340   93340   93340 rw---   [ anon ]
00007facb4000000   65536   65524   65524 rw---   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192      20      20 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         2351120 2236420 2231824
Wed Apr  5 15:10:48 IST 2023

7. Memory, after curl(3rd) completed:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                    929.38            0.00          **929.38**
----------------  --------------- --------------- ---------------
Total                     1570.31            0.00         1570.31
top output
top - 15:10:53 up 1 day,  1:27,  6 users,  load average: 15.73, 13.92, 13.41
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.3 us,  0.9 sy,  0.0 ni, 96.8 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
MiB Mem : 160344.0 total,  60375.0 free,  89675.3 used,  10293.7 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  68911.2 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 1779916   1.5g   4532 S   0.0   1.0   0:10.47 sample_server
4077508 root      20   0 1779916   1.5g   4532 S   0.0   1.0   0:13.94 civetweb-worker
4077509 root      20   0 1779916   1.5g   4532 S   0.0   1.0   0:27.46 civetweb-worker
4077510 root      20   0 1779916   1.5g   4532 S   0.0   1.0   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac54000000  131072   65668   65668 rw---   [ anon ]
00007fac5c000000  131072  131072  131072 rw---   [ anon ]
00007fac64000000   65536     132     132 rw---   [ anon ]
00007fac7c000000  131072  131072  131072 rw---   [ anon ]
00007fac84000000  131072  131072  131072 rw---   [ anon ]
00007fac8c000000  131072  131072  131072 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007facb4000000   65536   65524   65524 rw---   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192      20      20 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         1779920 1608004 1603408
Wed Apr  5 15:10:53 IST 2023

8. Memory, during curl(4th) execution:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                   1799.06            0.00         **1799.06**
----------------  --------------- --------------- ---------------
Total                     2440.00            0.00         2440.00
top output
top - 15:15:09 up 1 day,  1:31,  6 users,  load average: 13.19, 13.46, 13.34
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.3 us,  0.2 sy,  0.0 ni, 97.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem : 160344.0 total,  59485.9 free,  90557.8 used,  10300.3 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  68028.7 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 2613260   2.4g   4532 S   0.0   1.5   0:10.48 sample_server
4077508 root      20   0 2613260   2.4g   4532 S   0.0   1.5   0:26.99 civetweb-worker
4077509 root      20   0 2613260   2.4g   4532 S   0.0   1.5   0:27.46 civetweb-worker
4077510 root      20   0 2613260   2.4g   4532 S   0.0   1.5   0:00.00 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac24000000  122884  122884  122884 rw---   [ anon ]
00007fac2b801000    8188       0       0 -----   [ anon ]
00007fac2c000000   65536   65536   65536 rw---   [ anon ]
00007fac32d57000  281252  281252  281252 rw---   [ anon ]
00007fac44000000  131072  131072  131072 rw---   [ anon ]
00007fac4c000000  131072  131072  131072 rw---   [ anon ]
00007fac54000000  131072   65668   65668 rw---   [ anon ]
00007fac5c000000  131072  131072  131072 rw---   [ anon ]
00007fac64000000   65536   65536   65536 rw---   [ anon ]
00007fac7c000000  131072  131072  131072 rw---   [ anon ]
00007fac84000000  131072  131072  131072 rw---   [ anon ]
00007fac8c000000  131072  131072  131072 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007faca24d7000   93340   93340   93340 rw---   [ anon ]
00007facb4000000   65536   65524   65524 rw---   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192      20      20 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         2613264 2498564 2493968
Wed Apr  5 15:15:09 IST 2023

9. Memory, after curl(4th) completed:

numstat output

Per-node process memory usage (in MBs) for PID 4077507 (sample_server)
                           Node 0          Node 1           Total
                  --------------- --------------- ---------------
Huge                         0.00            0.00            0.00
Heap                       640.91            0.00          **640.91**
Stack                        0.02            0.00            0.02
Private                   1185.38            0.00         **1185.38**
----------------  --------------- --------------- ---------------
Total                     1826.31            0.00         1826.31
top output
top - 15:15:14 up 1 day,  1:31,  6 users,  load average: 13.09, 13.43, 13.34
Threads:   4 total,   0 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.2 us,  0.3 sy,  0.0 ni, 98.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem : 160344.0 total,  60111.6 free,  89932.1 used,  10300.3 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  68654.4 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
4077507 root      20   0 2042060   1.8g   4532 S   0.0   1.1   0:10.48 sample_server
4077508 root      20   0 2042060   1.8g   4532 S   0.0   1.1   0:27.54 civetweb-worker
4077509 root      20   0 2042060   1.8g   4532 S   0.0   1.1   0:27.46 civetweb-worker
4077510 root      20   0 2042060   1.8g   4532 S   0.0   1.1   0:00.01 civetweb-master
pmap output
4077507:   ./sample_server
Address           Kbytes     RSS   Dirty Mode  Mapping
000056368b5a8000      76      64       0 r-x-- sample_server
000056368b7ba000       4       4       4 r---- sample_server
000056368b7bb000       4       4       4 rw--- sample_server
000056368d1a0000  656404  656296  656296 rw---   [ anon ]
00007fac44000000  131072   65668   65668 rw---   [ anon ]
00007fac4c000000  131072  131072  131072 rw---   [ anon ]
00007fac54000000  131072   65668   65668 rw---   [ anon ]
00007fac5c000000  131072  131072  131072 rw---   [ anon ]
00007fac64000000   65536   65536   65536 rw---   [ anon ]
00007fac7c000000  131072  131072  131072 rw---   [ anon ]
00007fac84000000  131072  131072  131072 rw---   [ anon ]
00007fac8c000000  131072  131072  131072 rw---   [ anon ]
00007fac94000000  131072  131072  131072 rw---   [ anon ]
00007fac9c000000   65536   65536   65536 rw---   [ anon ]
00007facb4000000   65536   65524   65524 rw---   [ anon ]
00007facba39b000   29076   29076   29076 rw---   [ anon ]
00007facbc000000   65536   65524   65524 rw---   [ anon ]
00007facc2153000       4       0       0 -----   [ anon ]
00007facc2154000    8192       8       8 rw---   [ anon ]
00007facc2954000       4       0       0 -----   [ anon ]
00007facc2955000    8192      24      24 rw---   [ anon ]
00007facc3155000       4       0       0 -----   [ anon ]
00007facc3156000    8192      20      20 rw---   [ anon ]
00007facc3956000    1540     320       0 r-x-- libm-2.28.so
00007facc3ad7000    2044       0       0 ----- libm-2.28.so
00007facc3cd6000       4       4       4 r---- libm-2.28.so
00007facc3cd7000       4       4       4 rw--- libm-2.28.so
00007facc3cd8000     108      96       0 r-x-- libpthread-2.28.so
00007facc3cf3000    2044       0       0 ----- libpthread-2.28.so
00007facc3ef2000       4       4       4 r---- libpthread-2.28.so
00007facc3ef3000       4       4       4 rw--- libpthread-2.28.so
00007facc3ef4000      16       4       4 rw---   [ anon ]
00007facc3ef8000    1776    1312       0 r-x-- libc-2.28.so
00007facc40b4000    2048       0       0 ----- libc-2.28.so
00007facc42b4000      16      16      16 r---- libc-2.28.so
00007facc42b8000       8       8       8 rw--- libc-2.28.so
00007facc42ba000      16      12      12 rw---   [ anon ]
00007facc42be000      92      84       0 r-x-- libgcc_s-8-20210514.so.1
00007facc42d5000    2044       0       0 ----- libgcc_s-8-20210514.so.1
00007facc44d4000       4       4       4 r---- libgcc_s-8-20210514.so.1
00007facc44d5000       4       4       4 rw--- libgcc_s-8-20210514.so.1
00007facc44d6000    1560    1384       0 r-x-- libstdc++.so.6.0.25
00007facc465c000    2044       0       0 ----- libstdc++.so.6.0.25
00007facc485b000      48      48      48 r---- libstdc++.so.6.0.25
00007facc4867000       4       4       4 rw--- libstdc++.so.6.0.25
00007facc4868000      12      12      12 rw---   [ anon ]
00007facc486b000     792     724       0 r-x-- libprometheus-cpp-core.so.1.1
00007facc4931000    2044       0       0 ----- libprometheus-cpp-core.so.1.1
00007facc4b30000       4       4       4 r---- libprometheus-cpp-core.so.1.1
00007facc4b31000      16      16      16 rw--- libprometheus-cpp-core.so.1.1
00007facc4b35000     440     428       0 r-x-- libprometheus-cpp-pull.so.1.1
00007facc4ba3000    2048       0       0 ----- libprometheus-cpp-pull.so.1.1
00007facc4da3000       8       8       8 r---- libprometheus-cpp-pull.so.1.1
00007facc4da5000       8       8       8 rw--- libprometheus-cpp-pull.so.1.1
00007facc4da7000     180     180       0 r-x-- ld-2.28.so
00007facc4fc9000      24      24      24 rw---   [ anon ]
00007facc4fd2000       8       8       8 rw---   [ anon ]
00007facc4fd4000       4       4       4 r---- ld-2.28.so
00007facc4fd5000       8       8       8 rw--- ld-2.28.so
00007ffdf4cfe000     136      24      24 rw---   [ stack ]
00007ffdf4df7000      16       0       0 r----   [ anon ]
00007ffdf4dfb000       8       4       0 r-x--   [ anon ]
ffffffffff600000       4       0       0 r-x--   [ anon ]
---------------- ------- ------- -------
total kB         2042064 1870148 1865552
Wed Apr  5 15:15:14 IST 2023
@gjasny
Copy link
Collaborator

gjasny commented Dec 27, 2023

Hello,
sorry for the long delay.

Are those 2 million counters you actual use case or did you only use such a big number to make the "leak" visible?

What you are seeing here is a pretty bad case of memory fragmentation. If you add a malloc_stats() call in the forever running loop of the sample server you see that the allocated (requested) size by the server is about 700 MBytes in the idle period. However the "system bytes" (requested from OS) is increasing. The reason is that the Registry::Collect method returns a std::vector<MetricFamily> with 2000000 entries. For that vector the C++ STL needs continuous memory. Due to memory fragmentation it needs to request a new block of memory from the OS every time.

It looks like the glibc memory allocator (in its default configuration) is doing a bad job here. If I replace it with tcmalloc I don't experience any growth:

A run with LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libtcmalloc.so.4.5.14 does not increase those values with every curl call:

MALLOC:      583838960 (  556.8 MiB) Bytes in use by application
MALLOC: +   1632067584 ( 1556.5 MiB) Bytes in page heap freelist

There are multiple ways how to deal with the problem. The easiest would be to omit the intermediate representation and directly stream into non-contiguous I/O buffers (or directly into the HTTP response stream). This change would also get rid of the memory spikes during the requests. But this change will take some time to apply.

Thanks,
Gregor

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

No branches or pull requests

2 participants