Skip to content

Commit 64bc4dc

Browse files
cmaglieumbynos
andauthored
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: Umberto Baldi <[email protected]> Co-authored-by: Umberto Baldi <[email protected]>
1 parent 2ee2138 commit 64bc4dc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: arduino/utils/stream.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@
1515

1616
package utils
1717

18-
import "io"
18+
import (
19+
"io"
20+
"time"
21+
)
1922

2023
// FeedStreamTo creates a pipe to pass data to the writer function.
2124
// FeedStreamTo returns the io.Writer side of the pipe, on which the user can write data
2225
func FeedStreamTo(writer func(data []byte)) io.Writer {
2326
r, w := io.Pipe()
2427
go func() {
25-
data := make([]byte, 1024)
28+
data := make([]byte, 16384)
2629
for {
2730
if n, err := r.Read(data); err == nil {
2831
writer(data[:n])
32+
33+
// Rate limit the number of outgoing gRPC messages
34+
// (less messages with biggger data blocks)
35+
if n < len(data) {
36+
time.Sleep(50 * time.Millisecond)
37+
}
2938
} else {
3039
r.Close()
3140
return

0 commit comments

Comments
 (0)