Easiest way to inform server that a PATCH arrived on the client?

Hi,

I would like for there to be some mechanism for the server to be notified when the last PATCH arrives at the client, so that the server knows not to send another one. Is this possible?

The background is, I have a Bokeh server implementing a slider.on_change callback. The idea is to use the slider value to filter which slice of data gets displayed in a plot. It is potentially a lot of data (10k points per slice, and possibly 1000 or more slices) so I chose to do this by holding all of the data in a session server side, and only sending the slice to the client.

Also, I’ve implemented a mechanism to prevent multiple on_change callbacks to be scheduled. Unfortunately, this alone is not sufficient to prevent a backlog when the slider is dragged. I think this is what’s happening:

  1. On the client, the slider is dragged, which emits many “on-change” events
  2. The server is fast enough to process each of the on-change events completely before the next one arrives.
  3. Each invocation of the server-side on-change handler causes a PATCH to be sent to the client.
  4. The PATCH messages start to overlap, causing lag.

Here you can (hopefully) see that when the slider is moved and then left alone, the updates to the plot keep rolling in. I’d like to prevent this behavior.

Couple random thoughts:

  1. Have you tried/is it viable to use value_throttled property on the slider for the application?

  2. I’m not sure how complex your filtering effort is, but if the data “slices” are static, it can be a lot faster/less laggy if you restructure the data sorta as follows:

data_dict = {'data_slice_0':{'Component 1':[.....]
                                            ,'Component 2':[....]}
                   ,'data_slice_1':{'Component 1':[.....]
                                            ,'Component 2':[....]}
                  ,....etc,
                   }

Then the on_change callback grabs the slider value, and sets the CDS’s data to the appropriate key in data_dict:

#where sl is your slider and src is the CDS driving the renderer
sl_dict = {i:v for i,v in enumerate(data_dict.keys} #maps slider value to a key in data_dict
src.data = data_dict[sl_dict[sl.value]]

I’m not sure if this will resolve the main issue but just sharing a method I’ve used in the past to reduce lag/computation time.