Limit parallel builds forked by IDE

1.8.6+ needs a limit on number of parallel builds it will fork for small memory systems.

A safe default would be number of cores present, with an option to select single-threaded for folks who don' t mind waiting.

https://forum.arduino.cc/index.php?topic=603700.0

Cheers!

Arduino does parallel builds?!

westfw, I think this is the commit where the parallel builds capability was added:

Parallel builds is mentioned in the 1.8.6 release notes.

Worst case please choose -j 8 or some finite value. Unlimited harshes the 1G RAM Raspberry Pi environment.

The "issue" pert links implies that the default limit is the limit that you asked for (number of cores.)
I don't see a way to pass a different limit to the build system, though, even if it's present in the arduino-builder app...

Do you have hard evidence that the RPi version is creating more forks than it has cores?
(It wouldn't surprise me if 1 compile job is pretty heavy-duty for a 1G RAM system :frowning: )
(Note that "-j8" is a make option, and make isn't involved in Arduino builds (sigh.))

Sorry for my old school gcc'ish args sir. I reached for what I knew, the Arduino IDE is a proprietary (tho free) JAVA blob to me.

The IDE or its underlings get into a forkfest. I'm on a standard pi3. 4 rocking ARM cores, 1G RAM.

How do I prove from the CLI the IDE goes nuts? let me try...

leem@testpi:~ $ grep -c processor /proc/cpuinfo 
4
leem@testpi:~ $ head -1 /proc/meminfo 
MemTotal:         948308 kB
leem@testpi:~ $ uname -a
Linux testpi 4.19.50-v7+ #896 SMP Thu Jun 20 16:11:44 BST 2019 armv7l GNU/Linux
leem@testpi:~ $ 


So a typical pi3b running debian buster. 

Load Blink.ino posted earlier into IDE.  Press complile...

leem@testpi:~ $ /opt/arduino-1.8.9/arduino &
[1] 2981
leem@testpi:~ $ Picked up JAVA_TOOL_OPTIONS: 
while [ 1 ] ; do date ; ps -ef | grep -c cc1plus; sleep 1; done
Sun 07 Jul 2019 02:03:53 AM EDT
1
Sun 07 Jul 2019 02:03:55 AM EDT
1
Sun 07 Jul 2019 02:03:56 AM EDT
1
Sun 07 Jul 2019 02:03:57 AM EDT
1
Sun 07 Jul 2019 02:03:58 AM EDT
1
Sun 07 Jul 2019 02:03:59 AM EDT
1
Warning: Board Breadboard Arduino:avr:atmega328bb doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA328BB
Sun 07 Jul 2019 02:04:00 AM EDT
2
Sun 07 Jul 2019 02:04:01 AM EDT
2
Sun 07 Jul 2019 02:04:02 AM EDT
2
Sun 07 Jul 2019 02:04:03 AM EDT
2
Sun 07 Jul 2019 02:04:04 AM EDT
2
Sun 07 Jul 2019 02:04:05 AM EDT
2
Sun 07 Jul 2019 02:04:06 AM EDT
2
Sun 07 Jul 2019 02:04:07 AM EDT
2
Sun 07 Jul 2019 02:04:08 AM EDT
2
Sun 07 Jul 2019 02:04:09 AM EDT
2
Sun 07 Jul 2019 02:04:10 AM EDT
2
Sun 07 Jul 2019 02:04:11 AM EDT
2
Sun 07 Jul 2019 02:04:12 AM EDT
2
Sun 07 Jul 2019 02:04:13 AM EDT
2
Sun 07 Jul 2019 02:04:14 AM EDT
2
Sun 07 Jul 2019 02:04:16 AM EDT
2
Sun 07 Jul 2019 02:04:17 AM EDT
17
Sun 07 Jul 2019 02:04:18 AM EDT
17
Sun 07 Jul 2019 02:04:19 AM EDT
17
Sun 07 Jul 2019 02:04:21 AM EDT
17
Sun 07 Jul 2019 02:04:22 AM EDT
17
Sun 07 Jul 2019 02:04:23 AM EDT
17
Sun 07 Jul 2019 02:04:25 AM EDT
17
Sun 07 Jul 2019 02:04:26 AM EDT
14
Sun 07 Jul 2019 02:04:27 AM EDT
12
Sun 07 Jul 2019 02:04:29 AM EDT
8
Sun 07 Jul 2019 02:04:30 AM EDT
6
Sun 07 Jul 2019 02:04:31 AM EDT
4
Sun 07 Jul 2019 02:04:32 AM EDT
2
Sun 07 Jul 2019 02:04:33 AM EDT
2
Sun 07 Jul 2019 02:04:34 AM EDT
1
Sun 07 Jul 2019 02:04:35 AM EDT
1
Sun 07 Jul 2019 02:04:36 AM EDT
1
Sun 07 Jul 2019 02:04:37 AM EDT
1
Sun 07 Jul 2019 02:04:38 AM EDT
22
Sun 07 Jul 2019 02:04:40 AM EDT
53
Sun 07 Jul 2019 02:04:42 AM EDT
42
Sun 07 Jul 2019 02:04:44 AM EDT
41
Sun 07 Jul 2019 02:04:46 AM EDT
40
Sun 07 Jul 2019 02:04:48 AM EDT
39

HANG FOREVER, Find the power cord.... Last I checked i had 4 cores,not ~40.

It's repeatable, but 1.8.5 is rocking hard for me on same OS, sketch, etc.

Lee

Sun 07 Jul 2019 02:04:40 AM EDT
53
Sun 07 Jul 2019 02:04:42 AM EDT
42
Sun 07 Jul 2019 02:04:44 AM EDT
41
Sun 07 Jul 2019 02:04:46 AM EDT
40
Sun 07 Jul 2019 02:04:48 AM EDT
39

So, that's counting up to 53 concurrent "cc1plus" processes?
That's really weird, since Blink.ino on my Mac only compiles 28 files (and only 20 are C++.)
My (non-existent) Go programming skills are not up to figuring out how the parallel builds are supposed to be working :frowning:

Do you feel up to trying to run arduino-builder from the cli?

I set board type to ESP8266 generic and add #include <ESP8266WiFi.h> to the blink sketch. The ESP266 board package has 176 cpp files. I see the number of cc1plus processes running go has high as 58 before the Pi freezes.

Doing the same on my desktop Ubuntu system, the cc1plus processes goes up to 17. No freezes since it has lots of RAM.

I am not a go expert but I think the following code limits the number of CPUs for the go thread scheduler. It does not limit how fast the builder calls the exec function which is used to run gcc.

        if *jobsFlag > 0 {
		runtime.GOMAXPROCS(*jobsFlag)
	} else {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}

I set board type to ESP8266 generic and add #include <ESP8266WiFi.h> to the blink sketch. The ESP266 board package has 176 cpp files. I see the number of cc1plus processes running go has high as 58 before the Pi freezes.

I get 90 compiles for similar board/sketch. I can't tell how many happen simultaneously on my system; the whole build doesn't last long enough to see anything with "top"...
For kicks, I set up a linux mint VM with one CPU and 1GB of RAM, and an AVR compile still doesn't take long enough to measure :frowning:

limits the number of CPUs for the go thread scheduler.

Yeah, but didn't see anything else that would start builds in parallel, either. It looks like everything filters down through ExecCommand() in utils.utils.go, and IT does:

    err := command.Start()
    if err != nil {
        return nil, nil, i18n.WrapError(err)
    }
    err = command.Wait()

Which certainly looks like it will wait for a particular process to finish before starting another one (unless the forking happens at a higher Go level, in which case I'd expect GOMAXPROCS to work...)

(An interesting problem. Y'all are going to end up motivating me to dust off my RPi and figure out how to get it working. It's an RPi2, which should give you an idea how long it's been sitting on a shelf. :frowning: )

And I completely understand "here's a nickle kid, get a real computer" :slight_smile:

I mostly use the Pi for sensors that are already in place. Some are in bad locations to hook a real laptop to and since the Pi can run fine off an external cell phone battery I don't even need AC handy which is nice.

So I tried to get clever. I moved arduino-builder to arduino-builder.real, made arduino-builder a script which adds '-jobs 4' to the parameters passed.

Output of arduino-builder help:

-jobs int
specify how many concurrent gcc processes should run at the same time. Defaults to the number of available cores on the running machine

I tried both -jobs=4 and -jobs 4. neither threw a syntax error but neither limited the concurrent builds.

root@pi4:/opt/arduino-1.8.9# cat arduino-builder
#!/usr/bin/perl
print "calling arduino-builder -jobs 4 @ARGV\n";
system "/opt/arduino-1.8.9/arduino-builder.real -jobs 4 @ARGV";

When I compile I see:

calling arduino-builder -jobs 4 -compile -logger=machine -hardware /opt/arduino-1.8.9/har....

I also added a 8G USB stick as device swap and hoped that would get it over the hump building the initial core. The pi didn't crash then but it hung tight enough swapping to drop the network connection and so IDE session I was tossing. I'll add vncserver and run it local, that might get it.

Reverting to 1.8.5 works as well.

Cheers!

Lee

A related issue was recently opened on GitHub and an investigation was done by one of the Arduino developers:

IDE 1.8.10 fixes the Raspberry Pi freezing problem at least in my testing.