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

The ability to send WebSocket messages in batches #2314

Closed
szlepermarcin opened this issue Jul 26, 2023 · 5 comments · Fixed by #2315
Closed

The ability to send WebSocket messages in batches #2314

szlepermarcin opened this issue Jul 26, 2023 · 5 comments · Fixed by #2315
Assignees
Labels
💎 Bounty enhancement New feature or request

Comments

@szlepermarcin
Copy link

From version 3.0.0-RC2, the WebSocket protocol handling API has changed (overall, the change has been very positive).
This change resulted in the loss of the ability to send multiple messages and flush them all at once.
In the previous versions (0.0.4 and 0.0.5), it was possible to optimize sending in this way

  val channel: Channel[WebSocketFrame] = ???
  def send(messages: Chunk[WebSocketFrame]) = messages match {
    case ch if ch.isEmpty => ZIO.unit
    case ch =>
      ZIO.foreachDiscard(ch.init)(m => channel.write(m)) *> channel.writeAndFlush(chunk.last, await = true)
  }

In my use case, this optimization led to even a few percent increase in performance, so my question is: would it be possible to add a feature that somehow enables way for such optimization in next versions?

@szlepermarcin szlepermarcin added the enhancement New feature or request label Jul 26, 2023
@adamgfraser
Copy link
Contributor

Will take a look at this.

@szlepermarcin
Copy link
Author

szlepermarcin commented Jul 27, 2023

One more important thing regarding the example above - the await = true flag set when the last message was sent is a protection in case that the WS client is slow or does not read the messages at all, without this protection we can have nasty effect of a heap or direct buffer memory "leak"

@jdegoes
Copy link
Member

jdegoes commented Jul 27, 2023

/bounty $100

@algora-pbc
Copy link

algora-pbc bot commented Jul 27, 2023

💎 $100 bounty created by jdegoes
🙋 If you start working on this, comment /attempt #2314 to notify everyone
👉 To claim this bounty, submit a pull request that includes the text /claim #2314 somewhere in its body
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to zio/zio-http!

Attempt Started Solution
🟢 @adamgfraser #2315

@algora-pbc
Copy link

algora-pbc bot commented Jul 28, 2023

💡 @adamgfraser submitted a pull request that claims the bounty. You can visit your org dashboard to reward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants