Profiling the Reference Server

We have learned a lot about profiling the code of the reference server, but there are some tricks to getting meaningful output. This section spells out a configuration that seems to work. As one can imagine, profiling a python program running under Apache is very difficult. It is better to run the server from the command line when using the python profiler. The other barrier to profiling that we found was caused by the reloader, so we had to tell python to not use the reloader. Finally, we found it best to disable the flask debugger (which is on by default if you run the server from the command line) because the debugger will cause every error message to be printed to the screen, which is in addition to the printout we already get from our exception handler. Leaving the debugger on will result in all exceptions print out twice.

Running the profile:

python -m cProfile -s cumulative -o profile.out ko-server/server_dev.py -H 100.70.26.73 --dont-use-reloader --config-file /srv/ga4gh/config.py

Evaluating the profile output:

If you don’t use the -o {output file} option then all output from the profiler runs to stdout and will be sorted with the function that takes the most cumulative time at the top of the list. You can review the text output manually, but a beter method is to use the -o option and then review the output using a nifty little program we found that interactively browses the function list. It provides a way to change the sorting and it also links the functions together so that you can follow the called and caller stacks. This is pretty handy. You can install and run it like this:

sudo pip install cprofilev
cprofilev -f profile.out -a 100.70.26.73

Note that it takes the ‘’‘profile.out’‘’ file that was generated by the cProfile run. To review the output simply point your browser to http://localhost:4000