Skip to content

Is there any way at all to send data between recieving a close frame and sending the reply close frame? #523

@Scripter17

Description

@Scripter17

I'm making a thing that takes lines of tasks in Message::Text and returns lines of results in Message::Text.

For performance, I want to send response lines in fewer messages by accumulating them in a buffer and sending that buffer on some interval. This makes my code anywhere from 5 to 7 times faster.

Basically within a rocket_ws::WebSocket::channel (which uses tungstenite internally) I have

  1. A tokio::spawn'd future that repeatedly waits 1ms, gets all available results, and if there's any to return, returns them all at once.
  2. A loop that repeatedly gets the next message, then for each line of text parses the task, does it, and sends it over to the responding thread.

The problem is that the instant I read a Message::Close from the stream it is impossible to send any further responses because tungstenite immediately closes the connection with no consideration that I might actually have shit to do before closing the connection.

If I do it without the responding future, sending all the results from each message before getting the next message, it reliably sends all responses at the cost of taking 5 to 7 times as long.

If I were to manually reimplement the relevant parts of rocket_ws on top of tungstenite, is there any way at all for me to get the 5-7x performance boost without having a race condition forced upon me? I don't care how low level I have to go I just want this over with.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions