Skip to content
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

Transmit only single frame in Write when compression enabled too #435

Open
andersroos opened this issue Feb 21, 2024 · 6 comments
Open

Transmit only single frame in Write when compression enabled too #435

andersroos opened this issue Feb 21, 2024 · 6 comments
Labels
Milestone

Comments

@andersroos
Copy link

Hi I am experiencing a pretty weird behavior and I am unsure if this is intentional or not.

We have had problems with bad client performance when reading data from a websocket in a game client based on Unreal Engine.

I have investigated this and with compression enabled each message is chopped up in tiny frames (the problem surfaced when we run with 1.8.7 which had compression on by default). The problem with Unreal is that it only reads one frame per client tick (~8 milliseconds) by default.

When I inspect this in Wireshark it looks like every other frame has a 236 byte payload and every other has a 4 byte payload.

I also run it in the debugger and it looks like the server will send a frame for each write call from the flate lib (github.com/klauspost/compress) and it has a hard coded bufferFlushSize set to 240 which in turn causes all those individual calls to writeFrame.

Is this intentional?

@nhooyr
Copy link
Owner

nhooyr commented Feb 21, 2024

Are you using Write or Writer? Write should write in a single frame whereas Writer unfortunately does write in two frames.

If you are using Write it's possible I forgot to add the code necessary to make it use a single frame with compression enabled.

@nhooyr
Copy link
Owner

nhooyr commented Feb 21, 2024

Also are you using the latest version or are you on 1.8.7 still?

@andersroos
Copy link
Author

Thanks for the response.

I have tested on 1.8.10 and it is the same behavior if compression is enabled (CompressionMode: websocket.CompressionNoContextTakeover).

The code uses Write (this method:

func (c *Conn) Write(ctx context.Context, typ MessageType, p []byte) error {
).

I can make a minimal example to reproduce if it's helpful.

@nhooyr
Copy link
Owner

nhooyr commented Feb 21, 2024

No need I see it, the problem is here:

if !c.flate() {

I need to extend this code to allow for single frame compression.

@nhooyr nhooyr added this to the v1.9.0 milestone Feb 21, 2024
@nhooyr nhooyr added feature and removed bug labels Feb 21, 2024
@nhooyr nhooyr changed the title Tiny frames when compression is enabled Transmit single frame in Write when compression enabled too Feb 21, 2024
@nhooyr nhooyr changed the title Transmit single frame in Write when compression enabled too Transmit only single frame in Write when compression enabled too Feb 21, 2024
@nhooyr
Copy link
Owner

nhooyr commented Feb 21, 2024

I would suggest disabling compression till I get to this. Hopefully within the next 2 months.

@andersroos
Copy link
Author

I would suggest disabling compression till I get to this. Hopefully within the next 2 months.

Thank you, will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants