flux-core icon indicating copy to clipboard operation
flux-core copied to clipboard

idea: implement something like libuv streams interface for libsubprocess writes

Open grondo opened this issue 1 year ago • 0 comments

As noted in #5518, libsubprocess has a set of fixed buffers (though configurable in size), with a default of 4M. When the buffer is full, flux_subprocess_write() returns a partial write, which pushes handling of flow control etc. onto the caller. This would mean each location at which flux_subprocess_write() is used would have to implement its own flow control, keep partially written buffers cached, accumulate a queue of buffers, etc. Instead the buffer/subprocess interface should probably assist more here.

Though I haven't studied in detail, the libuv stream interface seems like a good model. Instead of writing bytes to a subprocess (or buffer), where the data is copied to the buffer and potentially fails when the buffer is full, the write interface appears to take a vector of buffers which are passed by reference through the write interface without copying. These buffers are then queued for writing and written in order. Flow control is (apparently) handled seamlessly by the reactor, with a callback that fires once each buffer is written (likely for memory management).

This seems like it would be a good long-term solution for #5518, while also offering an advantage anywhere libsubprocess is used, instead of just being a one-off fix in the job-ingest workcrew code.

grondo avatar Nov 08 '23 16:11 grondo