Unverified Commit 64bc4dce authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Rate limit the number of outgoing gRPC messages (#1759)

* Rate limit the number of outgoing gRPC messages

This change should allow a better buffering of the outgoing gRPC
messages (less messages with bigger data blocks -> less fragmentation).
This should allow the clients (IDE) to better handle incoming data.

* Update arduino/utils/stream.go
Co-authored-by: default avatarUmberto Baldi <34278123+umbynos@users.noreply.github.com>
Co-authored-by: default avatarUmberto Baldi <34278123+umbynos@users.noreply.github.com>
parent 2ee21386
......@@ -15,17 +15,26 @@
package utils
import "io"
import (
"io"
"time"
)
// FeedStreamTo creates a pipe to pass data to the writer function.
// FeedStreamTo returns the io.Writer side of the pipe, on which the user can write data
func FeedStreamTo(writer func(data []byte)) io.Writer {
r, w := io.Pipe()
go func() {
data := make([]byte, 1024)
data := make([]byte, 16384)
for {
if n, err := r.Read(data); err == nil {
writer(data[:n])
// Rate limit the number of outgoing gRPC messages
// (less messages with biggger data blocks)
if n < len(data) {
time.Sleep(50 * time.Millisecond)
}
} else {
r.Close()
return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment