0

how to measure memory usage on gwan application (each request made)? for the memory usage consumed by /csp script and /handlers script.

Gil
  • 3,279
  • 1
  • 15
  • 25
csw
  • 125
  • 6

2 Answers2

1

You can use the server_report function.

Check out http://gwan.ch/source/report.c for an example.

Paulo Melo
  • 176
  • 1
  • 1
  • i am asking memory usage of the script that we made, not gwan self memory usage. – csw Feb 12 '13 at 02:58
  • That really depends on what you malloc and how many parallel connections. You can get the information on the each host/virtual host at the log when GWAN launches, but there is no "easy" way (if not impossible) to get info on a servlet base. Of course that you can isolate your servlet alone in one host and get it from the GWAN log. But that would only be the memory occupied by the servlet. Then you can call the Linux operating system to get the process memory, at the beginning of the servlet, ask again after all your malloc and before you start to free something then calculate the difference. – Paulo Melo Feb 12 '13 at 09:47
  • ok, thanks for the response. if you run ab test,take a look at ?report.c, the RAM will be increased and do not get back. am i wrong ? – csw Feb 13 '13 at 06:41
  • I believe that it will get back when it is garbage collected. But I'm not sure if there would be a need to call the gc_* functions. Check http://gwan.ch/api#gc – Paulo Melo Feb 13 '13 at 09:19
  • The memory is first released to the application memory pools rather than to the system, and (much) later memory pools are re-initialized when possible (minor activity), usually once a day. It makes no sense to release memory to the system when the server is under load. – Gil Feb 14 '13 at 09:54
0

To measure the memory consumed by a G-WAN script (either handler or servlet), you will have to consider two things:

  1. code size (see the gwan.log file which dumps it along with an MD5 checksum)
  2. data size (which is dependant on your code so it can only be reported at runtime)

As Paulo suggested it, you can check what every malloc() / calloc() / strdup(), etc. does in your code but you will miss whatever memory used by G-WAN, system or third-party library calls.

The worker thread stack is also dynamically growing when needed... so, unless you know what you do there is no obvious way to precisely check what amount of memory is used by any given script.

Gil
  • 3,279
  • 1
  • 15
  • 25