i'm doing project university friends , wanted compare docker , openstack in terms of execution time simple script. however, we're getting results none of can explain, i'm hoping can explain whether did things wrong or if lack of knowledge understand happened.
here simple 'prime.sh' script
num=14293; i=2 while [ $i -lt $num ]; if [ `expr $num % $i` -eq 0 ] echo "divisible $i" exit fi i=`expr $i + 1` done echo "$num prime number "
what did execute unix time command (like time ./prime.sh
) on ubuntu server 14.04 instance in openstack, on ubuntu server 14.04 in docker , on host os (also ubuntu server 14.04) itself. on each system executed script 10 times.
our results were:
openstack 16,48 sec docker: 25,77 sec hostos: 30,45 sec
can please trying explain? don't get, why script needs twice long execute on host os on open stack, , also, why openstack 8secs faster docker.
ps. on unix, 'time' outputs real, user, , sys time, while docker , hostos pretty short in sys , user time (around 3 , 1secs, both) openstack needed 16secs in sys time. don't know if changes real time should important one, maybe helps understand?
edit: 1
for execution ssh'ed openstack ubuntu instance, touched script there , executed command line. same happened docker, here used docker exec -it ourubuntu bash
container , there created , executed script.
the command execute scripts time ./prime.sh
in fact used simple loop for in
seq 1 10; time ./prime.sh; done
number of results.
edit: 2 new script using $(( .. )) instead of expr ..
execution times lot more understandable. now, host os executes code fastest, second comes docker, openstack needs bit longer others
the first thing point out code spending huge amount of time doing things subshell expansions of expr
, seems beside point. if use bash, can faster result small primes (without changing algorithm):
prime1() { local -i num="$1" local -i i=1 while (( i++ < num )); (( num % )) && continue printf '%d divisible %d\n' "$num" "$i" return done printf '%d prime number\n' "$num" }
(if you're targetting /bin/sh or dash, need write in more posixly_strict manner, this:
prime2() { local num="$1" local i=2 local cur while [ $i -lt $num ]; cur=$(( $num % $i )) if [ $cur -eq 0 ]; printf '%d divisible %d\n' "$num" "$i" return fi i=$(( + 1 )) done printf '%d prime number\n' "$num" }
my tests yield these results on el capitan using bash:
$ ./prime running prime1 14293 prime number real 0m0.168s user 0m0.160s sys 0m0.006s running prime2 14293 prime number real 0m0.323s user 0m0.303s sys 0m0.019s running prime_orig 14293 prime number real 0m46.016s user 0m19.682s sys 0m25.132s
so comparison, you're losing on 46 seconds on calls have nothing prime comparison. makes me suspect there's funky method of invocation itself. example, passing script vm in such way makes host responsible expanding expr
subshells, save vms lot of processing time.
it's conjecture now, provide more info in question , i'll flesh out.
Comments
Post a Comment