| View previous topic :: View next topic |
| Author |
Message |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Thu Dec 19, 2002 11:39 am Post subject: Automated emerge with distcc! |
|
|
Hi there,
I thought I'd share this new script with you (BEWARE: likely to contain bugs as it hasn't been thoroughly tested I only tested it with emerge -u world, so other command lines haven't been tested at all)
(Though bugs are not very likely to screw up your system )
Ok, what it does:
when you emerge it switches on distcc usage by default, but when the build fails with distcc, it tries to build the failing package again without it. After that, distcc is again switched on for the remaining packages, until it fails... etc.
Very handy for your emerge -u world
There are three ingredients:
1. /etc/env.d/90distcc:
| Code: |
CC="distcc"
CXX="distcc g++"
DISTCC_HOSTS="localhost myotherhost yah"
|
2. /usr/local/bin/gentoo_distcc_switch.sh:
| Code: |
#! /bin/bash
DISTCC_ENV="/etc/env.d/90distcc"
if [ "$1" = "on" ]; then
echo "Switching distcc on..."
/bin/cat $DISTCC_ENV | /bin/sed -e s/^#\ C/C/g > $DISTCC_ENV
/usr/sbin/env-update
echo "please run: \"source /etc/profile\""
fi
if [ "$1" = "off" ]; then
echo "Switching distcc off..."
/bin/cat $DISTCC_ENV | /bin/sed -e s/^C/#\ C/g > $DISTCC_ENV
/usr/sbin/env-update
echo "please run: \"source /etc/profile\""
fi
|
3. /usr/local/bin/gentoo_distcc_emerge.sh:
| Code: |
#! /bin/bash
# some user settings:
NO_DISTCC_LOG=/root/distcc_ebuild_failed.txt
# shift command line to contain the arguments to emerge
shift
while [ 1 ]; do
gentoo_distcc_switch.sh on
source /etc/profile
emerge $*
if [ $? -ne 0 ]; then
# an error occurred:
# get the first package again without distcc
# (strip version number with sed)
BAD_PKG=`emerge -p $* | awk '{ print $4 }' | grep -m 1 "/" | sed -e s/-[0-9].[0-9]*[A-z-0-9]*//g`
NON_PKG_OPT=`echo $* | grep -o -e -[A-z]`
gentoo_distcc_switch.sh off
source /etc/profile
emerge $NON_PKG_OPT $BAD_PKG
fi
if [ $? -ne 0 ]; then
# still an error without distcc: quit
exit 1
else
echo $BAD_PKG >> $NO_DISTCC_LOG
# now we can continue the original command,
# unless that's in fact a rebuild, which would result in endless rebuilding!
REBUILD=`emerge -p $* | grep "ebuild R "`
# ...or in case of update: "todo-list" is empty
TODO=`emerge -p $* | grep "/"`
if [ -n "$REBUILD" -o -z "$TODO" ]; then
echo "Nothing to do. (Finished I guess?)"
exit 0
fi
fi
done
|
Now, use it like this (for example):
| Code: |
gentoo_distcc_emerge.sh -u world
|
That's it
It seems the third scripts versioning stripper has a bug for some version-numbers, I'll check that later when I have time...
Oh, and change your MAKEOPTS in /etc/make.conf like so
| Code: |
MAKEOPTS="-j<number-of-distcc-hosts+1>"
|
This is said to be a good lower bound, out of thin air I'd say a good upper bound would be about <2*number-of-distcc-hosts>
The downside with large job-numbers will be that the primary build system will be very heavily loaded during non-distcc builds!
Enjoy  _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Sat Dec 21, 2002 9:17 pm Post subject: |
|
|
Sorry: two quite serious bugs
The fix: script 3 should read like this:
| Code: |
#! /bin/bash
# some user settings:
NO_DISTCC_LOG=/root/distcc_ebuild_failed.txt
while [ 1 ]; do
gentoo_distcc_switch.sh on
source /etc/profile
echo Executing: emerge $*
emerge $*
if [ $? -ne 0 ]; then
# an error occurred:
# get the first package again without distcc
# (strip version number with sed)
BAD_PKG=`emerge -p $* | grep -m 1 "\[ebuild" | awk '{ print $4 }' | sed -r -e s/-[0-9.]+[_-]*[A-z]*[0-9]*[_-]*[A-z]*[0-9]*//g`
NON_PKG_OPT=`echo $* | grep -o -r -e -[A-z]`
echo BAD_PKG=$BAD_PKG
echo NON_PKG_OPT=$NON_PKG_OPT
gentoo_distcc_switch.sh off
source /etc/profile
echo Executing: emerge $NON_PKG_OPT $BAD_PKG
emerge $NON_PKG_OPT $BAD_PKG
fi
if [ $? -ne 0 ]; then
# still an error without distcc: quit
exit 1
else
echo $BAD_PKG >> $NO_DISTCC_LOG
# now we can continue the original command,
# unless that's in fact a rebuild, which would result in endless rebuilding!
REBUILD=`emerge -p $* | grep "ebuild R "`
# ...or in case of update: "todo-list" is empty
TODO=`emerge -p $* | grep "/"`
if [ -n "$REBUILD" -o -z "$TODO" ]; then
echo "Nothing to do. (Finished I guess?)"
exit 0
fi
fi
done
|
I also added a few debug-lines.
It seems to work ok, I did a whole gentoo_distcc_emerge.sh -u world with it, and now gentoo_distcc_emerge.sh kde gnome is happily running... (yes it's a multi-user system, I don't need neither of them)
Try it!  _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
dek l33t


