comparison OrthancServer/Resources/ImplementationNotes/memory_consumption.txt @ 5156:2020c2e479d3

doc
author Alain Mazy <am@osimis.io>
date Thu, 02 Feb 2023 09:34:38 +0100
parents 20911302c6e7
children 874e6b135614
comparison
equal deleted inserted replaced
5155:20911302c6e7 5156:2020c2e479d3
1 In Orthanc 1.11.3, we have introduced a Housekeeper thread that 1 In Orthanc 1.11.3, we have introduced a Housekeeper thread that
2 tries to give back unused memory back to the system. This is implemented 2 tries to give back unused memory back to the system. This is implemented
3 by calling malloc_trim every 100ms. 3 by calling malloc_trim every 100ms.
4
4 5
5 Here is how we validated the effect of this new feature: 6 Here is how we validated the effect of this new feature:
6 ------------------------------------------------------- 7 -------------------------------------------------------
7 8
8 We compared the behaviour of 2 osimis/orthanc Docker images from the mainline 9 We compared the behaviour of 2 osimis/orthanc Docker images from the mainline
9 on Feb 1st 2023. One image without the call to malloc_trim and the other with 10 on Feb 1st 2023. One image without the call to malloc_trim and the other with
10 this call. 11 this call.
12
11 13
12 1st test: unconstrained Docker containers 14 1st test: unconstrained Docker containers
13 ......................................... 15 .........................................
14 16
15 5 large studies are uploaded to each instance of Orthanc (around 1GB in total). 17 5 large studies are uploaded to each instance of Orthanc (around 1GB in total).
16 A script triggers anonymization of these studies as quick as possible. 18 A script triggers anonymization of these studies as quick as possible.
17 We compare the memory used by the containers after 2 minutes of execution 19 We compare the memory used by the containers after 2 minutes of execution
18 (using `docker stats`): 20 (using `docker stats`):
19 - without malloc_trim: 1500 MB 21 - without malloc_trim: 1500 MB
20 - with malloc_trim: 410 MB 22 - with malloc_trim: 410 MB
23
21 24
22 2nd test: memory constrained Docker containers 25 2nd test: memory constrained Docker containers
23 .............................................. 26 ..............................................
24 27
25 Each Orthanc container is limited to 400MB (through the docker-compose configuration 28 Each Orthanc container is limited to 400MB (through the docker-compose configuration
35 2 ~ 390 MB ~ 340 MB 38 2 ~ 390 MB ~ 340 MB
36 3 ~ 398 MB ~ 345 MB 39 3 ~ 398 MB ~ 345 MB
37 4 out-of-memory crash ~ 345 MB 40 4 out-of-memory crash ~ 345 MB
38 5..20 ~ 380 MB (stable) 41 5..20 ~ 380 MB (stable)
39 42
40 3nd test: memory constrained Docker containers 43
44 3rd test: memory constrained Docker containers
41 .............................................. 45 ..............................................
42 46
43 In this last test, we lowered the memory allocation to 300MB and have been able to 47 In this last test, we lowered the memory allocation to 300MB and have been able to
44 run the first test script for at least 7 minutes (we did not try longer !). The 48 run the first test script for at least 7 minutes (we did not try longer !). The
45 consumed memory is most of the time around 99% but it seems that the memory constrain 49 consumed memory is most of the time around 99% but it seems that the memory constrain
47 Cache. 51 Cache.
48 52
49 The same test without malloc_trim could never run for more than 35 seconds. 53 The same test without malloc_trim could never run for more than 35 seconds.
50 54
51 55
52 Note: 56 4th test: performance impact of malloc_trim and available memory
53 ---- 57 ................................................................
58
59 In this test, we have measured the time required to anonymize a 2000 instances study
60 with various configurations. It appears that malloc_trim or the total amount
61 of memory available in the system has no significant impact of performance.
62
63 - No malloc trim, 300 MB in the system: ~ 38s
64 - No malloc trim, 1500 MB in the system: ~ 38s
65 - With malloc trim, 300 MB in the system: ~ 38s
66 - With malloc trim, 1500 MB in the system: ~ 38s
67
68
69 Conclusion:
70 ----------
54 71
55 The use of malloc_trim does not guarantee that Orthanc will never reach a 72 The use of malloc_trim does not guarantee that Orthanc will never reach a
56 out-of-memory error, especially on very constrained systems. 73 out-of-memory error, especially on very constrained systems.
57 Depending on the allocation pattern, the Orthanc memory can get 74 Depending on the allocation pattern, the Orthanc memory can get
58 very fragmented and increase since malloc_trim only releases memory 75 very fragmented and increase since malloc_trim only releases memory
59 at the end of each of malloc arena. However, note that, even long before the 76 at the end of each of malloc arena. However, note that, even long before the
60 introduction of malloc_trim, we have observed Orthanc instances running for years 77 introduction of malloc_trim, we have observed Orthanc instances running for years
61 without ever reaching out-of-memory errors and Orthanc is usually considered as 78 without ever reaching out-of-memory errors and Orthanc is usually considered as
62 very stable. 79 very stable.
63
64
65
66 80
67 81
68 82
69 malloc_trim documentation 83 malloc_trim documentation
70 ------------------------- 84 -------------------------