lxzan / gws

simple, fast, reliable websocket server & client, supports running over tcp/kcp/unix domain socket. keywords: ws, proxy, chat, go, golang...
https://pkg.go.dev/github.com/lxzan/gws
Apache License 2.0
1.34k stars 84 forks source link

Can library be modified to support (as a client) compression WITH server context takeover? #73

Closed Andrey36652 closed 7 months ago

Andrey36652 commented 7 months ago

My usecase includes many similar messages (150-400 bytes each) sent from third party server. I suppose required bandwidth can be decreased by using server context takeover (as a client). Currently as I can see in code https://github.com/lxzan/gws/blob/5318d69e5cc8140f33197fcb328f565e66043e2d/client.go#L135 https://github.com/lxzan/gws/blob/5318d69e5cc8140f33197fcb328f565e66043e2d/internal/others.go#L18 extension "server_no_context_takeover" is hardcoded. Is there any way to modify library for using server context takeover? Or is it too much hassle?

lxzan commented 7 months ago

There is no immediate intention to support context_take_over.

context_take_over was designed to be too confusing and inelegant to implement. Supporting context_take_over also introduces additional memory overhead, which breaks the way gws manages compressors/decompressors. And I don't think it's very effective at saving traffic, try protobuffer?

lxzan commented 7 months ago

While context_take_over makes more sense for client-side compatibility, gws is focused on high-performance servers, and I didn't want to implement an ugly context_take_over for clients.

Andrey36652 commented 7 months ago

try protobuffer?

As I said I receive data from third party server. It sends data as JSON. I have no control there

Andrey36652 commented 7 months ago

context_take_over was designed to be too confusing and inelegant to implement

What are possible obstacles while implementing it? Keep in mind I'm talking exclusively about client-side decompression with context takeover.

lxzan commented 7 months ago

It's not hard to just provide context_take_over support to the client, but I'll explore that when I have time.

The server has to consider the management of multiple compressors, but the client has only one, and does not need to consider the memory pool.

Andrey36652 commented 7 months ago

Thanks. Sadly their server does not support context takeover :( I wanted to benchmark it using python websocket library and found it out.

lxzan commented 7 months ago

gws supports context-takeover now

https://github.com/lxzan/gws/tree/context-takeover

Andrey36652 commented 7 months ago

Thank you very much

lxzan commented 7 months ago

gws v1.8.0 released, server/client fully support context takeover

https://lxzan.github.io/gws/reports/servers/ https://lxzan.github.io/gws/reports/clients/