Joined: 16 May 2002 Posts: 657 Location: Germany
|
Posted: Sun Dec 22, 2002 6:22 pm Post subject: |
|
|
Yes it really does something!
I started your script to compile qt on a almost fresh installed GCC3.2 system.
Unfortunately only the first package (libtiff) used distcc for the build. The second one in line (mysql) did not.
So i stopped the emerge after mysql was build. Next package was libmng.
I did "gentoo_distcc_emerge.sh libmng" and ended up in a loop. libmng compiles again and again, the fifth time right now, and it does not use distcc at all.
Any ideas whats going wrong here? _________________ Computer games don't affect kids. I mean if Pacman affected us as kids, we'd all be running around in darkened rooms, munching pills and listening to repetitive music. |
|
| Back to top |
|
 |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Sun Dec 22, 2002 8:00 pm Post subject: |
|
|
Did you use the second version of script (3)
Other than that you might check if script (2) changes file (1) the way it should: i.e. comment resp. uncomment line 1 and 2 of that file.
It may help to add some echo lines in script (3) to see exactly what commands are executed. That should provide some info on what's going wrong here.
Btw., kde-related stuff seems to be reluctant to use distcc? I'm not really sure, but I think the makefiles are constructed in a way that makes them ignore $CC and $CXX?
It's not perfect in the sense that I estimate about 70% of the packages of a gentoo system are actually able to use distcc, and of one such package about 20-40% of the total CPU-time would actually be distributed.
Anyway, an alternative would be mosix or cross-compiling, wich is significantly more work to get working.
Good luck
EDIT:
I just noticed that older versions of portage (i.e. as found on stage3 installs) produce different outputs... It may be worth to change the TODO line in script (3) to
| Code: |
TODO=`emerge -p $* | grep "\[ebuild"`
|
as it should be a bit more robust (?) _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
dek l33t


Joined: 16 May 2002 Posts: 657 Location: Germany
|
Posted: Sun Dec 22, 2002 10:54 pm Post subject: |
|
|
| JeroenV wrote: | Did you use the second version of script (3)  |
Yes, i've used the 2nd version.
| JeroenV wrote: | | Btw., kde-related stuff seems to be reluctant to use distcc? I'm not really sure, but I think the makefiles are constructed in a way that makes them ignore $CC and $CXX? |
I really don't know I've tried to build different packages with the script, but not a single one is using distcc. My first success with libtiff was the only one.
Just to make sure. Do i have to change the "-j" on every machine, or just on the one running the script?
The daemon runs on both machines and i read this in the helper machine's logfile:
| Code: | Dec 22 23:24:36 [distccd] (main) stdin is a tty; assuming --daemon mode
Dec 22 23:24:36 [distccd] distccd (version 0.14, built Dec 12 2002 17:01:44) listening on port 4200
Dec 22 23:24:36 [distccd] (dcc_parent_loop) waiting to accept connection |
When libtiff was compiled, there had be alot of output in the logfile about distcc.
| Quote: | | It's not perfect in the sense that I estimate about 70% of the packages of a gentoo system are actually able to use distcc, and of one such package about 20-40% of the total CPU-time would actually be distributed. |
I appreciate any cycle i can get.
| Quote: |
EDIT:
I just noticed that older versions of portage (i.e. as found on stage3 installs) produce different outputs... It may be worth to change the TODO line in script (3) to
| Code: |
TODO=`emerge -p $* | grep "\[ebuild"`
|
as it should be a bit more robust (?) |
I changed the line, but it does not help. _________________ Computer games don't affect kids. I mean if Pacman affected us as kids, we'd all be running around in darkened rooms, munching pills and listening to repetitive music. |
|
| Back to top |
|
 |
