From bcb8381ef383b824f07885cdf04be205a1e8b619 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 14 Jun 2022 09:36:43 +0200 Subject: [PATCH 1/2] 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. --- arduino/utils/stream.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arduino/utils/stream.go b/arduino/utils/stream.go index c8894a6403b..5d25c20cf2e 100644 --- a/arduino/utils/stream.go +++ b/arduino/utils/stream.go @@ -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, 10240) 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 From afcc3969f9fdec686e0c0dcf346f67bd24f3cbb4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 15 Jun 2022 15:39:26 +0200 Subject: [PATCH 2/2] Update arduino/utils/stream.go Co-authored-by: Umberto Baldi <34278123+umbynos@users.noreply.github.com> --- arduino/utils/stream.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/utils/stream.go b/arduino/utils/stream.go index 5d25c20cf2e..d210ad08a3b 100644 --- a/arduino/utils/stream.go +++ b/arduino/utils/stream.go @@ -25,7 +25,7 @@ import ( func FeedStreamTo(writer func(data []byte)) io.Writer { r, w := io.Pipe() go func() { - data := make([]byte, 10240) + data := make([]byte, 16384) for { if n, err := r.Read(data); err == nil { writer(data[:n])