-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State pickle compression #4430
base: main
Are you sure you want to change the base?
State pickle compression #4430
Conversation
@masenf we could add a compression threshold for small payloads. WDYT? Edit: I just implemented it |
While this can help a lot with big states, I think frontend payload compression could have an even bigger impact. Especially with slow connections, f.e. on mobile. Pickle payloads already benefit from referential serialization, json/ws does nothing similar. In fact, currently, the ws payloads are not compressed at all. Socketio only compresses in long-polling mode, which is only used for the initial connection and incompatible with gunicorn (I disabled it in #4441) |
@masenf i was just brainstorming in that comment and only read some docs. I did not test it. Just confirmed your wireshark capture, seems to be compressed by default. Interesting, i wonder where this happens, maybe i'll need to scroll trough some code to understand it. |
It is just not documented very well. python-socketio uses python-engineio which uses simple-websocket, which has compression enabled with hardcoded default settings since miguelgrinberg/simple-websocket@9277e67 |
In the JS version of socket.io,
|
Very intersting, thanks for sharing. Maybe some (optimized) reflex apps could even benefit from disabling that compression. For big states/apps it's probably good that it's enabled. However with python-socketio reflex has no way to control this. Maybe we can adress that in the future. However we are getting a bit off-topic in this PR which is about pickle compression. Maybe i'll create an Issue to further discuss our performance impact and ideas for websocket compression. |
6ae0ad0
to
e2a58c2
Compare
Turns out, state compression can make a big difference. Of course depending on the circumstances (Redis Bandwidth, Latency, State Size, ...). You can run
REDIS_URL=redis_host:redis_port pytest benchmarks/benchmark_pickle.py
to test it on your machine.Will probably evaluate other compression algorithms (especially those integrated into python) in a followup and introduce a
ReflexCompressor
Interface.