Changes between Version 2 and Version 3 of PJNATH_Memory_Usage
- Timestamp:
- Jun 4, 2010 6:28:25 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PJNATH_Memory_Usage
v2 v3 5 5 }}} 6 6 7 = PJNATH RAMUsage Analysis and Optimization =7 = PJNATH Heap Usage Analysis and Optimization = 8 8 9 9 '''Table of Contents''' … … 20 20 We will use [http://www.pjsip.org/pjsua.htm pjsua] application for this purpose. All NAT traversal features will be enabled: STUN, ICE, and TURN. The lot. 21 21 22 Memory usage of non-PJNATH components will not be shown nor calculated.23 24 The tests are run on Linux x86_64 machine. The default 64bit alignment may grow the memory usage slightly. The executable are built with optimizationturned off (because I needed to do some debugging at the same time), but this shouldn't matter to the heap usage I think.25 26 I'm using PJSIP version 1.6-trunk, r3197 to be exact. Version prior to this didn't have configurable TURN pool memory size.22 For the purpose of this article, memory usage of non-PJNATH components will not be shown nor calculated. 23 24 The tests were run on a Linux x86_64 machine. The default 64bit alignment may have grown the memory usage slightly. The executable were built with optimizations turned off (because I needed to do some debugging at the same time), but this shouldn't matter to the heap usage I think. 25 26 PJSIP version 1.6-trunk was used, r3197 to be exact. Version prior to this didn't have configurable TURN pool memory size. 27 27 28 28 [[BR]] … … 30 30 == How to Calculate the Memory Usage == 31 31 32 You can enter "'''dd'''" in pjsua do dump memory usage to the screen and log. For this test though, I've instrumented the application to dump memory usage at certain points(with {{{pjsip_endpt_dump()}}}) to make the results more consistent.32 Enter "'''dd'''" in pjsua menu to dump all the pools being allocated to the screen/log. For this test though, I've instrumented the application a bit to dump the memory usage at certain points during execution (with {{{pjsip_endpt_dump()}}}) to make the results more consistent. 33 33 34 34 [[BR]] … … 36 36 == Call Setup == 37 37 38 Tests are all done in caller side.38 Calculations were all done in caller side. 39 39 40 40 Caller: … … 43 43 $ ./pjsua-x86_64-unknown-linux-gnu --null-audio --max-calls=1 \ 44 44 --stun-srv=stun.pjsip.org --use-ice \ 45 --dis-codec \* --add-codec pcmu 45 --dis-codec \* --add-codec pcmu \ 46 46 --log-file mem.log \ 47 47 --use-turn --turn-srv=turn.pjsip.org:33478 \ 48 48 --turn-user xxx --turn-passwd xxx 49 49 }}} 50 - has two components (RTP and RTCP) and three candidates for each component (host, STUN, and TURN) in the SDP offer50 - has two components (RTP and RTCP) and three candidates (host, STUN, and TURN) for each component in the SDP offer, making a total of six candidates in the offer. 51 51 52 52 … … 58 58 --stun-srv=stun.pjsip.org 59 59 }}} 60 - has two components (RTP and RTCP) and one host candidate in the SDP answer .60 - has two components (RTP and RTCP) and one host candidate in the SDP answer, making a total of two candidates in the answer. 61 61 62 62 … … 65 65 == Checkpoints == 66 66 67 Memory usage calculations are taken at the following checkpoints:67 Memory usage calculations were taken at the following checkpoints: 68 68 69 69 1. Startup, after TURN allocation: 70 - this will show the ICE objects, along with some transmit data buffers for TURN allocation70 - this will show the initial ICE objects, along with some transmit data buffers for TURN allocation. This checkpoint is not really important. 71 71 1. After pjsua_start(): 72 - this will show additional objects by NAT type checker. This would be a good indication on how muchmemory is used during startup.72 - this will show additional objects created by NAT type checker. This would be a good indication on how much peak memory is used during startup. 73 73 1. Idle after initialization: 74 - memory usage should decrease before NAT type checker and initial transmit data buffershave been cleared. This shows the idle memory usage.74 - memory usage should have decreased because NAT type checker and initial transmit data buffers would have been cleared. This shows the idle memory usage. 75 75 1. Right after making outgoing call: 76 - this will show the additional objects created for the session 76 - this will show the additional objects created for the session. There is no special significance of this checkpoint. 77 77 1. ICE negotiation is complete: 78 - this would '''probably''' show the peak memory usage , as many ICE connectivity checks are still kept in memory.78 - this would '''probably''' show the peak memory usage during a call (and at all times), as many ICE connectivity checks are still kept in memory. 79 79 - Warning though: that might not be true. If connectivity checks have been running for a long time (say more than 7 seconds), some objects may have been cleaned. 80 80 1. 1 minute into call: 81 - memory usage should decrease as ICE connectivity checks are done. 81 - memory usage should decrease as ICE connectivity checks are done. This shows stable memory usage in a call. 82 - Warning though: TURN was not selected by ICE on this test. When TURN is selected, memory usage will be greater. 82 83 83 84 [[BR]] … … 85 86 == Running with Default Settings == 86 87 87 Here are the result: 88 88 Here are the heap usage (of PJNATH objects only) of pjsua, built with default settings, at the above checkpoints: 89 89 90 90 || || Used ||Allocated ||Utilization %|| … … 110 110 === Reduce the size of the packet buffers === 111 111 112 Each STUN and TURN sockets/sessions would allocate memory buffer, and by default the buffer size is quite big to accommodate wide uses of the library. The savings from reducing these would be significant. 113 112 114 Sample optimized value for the affected settings (and their previous default values in comment): 113 115 {{{ … … 117 119 }}} 118 120 119 Each STUN and TURN socket/session would allocate that much memory for their buffers, so the savings from reducing these would be significant.120 121 121 Note: 122 - (160+200): 160 is for 20ms PCMA/PCMU frame, and 200 is for additional STUN/TURN headers in case the frame needs to be transported encapsulated with that (it's probably too big, but I haven't checked the actualsize).122 - (160+200): 160 is for 20ms PCMA/PCMU frame, and 200 is for additional STUN/TURN headers in case the frame needs to be transported encapsulated inside STUN/TURN frame (the actual STUN/TURN overhead most likely would be much lower, but I haven't checked the exact size). 123 123 124 124 Warning: 125 - reducing the buffer size will limit how much you can send/receive of course 125 - reducing the buffer size will limit how much you can send/receive of course. 126 126 127 127 128 128 === Limit the number of ICE candidates, checks, components, etc. === 129 129 130 Sample optimized value for the affected settings (and their default value):130 These would affect the ICE's ''struct'' size. It probably wouldn't reduce it by much, but still, every bytes count! Sample optimized value for the affected settings (and their default value): 131 131 {{{ 132 132 #define PJ_ICE_ST_MAX_CAND 4 /* 8 */ … … 143 143 === Reduce Log Verbosity === 144 144 145 Turning off level 5 logging will turn off message tracing in the STUN session, which frees up memory by 1000 bytes per STUN session! 146 145 147 Suggested setting: 146 148 {{{ … … 148 150 }}} 149 151 150 Turning off level 5 logging will turn off message tracing in the STUN session, which frees up memory by 1000 bytes per STUN session!151 152 152 153 === Optimize the Pool Size === 153 154 154 Using smaller pool sizes would reduce the memory wasted , at the expense of more calls to ''malloc()''.155 156 For a very lazy optimization , just set all pool sizes to 128 (or lower!).155 Using smaller pool sizes would reduce the memory wasted by the pool, at the expense of more calls to ''malloc()''. Each memory pool used by the libraries are tunable, but you would need to experiment with your use case to find out the best size settings for them. 156 157 For a very lazy optimization though, just set all pool sizes to 128 (or lower!). 157 158 158 159 Warning: … … 160 161 161 162 163 162 164 === All Settings === 163 165 164 These are the combined settings based on above methods. Copy and paste these to your '''{{{config_site.h}}}''':166 These are the combined settings based on above methods. You can copy and paste these to your '''{{{config_site.h}}}''': 165 167 166 168 {{{ … … 228 230 - please see all other warnings above 229 231 - the number of candidates will vary on each host, hence the memory usages will vary. 232 - these are just crude experimentations, just to give an idea on how to experiment further 230 233 231 234