File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,26 @@ go run ./dev/client tty bash
70
70
go run ./dev/client notty ls
71
71
```
72
72
73
+ ### Local performance cost
74
+
75
+ Local ` sh ` through a local ` wsep ` connection
76
+
77
+ ``` shellscript
78
+ $ head -c 100000000 /dev/urandom > /tmp/random; cat /tmp/random | pv | time ./bin/client notty sh -c "cat > /dev/null"
79
+
80
+ 95.4MiB 0:00:00 [ 269MiB/s] [ <=> ]
81
+ ./bin/client notty sh -c "cat > /dev/null" 0.32s user 0.31s system 31% cpu 2.019 total
82
+ ```
83
+
84
+ Local ` sh ` directly
85
+
86
+ ``` shell script
87
+ $ head -c 100000000 /dev/urandom > /tmp/random; cat /tmp/random | pv | time sh -c " cat > /dev/null"
88
+
89
+ 95.4MiB 0:00:00 [1.73GiB/s] [ <=> ]
90
+ sh -c " cat > /dev/null" 0.00s user 0.02s system 32% cpu 0.057 total
91
+ ```
92
+
73
93
### Performance Goals
74
94
75
95
Test command
Original file line number Diff line number Diff line change @@ -13,12 +13,15 @@ import (
13
13
"nhooyr.io/websocket"
14
14
)
15
15
16
+ const maxMessageSize = 64000
17
+
16
18
type remoteExec struct {
17
19
conn * websocket.Conn
18
20
}
19
21
20
22
// RemoteExecer creates an execution interface from a WebSocket connection.
21
23
func RemoteExecer (conn * websocket.Conn ) Execer {
24
+ conn .SetReadLimit (maxMessageSize )
22
25
return remoteExec {conn : conn }
23
26
}
24
27
@@ -94,7 +97,21 @@ func (r remoteStdin) Write(b []byte) (int, error) {
94
97
return 0 , err
95
98
}
96
99
stdinWriter := proto .WithHeader (r .conn , headerByt )
97
- return stdinWriter .Write (b )
100
+
101
+ maxBodySize := maxMessageSize - len (headerByt ) - 1
102
+ var nn int
103
+ for len (b ) > maxMessageSize {
104
+ n , err := stdinWriter .Write (b [:maxBodySize ])
105
+ nn += n
106
+ if err != nil {
107
+ return nn , err
108
+ }
109
+ b = b [maxBodySize :]
110
+ }
111
+
112
+ n , err := stdinWriter .Write (b )
113
+ nn += n
114
+ return nn , err
98
115
}
99
116
100
117
func (r remoteStdin ) Close () error {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
20
20
// The execer may be another wsep connection for chaining.
21
21
// Use LocalExecer for local command execution.
22
22
func Serve (ctx context.Context , c * websocket.Conn , execer Execer ) error {
23
+ c .SetReadLimit (maxMessageSize )
23
24
var (
24
25
header proto.Header
25
26
process Process
You can’t perform that action at this time.
0 commit comments