dek l33t


Joined: 16 May 2002 Posts: 657 Location: Germany
|
Posted: Sun Dec 22, 2002 11:14 pm Post subject: |
|
|
Oh wait, for some reason /etc/env.d/90distcc got overwritten. What happend here, the file was empty
OK i give it another try.
I'm compiling a bunch of GTK/Gnome stuff right now. The first package used distcc and compiled fine, the second package in line does not use distcc. Same as before.
EDIT: Let me rephrase this:
The compiler output says distcc g++ ... for the second package, too. But the helper machine doesn't compile anything. Maybe i have to increase the "-j" settings. I use "-j3" right now. (i've got two machines)
I'll have to do more testing and report how it is going. _________________ Computer games don't affect kids. I mean if Pacman affected us as kids, we'd all be running around in darkened rooms, munching pills and listening to repetitive music.
Last edited by dek on Sun Dec 22, 2002 11:30 pm; edited 1 time in total |
|
| Back to top |
|
 |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Sun Dec 22, 2002 11:26 pm Post subject: |
|
|
| Quote: | | Just to make sure. Do i have to change the "-j" on every machine, or just on the one running the script? |
Only the build host.
It may be the case that the gentoo_distcc_switch.sh is not working, or maybe for some reason your environment isn't updated
Try the following to check:
| Code: |
gentoo_distcc_switch.sh on
source /etc/profile
echo $CC $CXX
|
the output should be:
And doing the same but with "switch off", your output should be:
Also you might want to recheck the pathnames of 90distcc (file 1) for correctness (filename and reference in script (2))....
(although, as it worked for you once it should be ok...)
And is the directory containing the scripts in your path? Otherwise, make pathnames in the script (3) absolute.
I'm out of ideas for the rest, but you could add some lines in the script to give feedback on the values of $CC and $CXX at different points (i.e. before and after calling gentoo_distcc_switch.sh) to check if things are as they should be.
One more observation: I'm (still) compiling kde with the script, and it pretty much looks as though all kde stuff doesn't use distcc...
DUH I just checked 90distcc on that host, it's contents read
| Code: |
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
|
Something is seriously wrong here
That must have happened somewhere along the road, because int went well for a very long time... anyway, you might want to check that too
The good news: after manually changing 90distcc, kdeartwork is partly compiling distributed (so my kde-conclusion was partly incorrect)  _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
dek l33t


Joined: 16 May 2002 Posts: 657 Location: Germany
|
Posted: Mon Dec 23, 2002 12:06 am Post subject: |
|
|
| JeroenV wrote: | Try the following to check:
| Code: |
gentoo_distcc_switch.sh on
source /etc/profile
echo $CC $CXX
|
the output should be:
And doing the same but with "switch off", your output should be:
|
Works exactly the way you described.
| JeroenV wrote: | Also you might want to recheck the pathnames of 90distcc (file 1) for correctness (filename and reference in script (2))....
(although, as it worked for you once it should be ok...)
And is the directory containing the scripts in your path? Otherwise, make pathnames in the script (3) absolute. |
All is fine here. The scripts are in my path etc..
| JeroenV wrote: | DUH I just checked 90distcc on that host, it's contents read
| Code: |
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
|
Something is seriously wrong here
That must have happened somewhere along the road, because int went well for a very long time... anyway, you might want to check that too
|
So i'm not completely stupid.
In my case the file was suddenly empty and i had been sure i haven't touched it.
I assume portage itself does something after certain emerges (updating env stuff?) and this somehow kills 90distcc.
| Quote: | The good news: after manually changing 90distcc, kdeartwork is partly compiling distributed (so my kde-conclusion was partly incorrect)  |
Yes, these are really good news. KDE takes ages to compile. Every help compiling this monster is welcome.
It looks good, my helper machine compiles something and not only for one package like before.
Thanks for all your work! _________________ Computer games don't affect kids. I mean if Pacman affected us as kids, we'd all be running around in darkened rooms, munching pills and listening to repetitive music. |
|
| Back to top |
|
 |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Mon Dec 23, 2002 12:18 am Post subject: |
