xyproto/wallutils

setrandom locks whole session

tigerjack opened this issue · 6 comments

I have a script calling setrandom every 30 minutes, and each time I notice the whole system freezes for a short period. This is quite annoying, especially when typing. Here there is a short video reproducing the issue
https://youtu.be/08_GoLF4sIw

Hi! Thanks for reporting the issue.

Could you please try running it as easy -c3 -N setrandom, after having installed easy from https://github.com/xyproto/easy ?

If that works out, I can add some of the code from easy to setrandom to make it ease up on the resource use.

Hi! Thanks for reporting the issue.

Could you please try running it as easy -c3 -N setrandom, after having installed easy from https://github.com/xyproto/easy ?

If that works out, I can add some of the code from easy to setrandom to make it ease up on the resource use.

Thanks for your help. I tried indeed to run it with easy and it seems slightly better, but still there is a visible freeze. I was thinking that it may be due to the size of the file, but I don't experience the biggest file in the directory with, for example, feh or imv. So, maybe it's just due to the number of files (~100)? I don't know, just guessing here.

It could be related to the number of files, but it's fairly quick with a directory here with 172 files:

% time setrandom /usr/share/pixmaps
setrandom /usr/share/pixmaps  0,01s user 0,00s system 105% cpu 0,011 total

How long does it take on your system?

Could it be that the disk spins down, if you use a harddrive, and then it needs to spin up again when a random wallpaper is set?

@xyproto

>time setrandom -v "$(xdg-user-dir PICTURES)/NotShotwelled/Backgrounds/esahubble-top100" 
Setting background image to: /mnt/internal/SharedData/Pictures/NotShotwelled/Backgrounds/esahubble-top100/heic1307a.jpg
Using the Sway backend.
swaymsg output * bg /mnt/internal/SharedData/Pictures/NotShotwelled/Backgrounds/esahubble-top100/heic1307a.jpg stretch
real	0m0.251s
user	0m0.019s
sys	0m0.012s
ls -l "$(xdg-user-dir PICTURES)/NotShotwelled/Backgrounds/esahubble-top100" | wc -l
93
>du -sh "$(xdg-user-dir PICTURES)/NotShotwelled/Backgrounds/esahubble-top100"
614M	/mnt/internal/SharedData/Pictures/NotShotwelled/Backgrounds/esahubble-top100

As a matter of fact, I think it's also related to the number of monitors you have. Also, I think it may be a problem with swaymsg output itself

This is the comparison of a direct application of swaymsg on a random file, and an indirect application through setrandom. 3 monitors were plugged.

hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' './direct.sh'
hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' './indirect.sh'

Command Mean [s] Min [s] Max [s] Proportions
./direct.sh 2.089 ± 0.334 1.552 2.468 [User: 0.006 s, System: 0.004 s]
./indirect.sh 1.957 ± 0.303 1.443 2.399 [User: 0.006 s, System: 0.006 s]

Thanks for the nice table, @tigerjack!

I assume we can conclude that it's swaymsg output that takes time.