mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

Consider adding in permessage-deflate support for websockets

Open TheSkorm opened this issue 4 years ago • 2 comments

Hello,

We use mosquitto as an MQTT broker for the websockets endpoint of SondeHub.org. As an experiment to try to save bandwidth costs I implemented permessage-deflate in websockets.c and we saw significant reduction in bandwidth consumed.

image image

While having permessage-deflate likely isn't suitable for everyone I think making it a configurable option would be very hand for many users and the changes to code is very minimal.

The way I hacked it in was modifying websockets.c to add

static const struct lws_extension extensions[] = {
        {
                "permessage-deflate",
                lws_extension_callback_pm_deflate,
                "permessage-deflate"
                 "; client_no_context_takeover"
                 "; client_max_window_bits"
        },
        { NULL, NULL, NULL /* terminator */ }
};

and in mosq_websockets_init add info.extensions = extensions; prior to lws_create_context

I then had to modify the docker file to include -lz in the linker for mosquitto build and changed LWS_WITHOUT_EXTENSIONS=OFF and -DLWS_WITH_ZLIB=ON in the lws build.

TheSkorm avatar Jul 30 '21 11:07 TheSkorm

Thank you, it sounds sensible to have that as a configuration option.

ralight avatar Aug 20 '21 23:08 ralight

image fyi we are seeing segfaults with this approach under some loads / conditions. I haven't been able to debug further but thought you should be aware.

TheSkorm avatar Jan 06 '23 00:01 TheSkorm