Windows 7 Android Studio: Is there a way to limit the gradle builds (java.exe) to certain cores (i.e. set permanent affinity)?

3,600 views
Skip to first unread message

Streets Of Boston

unread,
Feb 5, 2014, 10:43:48 AM2/5/14
to adt...@googlegroups.com
My 64 bit Windows 7 machine has 4 cores.

When Android Studio builds, the java.exe processes that are spawned take up all the CPU power of all the cores. 
This slows down the rest of my laptop, where the mouse stutters, keyboard gets unresponsive and other things slow down too much as well.

Is there a way to limit these java.exe processes, i.e. the builds, to certain core, i.e. set the affinity and do this permanently (not using the task manager, because that works only as long as the java.exe process is alive)?

I tried TaskAssign.exe, but that doesn't seem to work for the java.exe processes spawned by the build.

I tried TaskAssign.exe to limit studio64.exe. This limits the IDE itself to a limited number of cores and the java.exe spawned by studio64.exe. But still, the java.exe processes spawned by the builds are not limited.

Thanks!

Scott Barta

unread,
Feb 5, 2014, 4:40:53 PM2/5/14
to adt...@googlegroups.com
Is your problem CPU or RAM? Those sorts of symptoms sound like a machine that's hitting swap really heavily, and in that case, setting CPU affinity isn't going to help a lot.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Streets Of Boston

unread,
Feb 5, 2014, 11:27:33 PM2/5/14
to adt...@googlegroups.com
I have a quad core intel laptop, with 8GB ram and a 16GB swap file. 
Only 4 to 5 GB are in use when it's building. It seems to be a pure function of all 4 cores being used 100% by the java.exe processes used by the build.

Streets Of Boston

unread,
Feb 14, 2014, 3:26:10 PM2/14/14
to adt...@googlegroups.com
Just bumping this question a little bit. Hope you all can forgive me :)

Xavier Ducrohet

unread,
Mar 5, 2014, 5:24:21 PM3/5/14
to adt...@googlegroups.com
There's no support for this at the moment. Long term it'll be tied to the --parallel option, in particular with --parallel-threads but right now this is not the case.

Whenever a task can be parallelized with create as many threads as there are cores. We should change this, but it'll have to be with a -P option since Gradle doesn't allow you to add new command line options (yet).

So you'll need to call it with:
./gradlew -PtaskThreads=2

Would that work for you? (We'll update Studio to have the same option).

--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Xavier Ducrohet

unread,
Mar 5, 2014, 5:30:08 PM3/5/14
to adt...@googlegroups.com

Streets Of Boston

unread,
Mar 6, 2014, 10:00:58 AM3/6/14
to adt...@googlegroups.com
Thank you for entering this feature request into the issues list.

That workaround, using the -P option, would work great for now, especially under Android Studio while developing one's app.

Ryan Sweny

unread,
May 1, 2014, 4:00:24 PM5/1/14
to adt...@googlegroups.com
This has gotten really bad and annoying for me too during builds. Maybe it should use (numcores-1) threads by default. Android Studio / Gradle is the only app I've ever used that will take so much CPU it freezes the mouse and cuts audio.

Mohit Agrawal

unread,
Jul 11, 2014, 11:49:36 AM7/11/14
to adt...@googlegroups.com
How can I add this settings when android studio is building it for me?

Jia Pin Teh

unread,
May 19, 2015, 4:29:18 PM5/19/15
to adt...@googlegroups.com
Hi, anybody got a solution to this? I am using Win 7 4 cores and 8GB too. During coding my PC keep hanging and Android Studio is pushing my CPU to 100%. I tried to go to power saving mode, but that stops all the auto reference, spelling, reference etc. 

Lou Morda

unread,
Jul 10, 2015, 7:35:10 PM7/10/15
to adt...@googlegroups.com
I'm also experiencing major problems with CPU usage.  See my attached Windows Task Manager - Performance screenshot.  

I have no problems with small projects, but on a medium sized project it will take me on average 24 seconds to do a Rebuild Project and on average 37 seconds for the build when I launch the app (not included the time to upload to the device).  Most of that time is during the pre-dex and dex tasks.  All together I have 588 files in my src folder, which includes all of my java and xml files.  

I am also experiencing delays in iTunes when I am playing music.  It's very strange.  My songs literally skip as if I'm playing a scratched CD (remember those?)

This issue was filed as a ticket but for some reason it was closed:


Apparently Google is assuming all tickets before version 1.0 are now invalid.
cpu.png

Tomáš Procházka

unread,
Jul 11, 2015, 4:00:04 AM7/11/15
to adt...@googlegroups.com
Maybe android building tools should use some Thread.yield() ;-)

Reply all
Reply to author
Forward
0 new messages