Changes between Version 2 and Version 3 of PJNATH_Memory_Usage


Ignore:
Timestamp:
Jun 4, 2010 6:28:25 PM (14 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PJNATH_Memory_Usage

    v2 v3  
    55}}} 
    66 
    7 = PJNATH RAM Usage Analysis and Optimization = 
     7= PJNATH Heap Usage Analysis and Optimization = 
    88 
    99'''Table of Contents''' 
     
    2020We 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. 
    2121 
    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 optimization 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 I'm using PJSIP version 1.6-trunk, r3197 to be exact. Version prior to this didn't have configurable TURN pool memory size. 
     22For the purpose of this article, memory usage of non-PJNATH components will not be shown nor calculated. 
     23 
     24The 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 
     26PJSIP version 1.6-trunk was used, r3197 to be exact. Version prior to this didn't have configurable TURN pool memory size. 
    2727 
    2828[[BR]] 
     
    3030== How to Calculate the Memory Usage == 
    3131 
    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. 
     32Enter "'''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. 
    3333 
    3434[[BR]] 
     
    3636== Call Setup == 
    3737 
    38 Tests are all done in caller side. 
     38Calculations were all done in caller side. 
    3939 
    4040Caller: 
     
    4343 $ ./pjsua-x86_64-unknown-linux-gnu --null-audio --max-calls=1 \ 
    4444                                    --stun-srv=stun.pjsip.org --use-ice \ 
    45                                     --dis-codec \* --add-codec pcmu  
     45                                    --dis-codec \* --add-codec pcmu \ 
    4646                                    --log-file mem.log \ 
    4747                                    --use-turn --turn-srv=turn.pjsip.org:33478 \ 
    4848                                    --turn-user xxx --turn-passwd xxx 
    4949}}} 
    50  - has two components (RTP and RTCP) and three candidates for each component (host, STUN, and TURN) in the SDP offer 
     50 - 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. 
    5151 
    5252 
     
    5858                                   --stun-srv=stun.pjsip.org 
    5959}}} 
    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. 
    6161 
    6262 
     
    6565== Checkpoints == 
    6666 
    67 Memory usage calculations are taken at the following checkpoints: 
     67Memory usage calculations were taken at the following checkpoints: 
    6868 
    6969 1. Startup, after TURN allocation:  
    70     - this will show the ICE objects, along with some transmit data buffers for TURN allocation 
     70    - this will show the initial ICE objects, along with some transmit data buffers for TURN allocation. This checkpoint is not really important. 
    7171 1. After pjsua_start():  
    72     - this will show additional objects by NAT type checker. This would be a good indication on how much memory 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. 
    7373 1. Idle after initialization:  
    74     - memory usage should decrease before NAT type checker and initial transmit data buffers have 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. 
    7575 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. 
    7777 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. 
    7979    - 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. 
    8080 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. 
    8283 
    8384[[BR]] 
     
    8586== Running with Default Settings == 
    8687 
    87 Here are the result: 
    88  
     88Here are the heap usage (of PJNATH objects only) of pjsua, built with default settings, at the above checkpoints: 
    8989 
    9090|| ||   Used    ||Allocated     ||Utilization %|| 
     
    110110=== Reduce the size of the packet buffers === 
    111111 
     112Each 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 
    112114Sample optimized value for the affected settings (and their previous default values in comment): 
    113115{{{ 
     
    117119}}} 
    118120 
    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  
    121121Note:  
    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 actual size). 
     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). 
    123123 
    124124Warning: 
    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. 
    126126 
    127127 
    128128=== Limit the number of ICE candidates, checks, components, etc. === 
    129129 
    130 Sample optimized value for the affected settings (and their default value): 
     130These 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): 
    131131{{{ 
    132132 #define PJ_ICE_ST_MAX_CAND             4                       /* 8 */ 
     
    143143=== Reduce Log Verbosity === 
    144144 
     145Turning off level 5 logging will turn off message tracing in the STUN session, which frees up memory by 1000 bytes per STUN session! 
     146 
    145147Suggested setting: 
    146148{{{ 
     
    148150}}} 
    149151 
    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! 
    151152 
    152153=== Optimize the Pool Size === 
    153154 
    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!). 
     155Using 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 
     157For a very lazy optimization though, just set all pool sizes to 128 (or lower!). 
    157158 
    158159Warning: 
     
    160161 
    161162 
     163 
    162164=== All Settings === 
    163165 
    164 These are the combined settings based on above methods. Copy and paste these to your '''{{{config_site.h}}}''': 
     166These are the combined settings based on above methods. You can copy and paste these to your '''{{{config_site.h}}}''': 
    165167 
    166168{{{ 
     
    228230 - please see all other warnings above 
    229231 - 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 
    230233 
    231234