sbs20 / scanservjs

SANE scanner nodejs web ui
https://sbs20.github.io/scanservjs/
GNU General Public License v2.0
686 stars 137 forks source link

Convert gets called multiple times on slow devices #709

Open Leone25 opened 6 months ago

Leone25 commented 6 months ago

Hello,

On slow devices, such as raspberry pi 2 b+, since they are very limited resource wise, they tend to respond slowly to the preview request. What I've noticed from looking at processes trough htop (or top) while generating a preview of a scan is that the convert command gets called many times and multiple processes get started at the same time, all doing the same thing, aka converting and scaling down the preview image. Considering how slow the pi is, having to do this operation multiple times at the same time for no reason can be very degrading to the experience with the app.

I've checked a bit what the app is doing and I think there are multiple factors at blame:

  1. Refresing the preview image every flew seconds: I get why this is done, it allows the user to preview live the progress of the scan and it's an easy way to do pooling
  2. Not queueing requests: This tbh feels more like a design flaw/a cheap way to just get in working, what I believe it should happen is that requests to this endpoint should be queued, allowing, if the previews request hasn't finished processing in time for the next one, to all receive the same output from a single conversion process

By any chance, could we get a fix for this? I've tried to do this my self but, I'm not sure if my method would be the appreciated one. I'm willing to do it my self if you'd just give me some directives. Perhaps it would also be a good idea to include a way to disable generating previews while the scanner is still scanning. Lastly, why can't we delegate the resizing operation to the frontend?

Thank you for your time Enrico