jeudi 29 novembre 2018

Laravel 5:7 Determining reasonable setRedrawFrequency for Symfony's Progress Bar to avoid CLI blinking based on a quantity of records to loop

I work on several artisan commands that do something in a loop over a different quantity of items. Sometimes it's 30 items, sometimes it's 800k items, sometimes 20k.

Everything works but sometimes the output blinks. I know why - due to the too frequent refresh.

$progress = $this->output->createProgressBar($this->countSyncRowsCleaned);

I came up with determining the refresh rate somehow dynamically based on the volume of records to loop through. So instead of hardcoding:

$progress->setRedrawFrequency(50);

I do:

$progress->setRedrawFrequency(max(1, floor($this->countSyncRowsCleaned / 1000)));

Sometimes 50 is great, sometimes it's still to frequent.

What would be a good math formula to set reasonable redraw frequency for a huge spread of integers? Sometimes several records, sometimes over a million.

Thanks for any hints.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire