Skip to content

Commit 8626e66

Browse files
committed
Allow specification of PipedInputStream buffer size
The buffer size (in bytes) for the piped stream used to implement the :stream option for :out. If the ssh commands generate a high volume of output, then this buffer size can become a bottleneck. The buffer size can be specified by binding *piped-stream-buffer-size*, and defaults to 10Kb.
1 parent 30bd151 commit 8626e66

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/clj_ssh/ssh.clj

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,25 @@ keys. All other option key pairs will be passed as SSH config options."
301301
[^Session session]
302302
(open-channel session :shell))
303303

304+
(def
305+
^{:dynamic true
306+
:doc (str "The buffer size (in bytes) for the piped stream used to implement
307+
the :stream option for :out. If your ssh commands generate a high volume of
308+
output, then this buffer size can become a bottleneck. You might also
309+
increase the frequency with which you read the output stream if this is an
310+
issue.")}
311+
*piped-stream-buffer-size* (* 1024 10))
312+
304313
(defn- streams-for-out
305314
[out]
306315
(if (= :stream out)
307316
(let [os (java.io.PipedOutputStream.)]
308-
[os (java.io.PipedInputStream. os)])
317+
[os (java.io.PipedInputStream. os *piped-stream-buffer-size*)])
309318
[(java.io.ByteArrayOutputStream.) nil]))
310319

311320
(defn- streams-for-in
312321
[]
313-
(let [os (java.io.PipedInputStream.)]
322+
(let [os (java.io.PipedInputStream. *piped-stream-buffer-size*)]
314323
[os (java.io.PipedOutputStream. os)]))
315324

316325
(defn ssh-shell

0 commit comments

Comments
 (0)