|
|
Eh, one addendum: it's my script (2) for sure that kills 90distcc , there shouldn't be any other things touching that file...
I'll be investigating that... the sed line is probably not robust
Anyway, I just started using sed
EDIT:
one more thing: apparently the emerge dependency order is not entirely fixed? So the assumption to "normally" emerge the failed package may lead to also normally emerging a dependency? Anyway, that might be a feature enhancement later... _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
dek l33t


Joined: 16 May 2002 Posts: 657 Location: Germany
|
Posted: Mon Dec 23, 2002 4:41 pm Post subject: |
|
|
There is still a bug in your script. Like i've already reported before, the last package always stays in a endless loop and gets compiled again and again.
Everything else works fine here. Some packages just don't make use of the helper machine. But i think this has nothing to do with your script. It is more likely to be concerned with distcc itself or the makefile of the given package.
I played a bit with different settings. So far i'm getting the best results with:
/etc/make.conf
MAKEOPTS="-j5"
/etc/env.d/90distcc
DISTCC_HOSTS="faster_machine slower_machine"
btw: Have you considered putting your scripts into "Documentation, Tips & Tricks"? _________________ Computer games don't affect kids. I mean if Pacman affected us as kids, we'd all be running around in darkened rooms, munching pills and listening to repetitive music. |
|
| Back to top |
|
 |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Mon Dec 23, 2002 5:08 pm Post subject: |
|
|
Hi,
I'm unable to reproduce the endless loop you mention, I have no trouble with it... Maybe you could add some debugging lines concerning the TODO and REBUILD variables and check what exactly happens
Is the order of the hosts in $DISTCC_HOSTS indeed of influence That's nice (maybe I should have RTFM'd)
Now I'm considering to write a more feature-rich script (maybe in python). The main objective is to really do cross-building: i.e. I will use my fastest machine as the main build host (and use distcc of course). It will work according to the following scheme:
1) use a customised set of USE and CFLAGS for the target host
2) get the list of packages to be emerged using emerge -p ....
3) get the first package from the list
4) double check whether emerge -p <first_package> indeed has no further dependencies
5) try a distcc-powered ebuild <first_package> package, if it fails, try without distcc again
6) repeat from (2) until done
and then (manually) do:
7 ) copy or mount the $PKGDIR on the target host
8 ) emerge -k ....
There is one (unsolvable) problem as I see it: compile time dependencies that are not satisfied on the build host will stop the build. The only 2 solutions:
1) build on the target host
2) first emerge normally on the build host and continue
EDIT:
I will put the next generation script in the Docs&Tips&Trics.... _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
wayned n00b

Joined: 25 Dec 2002 Posts: 8
|
Posted: Wed Dec 25, 2002 6:53 am Post subject: Re: Automated emerge with distcc! |
|
|
| JeroenV wrote: | | Code: | /bin/cat $DISTCC_ENV | /bin/sed -e s/^#\ C/C/g > $DISTCC_ENV
|
|
This line is unsafe since it is trying to read the same file it is overwriting. If you happen to luck out and the read process gets the file read into memory before the write process truncates the length to zero, it will just happen to work. You cannot depend on this, though.
Here's a replacement for this line that uses perl's inline-edit option:
| Code: | perl -i -pe 's/^# C/C/' $DISTCC_ENV
|
You'll also need to replace the other sed line that reverses the edit:
| Code: | perl -i -pe 's/^C/# C/' $DISTCC_ENV
|
These changes should fix the problem some people are having with the 90distcc file becoming corrupted.
..wayne.. |
|
| Back to top |
|
 |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Wed Dec 25, 2002 2:16 pm Post subject: |
