Push freezes Browser

Hi,

i want to develop a webpage with vaadin, where i monitor some devices. I have an API where i get the current state of each device and i want to write changes to labels with server push.

Now i just tried with 100 devices shutting down and starting up. As the startup and shut down time depends on many cicumstances all devices have different times.
When i shut down / start up all devices at once the browser (tried on chrome and on firefox both current versions) starts to freeze when there are many server push actions going on to change the text of the labels.

Heres my code (a bit simplified):

for (int i = 0; i < wall.getRows(); i++){
              for (int j = 0; j < wall.getCols(); j++){
                        Device device = wall.getDevice(i, j);
                        Label label = new Label();
                        if (device.isSwitchedOn()){
                            label.setValue("ON ");
                        } else {
                            label.setValue("OFF ");
                        }
						labelMap.put(module.toString(), label);
                        grid.addComponent(label);
                    }
                }
            }

The code above just creates the table with all devices in the beginning. This works pretty well. I save all the labels in a hashmap so i can access them pretty fast without reading them from the dom tree.

Heres what i do when a state changes:

        public void devicePropChanged(final Device device, final String aPropertyName) {

            if (!aPropertyName.equals("strOperationState")) {
                return;
            }

            access(new Runnable() {
                
                @Override
                public void run() {
                    Label label = labelMap.get(device.toString());
                    if (device.isSwitchedOn()){
                        label.setValue("ON");
                    } else {
                        label.setValue("OFF");
                    }
                }
            });

Am i doing something wrong here? Any help would be appreciated.

Thanks!

Hi, how many of these devices do you have and how often do they change? The access() calls may cause contention on the session lock, slowing things down (although that shouldn’t happen too easily due to queuing and batching the invocations). More probably is, though, that the server-to-client communication is too much for the browser. You might want to update the UI only periodically, using manual push mode and a timer that calls UI.push() at some interval.

I testet with 100 devices. Normally they don’t switch on or off at the same time, but i still wanted to cover that as its not so good that the webpage freezes when you turn off or reboot all devices.
I already put any time consuming stuff outside the access() method so it only writes the new value to the label and nothing else, but it stays the same.

I tested with polling in 500ms periods and that worked fine, but polling is so old school and i thought push would be great because i dont have data all the time.

Server-to-client connection was localhost only so maybe its really the browser…

Ah, sorry, I see you already mentioned you tested with 100 devices.

I did a bit of testing myself and concluded that the browser side indeed seems to be the bottleneck. This is at least partially due to Vaadin doing some unnecessary work (see ticket
#8573
). Vaadin communication is not very well-optimized for the case of many tiny updates happening in a quick succession, so some sort of throttling and batching should improve the performance considerably.

One thing to try out would be switching to manual push, then in the device event schedule a push in, say, 1 second if one is not currently scheduled. This way the client is not drowned in push messages, it’s still updated almost immediately and you don’t need to do regular polling either server side or client side. However, a dedicated push thread that simply calls UI.push() at regular intervals might not be a bad option, as nothing is actually pushed if there are no changes.

Throttling push based on client performance is probably something we should investigate at Vaadin as well.

Ok thanks for your help. If theres nothing to push it wont push sounds acceptable to me so i will do it just as you said.