cloud-init generator script execute very slow in dash
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init (Ubuntu) |
Triaged
|
Medium
|
Unassigned |
Bug Description
hello
when system start, or sytemd reload, the cloud-init generator script (https:/
this is a simple test scirpt
```
root@debtest:~# cat /root/test.sh
while read line;do
echo $line
done < /root/test.txt
root@debtest:~# cat /root/test.txt
111
222
333
root@debtest:~# strace bash test.sh
...
read(0, "111\n222\n333\n", 4096) = 12
...
root@debtest:
read(0, "1", 1) = 1
read(0, "1", 1) = 1
read(0, "1", 1) = 1
read(0, "\n", 1) = 1
write(1, "111\n", 4111
) = 4
read(0, "2", 1) = 1
read(0, "2", 1) = 1
read(0, "2", 1) = 1
read(0, "\n", 1) = 1
write(1, "222\n", 4222
) = 4
read(0, "3", 1) = 1
read(0, "3", 1) = 1
read(0, "3", 1) = 1
read(0, "\n", 1) = 1
write(1, "333\n", 4333
```
in bash, read size is 4096, but in dash, read size is 1, so the dash need ready many many times if the configure file content is much, and we found in nfs/qemu_fw_cfg file system, (some cloud instance pass some cfg by qemu_fw_cfg file provided by kvm) , the cost time will be very long in dash
so we think it's better to modify the script interpreter to "/bin/bash" from "/bin/sh", if it is ok, we can submit a PR to change it.
Thanks
Changed in cloud-init (Ubuntu): | |
status: | New → Triaged |
importance: | Undecided → Medium |
I feel like the right thing to do is either:
a. write a tiny yaml parser in c and use it
b. let 'grep' do much of the filtering.
'a' is a lot of work and pain to get integrated but could ultimately lead to a much higher payout of having ds-identify in c (or rust... some better language than shell).
I feel like 'b' is probably the right solution here even though it requires some re-work and shell forks to get there. dash was chosen by ubuntu as /bin/sh for good reason. dash *does* outperform bash in many/most cases its really unfortunate that this is so bad. (https:/ /www.baeldung. com/linux/ dash-vs- bash-performanc e)
What I suggest is
1. file a bug with dash with an example of how bad the 'read(1)' performs on any non-tiny file.
2. re-work check_config to use 'grep' for most of the filtering.
I've put up a PR at https:/ /github. com/canonical/ cloud-init/ pull/4327 that shows '2'.