I’m trying to deploy a fairly resource-intensive Panel/Holoviews/Datashader project (a map with overlaid images with a lot of regridding and reshading going on) and based on what I found, it gets served by Bokeh, so that’s why I write here, but let me know if I’m wrong at that.
The app runs on an AWS EC2 ubuntu server with python 3.8.5 and with the latest versions for every module. I start the application with this command:
python -m panel serve app.py --allow-websocket-origin={'mydomain:5006','mydomain:8080','mydomain'}
The future is to be able to serve this through a Flask app using server_document, hence the extra ports, but currently it just gets embedded as an iframe using :5006. This is how the app.py exposes the content:
full_content = pn.Template(template_html)
full_content.add_panel('content', combined_panel_and_holoviews_elements)
full_content.servable()
When I start the script and load the page, I can see a process in htop with the same name as the command above and a green thread with the same name both taking up about 33% memory immediately and holding onto that. The CPU of the process ranges from 0% to 100% depending on the current user interaction. The memory consumption however constantly grows. Every time I refresh the browser, it grows by about 3% for a while and then decreases by about 1% but holds onto the total net 2% gain. So subsequent refreshes quickly grow the memory consumption of the system to the available maximum (which is 80.6% in this particular case), then at first everything just freezes, but finally, the script gets killed with a simple “Killed” message.
I have no information on what goes wrong, however, I had some error messages popping up earlier while still in development, but they went away before I had the time to directly address them. These only happened on rare occasions and looked like this:
bokeh.document.document - ERROR - Module <module 'bokeh_app_0471f2090d064ee1b1e2c9fd42c2fcb3' from '/x/y/app.py'> has extra unexpected referrers! This could indicate a serious memory leak. Extra referrers: [<cell at 0x7f15bc66bc50: module object at 0x7f15bc690470>]
Now, of course, I know that without reproducible code it’s hard to guess what goes wrong, but maybe somebody has any pointers.
- Are there common pitfalls that cause memory leaks and best practices to avoid them?
- Is there any documentation on what actually the Bokeh server does to be able to understand the underlying logic?
- Are there any better ways to investigate this issue than commenting out everything and hoping something will make it go away and then at least I would have a culprit?
- If the memory leak error message from earlier is relevant, how should I decipher what “cell” and “module object” it refers to?