question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak with bokeh serve and datashader

See original GitHub issue

I believe I am encountering a memory leak when using datashader in combination with a ‘bokeh serve’ style application.

Here is a simplified case that will reproduce the issue:

import datashader as ds
import numpy as np
import holoviews as hv
from itertools import cycle
from holoviews.operation.datashader import datashade
from bokeh.plotting import curdoc
import logging

log = logging.getLogger(__name__)

def setup_doc():
    log.info('Loading module.')
    cat = cycle(range(22))

    # Generate a bunch of data
    module_data = [
        {
            cat.next(): hv.Curve((np.linspace(0, 5000, 500000), np.random.normal(np.ones(500000))))
            for i in range(514)
        }
    ]

    # Use datashader and create a layout
    hv_layout = []
    for item in module_data:
        hv_layout.append(
            datashade(hv.NdOverlay(item, kdims='k'), aggregator=ds.count_cat('k'))
            .opts(plot=dict(width=800))
        )
    final_layout = hv.Layout(hv_layout).cols(1)
    log.info('Done loading module.')

    # Create plot
    plot = hv.renderer('bokeh').instance(mode='server').get_plot(final_layout)
    doc = curdoc()
    doc.add_root(plot.state)

setup_doc()

Add this to a folder test and run:

mprof run bokeh serve test

then try opening up a tab or two. Close the tabs and wait a minute or so for the sessions to be destroyed.

mprof plot

Afterward it appears that memory is not reclaimed.

Though it is hard to do with non-datashaded lines if you run the same experiment (with fewer datapoints) and a normal overlay, it appears the memory is reclaimed. I tried to dig into the persistent objects in the on_session_destroyed hook, and it seems at least the datashader object is not garbage collected when the session is destroyed. Not sure what else might be hanging around.

Am I missing something in the implementation?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
philippjfrcommented, Oct 26, 2018

Thank you both for your examples, after a marathon debugging session I’ve finally addressed the issue.

0reactions
ceballcommented, Nov 26, 2019

Sure, but please include detailed information about your environment (versions of packages, how installed, platform, etc) and how to reproduce (e.g. one of the scripts above).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bokeh server getting killed by memory leak, and sometimes ...
I'm trying to deploy a fairly resource-intensive Panel/Holoviews/Datashader project (a map with overlaid images with a lot of regridding and ...
Read more >
Panel/Holoviews/Bokeh app memory leaks, looking for ...
Based on Panel widgets it reads in some Tiff files with rioxarray and displays them as Datashader regrid. Both of these go onto...
Read more >
Repeated plotting in jupyter lab increases (browser) memory ...
By pre-rendering images on the Python side, Datashader is effectively a bandwidth compression tool (among other things). PNG export. Bokeh tilts ...
Read more >
Interactivity — Datashader v0.14.3
To get axes and interactivity, the images generated by Datashader need to be embedded into a plot using an external library like Matplotlib...
Read more >
pyviz/pyviz - Gitter
The Bokeh session timeouts aren't a memory leak either, for what that's worth. ... and unused-session-lifetime arguments to panel serve.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found