Cache could implement back pressure when streaming Fetch pipe data to disk




4 years ago
2 months ago


(Reporter: bkelly, Unassigned)


(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)




4 years ago
Bug 1110814 is implementing a simple push mechanism for streaming piped data from Fetch() over to the parent process.  Right now there is no back-pressure mechanism.  I think this is fine for most cases, but we might want to implement back-pressure in the future.  The problem case I am considering is:

1) On a memory constrained firefox OS device with slow flash storage.
2) Run Cache.put('dvd.iso', fetch('dvd.iso')) on a fast local network. dvd.iso is quite large.
3) The network loads dvd.iso faster than we can write to disk.
4) Because we have no back pressure dvd.iso ends up being buffered in the parent process.
5) Parent process OOMs rebooting the device.

My idea for addressing this is a "soft" window mechanism:

a) Wrap the pipe reader stream on the parent side so CachePushStreamParent knows how much data has been read and when reads occur.
b) Combine this with how much is written in the parent to understand current size of pipe.
c) When pipe size exceeds a limit X, then send a message to child process to pause reading.
d) Buffers sent while "paused" are still written to pipe since we don't have a synchronous way to stop them from being sent while the pause message is in flight.
e) When enough is read from the pipe to drop below limit Y, then send a message to resume reading in the Child.

So the parent memory buffer would likely exceed limit X, but we could stop it from being unbounded until OOM.

Obviously not suggesting we do this now.  Its something to consider later once we have better usage data for Cache.


2 months ago
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.