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

Massive 100% CPU load when receiving multi frame WebSocket message #97

Open
hishnash opened this issue Jul 22, 2021 · 3 comments
Open
Labels
bug Something isn't working

Comments

@hishnash
Copy link

Describe the bug

When running the client (or server) and the running app receives a Websocket message that is split over many frames CPU load is massive and it takes a very long time to parse the incoming frames concatenating the buffer and contract the message.

To Reproduce

  1. create a simple Vapor app with a websocket server
  2. create a WebSocket client (using this branch to that is can send large amounts of data Chunk Data/Text frames by outboundMaxFrameSize. #96)
  3. send a large amount of data to the server (a few MB is enough)
  4. Notice how the CPU load on the server spikes and it takes ages to handle the incoming data even through the client was able to send it all very quickly without any real CPU load.

Expected behavior

The server should be able to handle a multi frame ws message without completely locking up the cpu core at 100%.

Environment

MacOS (this happens with or without the #95)

  • Vapor Framework version: 2.1.3
  • Vapor Toolbox version: 18.3.3
  • OS version: macOS 12.0 Beta (21A5284e)

Additional context

Running a profile suggesss that 71% of the cpu time is spent moving memory around.

image

and 28% is spend relocating the buffer
image

This seems related to the WebSocketFrameSequence.append method. It might well be better to make the WebSocketFrameSequence is it possible to create a ByteBuffer like object that just points to the underlying existing buffers rather than copies and decloates them?

@hishnash hishnash added the bug Something isn't working label Jul 22, 2021
@hishnash hishnash changed the title Massing CPU load when receiving multi frame WebSocket message Massive 100% CPU load when receiving multi frame WebSocket message Jul 22, 2021
@0xTim
Copy link
Member

0xTim commented Jul 23, 2021

Are you testing this is release mode or debug mode?

@hishnash
Copy link
Author

I have tested debug and profile builds ( think profile build are almost identical to release right?) I will test again when I get back from the shops.

Looking at the code it does look like it is copying data for every frame, since the default frame size is quite small this does mean a lot! Of copy operations.

@hishnash
Copy link
Author

@0xTim i can confirm this happens with release builds as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants