question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

method to propagate backpressure from parser handler

See original GitHub issue

First some background on this idea (coming from the image PR):

Currently SIXELs are decoded synchronously and the image decoding can correctly slow down the whole input processing chain, which leads to a drop of callback calls in WriteBuffer. Ok - sync processing works.

Ofc image decoding creates quite alot fuzz on the main thread and prolly should be done in a worker (for PNG/JPEG it has to be done async anyway). And thats where the data pressure hell begins - the SIXEL decoder has a throughput of ~50 MB/s while the DCS parser path operates at ~250 MB/s, means the terminal floods the decoder with 200 MB more data than it can process in a second (worst case). Currently there is no way to inform the WriteBuffer asynchronously about that data pressure condition from within the terminal.

Repro: Doing cat *.sixel in a folder full of sixel images with my async decoder triggers the issue. Same with mpv with their new sixel video output above a certain output size.

In general: This is currently a non-issue for our normal sync handler actions, as sync code always “blocks” and would indicate data pressure by a lower callback rate in WriteBuffer. But any async handler code with lower throughput than the parser itself will run into this. It is def. not only a problem of image processing, it just happened to be the first complicated async handler.

Idea: It would be good to have some way to pause/resume the data chunk processing on WriteBuffer from a parser handler. Given that flow control is properly set up for the terminal itself, this enables correct backpressure signalling from async parser handler code as well.

Up for discussion.

Edit: I dont need this fine-grained to a single input buffer position (although this would solve many issues around async handlers in general, the needed stack unwinding is not worth it), I think our already established chunk border stops are good enough.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
mofuxcommented, Jan 19, 2021

I can’t provide much technical input as I’m not very familiar with the parser, but I enjoyed watching this issue on its journey over last couple of days. Thanks for sharing all the updates, it really helped me to get an understanding of the technical solution you are striving for. I think your latest iteration looks pretty good.

2reactions
jerchcommented, Jan 19, 2021

T | Promise<T> should be possible. And yes, async handlers should be used with great care only, they will slow down the input processing alot, no matter how we deal with the state internally in the end. This mainly results from the needed “code slicing” and re-scheduling of the continuation (+ promise creation in case of async parse methods) - the higher the async load is, the higher gets this “bookkeeping”.

Need a few more tests with the conceptual ideas before getting down to a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Propagate back-pressure between two netty channels
I want to write a system using netty-4 where a server receives a request from one channel (cleverly dubbed in), does a transform...
Read more >
Understanding Reactive IO and Back-Pressure with (your own ...
Once the parsing is successfully completed, and we are ready to process the request, the handler can register for WRITE events.
Read more >
Back Pressure, or, Don't Accept Work Before You're Ready [I]
Back Pressure, or, Don't Accept Work Before You're Ready [I] - Sam Roberts, IBM CanadaBack pressure is a network protocol concept that is ......
Read more >
Custom Flows: Parsing XML (part I) - Akka
In Java you will need to use the AbstractInHandler and AbstractOutHandler types to create your handlers for downstream and upstream handlers ...
Read more >
axum::middleware - Rust - Docs.rs
axum's error handling model requires handlers to always return a response. However middleware is one possible way to introduce errors into an application....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found