|
|
| Quote: | JeroenV wrote:
| Code: |
/bin/cat $DISTCC_ENV | /bin/sed -e s/^#\ C/C/g > $DISTCC_ENV
|
This line is unsafe since it is trying to read the same file it is overwriting. If you happen to luck out and the read process gets the file read into memory before the write process truncates the length to zero, it will just happen to work. You cannot depend on this, though. |
Ah, thanks indeed I'd surely have had a very hard time finding this out myself
| Quote: |
The compiler output says distcc g++ ... for the second package, too. But the helper machine doesn't compile anything. Maybe i have to increase the "-j" settings. I use "-j3" right now. (i've got two machines)
|
Increasing -j might help indeed. Also, I suspect that if a job doesn't last long enough (less than ~1 s compiletime??), distcc chooses not to introduce migration-overhead, so it would compile locally. (This is a guess!)
Please note that my personal development of this hack is discontinued in favour of this one. _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
french tony Tux's lil' helper


Joined: 21 Aug 2002 Posts: 148 Location: Belfast
|
Posted: Sat Dec 28, 2002 2:14 pm Post subject: |
|
|
Hi, I'm trying to get distcc running.
This is my problem:
| Code: |
distcc[17912] (dcc_open_socket_out) ERROR: failed to connect to 192.168.1.2 port 4200: Connection refused
distcc[17912] (dcc_build_somewhere) Warning: failed to distribute to "192.168.1.2", running locally instead
|
I read in another thread that distcc should not be run as root, but running the scripts as a normal user doe not work:
| Code: |
Switching distcc on...
Can't remove /etc/env.d/90distcc: Permission denied, skipping file.
Traceback (most recent call last):
File "/usr/sbin/env-update", line 7, in ?
portage.env_update()
File "/usr/lib/python2.2/site-packages/portage.py", line 348, in env_update
newld=open(root+"etc/ld.so.conf","w")
IOError: [Errno 13] Permission denied: '/etc/ld.so.conf'
please run: "source /etc/profile"
Executing: emerge -u world
myaction world
myopts ['--update']
emerge: root access required.
|
could the first issue stated above have something to do with running the scripts as root?
thanks for helping a noob with a slow laptop. |
|
| Back to top |
|
 |
wayned n00b

Joined: 25 Dec 2002 Posts: 8
|
Posted: Sat Dec 28, 2002 6:11 pm Post subject: |
|
|
| french tony wrote: | | I read in another thread that distcc should not be run as root |
No, they were talking about distccd, the server daemon. From the error you cite, it sounds like you didn't run distccd on the 192.168.1.2 system. Make sure you installed the distcc package on that machine too, and then run the server as a normal user (on the 192.168.1.2 machine):
After you do that, the distcc program on your slow system will be able to run remote jobs on that server. You'd then run emerge as usual (as root).
..wayne.. |
|
| Back to top |
|
 |
JeroenV Guru


Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Sat Dec 28, 2002 10:46 pm Post subject: |
|
|
Tony,
Also note that the gentoo_distcc_switch.sh is a rather ugly hack, even if you took the bug out. I have found my new hack to work better, see the link in my previous post.
Good luck  _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
| Back to top |
|
 |
kronenpj n00b

Joined: 06 Sep 2002 Posts: 3 Location: Orlando, FL
|
Posted: Sun Jan 05, 2003 1:38 am Post subject: |
|
|
-switch is actually not too far off. Here's my update:
| Code: | #! /bin/bash
DISTCC_ENV="/etc/env.d/90distcc"
if [ "$1" = "on" ]; then
echo "Switching distcc on..."
rm -f ${DISTCC_ENV}.new
/bin/cat $DISTCC_ENV | /bin/sed -e 's/^#\ C/C/g' > ${DISTCC_ENV}.new
if [ ! -z ${DISTCC_ENV}.new ]; then
cat ${DISTCC_ENV}.new > ${DISTCC_ENV}
fi
rm -f ${DISTCC_ENV}.new
/usr/sbin/env-update
echo "please run: \"source /etc/profile\""
fi
if [ "$1" = "off" ]; then
echo "Switching distcc off..."
rm -f ${DISTCC_ENV}.new
/bin/cat ${DISTCC_ENV} | /bin/sed -e 's/^C/#\ C/g' > ${DISTCC_ENV}.new
if [ ! -z ${DISTCC_ENV}.new ]; then
cat ${DISTCC_ENV}.new > ${DISTCC_ENV}
fi
rm -f ${DISTCC_ENV}.new
/usr/sbin/env-update
echo "please run: \"source /etc/profile\""
fi
|
Just a little mod for the way shell programming works... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|