I know it may look like a duplicate of How to disable Gradle daemon in IntelliJ Idea?, but I don't want to completely disable gradle daemon. I just want to use only one daemon, not many of them.
The problem I have is that to successfully run some gradle tasks I have to give about 2GB RAM to gradle. And my system only had 8GB of memory.
The problem is that when I perform certain actions (I think it's "refresh gradle projects", there are 2 of them) - I sometiems get 2 or more gradle daemons running. Each consuming 2GB of memory.
Is it possible to use only one daemon or somehow automatically stop those extra daemons?
You can stop all currently running daemons with gradlew --stop. New deamons are only created if necessary. If e. g. a different Java version is used or different daemon arguments are needed and so on. You could maybe look with Sysinternals ProcessExplorer and compare the two processes to find where they differ to find a reason why two are created.
Related
My Jenkins build hangs between build and post-build steps.
The console output shows there is a 6-minute wait (but I've seen waits of up to one hour):
10:53:26 BUILD FAILED in 1m 7s
10:53:26 4 actionable tasks: 4 executed
10:53:26 Build step 'Invoke Gradle script' changed build result to FAILURE
10:53:26 Build step 'Invoke Gradle script' marked build as failure
11:09:29 [CucumberReport] Using Cucumber Reports version 4.9.0
I found this and this questions that have similar issues, and they say the solution is setting -DSoftKillWaitSeconds=0 in jenkins.xml.
However, I need a way to set the option for particular jobs only, without messing with global Jenkins settings (I wouldn't want to mess with other projects).
EDIT:
When I manually abort the job, before the [CucumberReport] step, Cucumber reports are still generated.
I also checked Abort the build if it's stuck checkbox in Build Environment options, with Time-out strategy set to No Activity (Timeout seconds = 2).
When I build the project with these settings, the build will fail with "Aborted after 0 seconds" shown in Build History, as before, but the console output will be the same. (Nothing changes, Cucumber Reports will be generated but after a certain timeout).
It is not possible to select a job-specific value for SoftKillWaitSeconds (the value is derived from the Jenkins core at a point where the job name is not known).
My recommendation is to fix the abort handling in your job itself, so it will not depend on a "soft kill timeout". If you're running on a Unix-ish system, you can ensure this by running your job in a new process group (set -m in bash) and (for example) setting up a proper exit trap.
We are using the Build-timeout plugin to kill stuck jobs with timeout strategy set to No Activity or Absolute. For me, this is a good approach when you are using freestyle projects.
The reason why your build is "Aborted after 0 seconds" is that most likely there are unfinished child processes.
From documentation:
Because Java only allows threads to be interrupted at a set of fixed
locations, depending on how a build hangs, the abort operation might
not take effect. For example,
if Jenkins is waiting for child processes to complete, it can abort
right away.
if Jenkins is stuck in an infinite loop, it can never be
aborted.
if Jenkins is doing a network or file I/O within the Java VM
(such as lengthy file copy or SVN update), it cannot be aborted.
You could try the absolute timeout strategy. You can define a global variable, so that you do not repeat the timeout value in jobs:
Go to "Manage Jenkins" > "Configure System".
Check "Environment variables" in "Global properties".
Add an environment variable name="GLOBAL_TIMEOUT_MINUTES" value="20".
Go to a configuration page of a project.
Check "Abort the build if it's stuck" in "Build Environment".
Select "Absolute" for "Time-out strategy". Of course, also applicable to other strategies.
Set "${GLOBAL_TIMEOUT_MINUTES}" for "Timeout".
Set timeout action "Abort the build".
If this is not working, you could try to look in the logs https://your-jenkins-server/log or in a thread dump.
The hanging may be caused by new/old version of a plugin. Try to find what are the unfinished child processes. Try to disable post-build actions one by one to find the one that may be the cause of the issue.
You can see https://superuser.com/questions/1401879/debugging-what-happens-when-a-jenkins-build-unexpectedly-pauses-or-hangs
Gradle seem to be really slow for me and I have no idea why.
Whenever I run a build it takes like 30 seconds for me, according to the output 25 seconds of those it's doing nothing.
Building like this:
gradlew build --parallel --offline
This is happening to me now with Kotlin, it was the same when I was using Java only, incremental builds don't seem to do anything either
EDIT: I have the gradle daemon enabled
Every subsequent build right at the start takes as long or longer than starting the daemon apparently doing nothing
This is my Project: https://github.com/forsakenharmony/GameProt
I recommend starting with some measurement:
gradlew build --profile
Open up /report/profile in a web browser and see what it's doing.
It sounds to me like your project is taking a long time to configure. Do you have a large project or many projects in your build? Are you using a bunch of plugins?
The easy way to reduce configuration time is to configure fewer things. Remove plugins that you only use rarely. Try out the #Incubating --configure-on-demand option.
Come back after you've confirmed via profiling for further help.
You can try enabling gradle daemon.
That way gradle won't have to load from scratch every time you start a build. Instead, it will run in background waiting for a build to start.
org.gradle.daemon=true
in «USER_HOME»/.gradle/gradle.properties
My Windows 7 machine has a quad core i7 processor. When I Rebuild my project, it takes on average 25 seconds. And when I launch the app, it takes on average 36 seconds (before the app is uploaded to the device).
I have 588 files in my project's /src folder, which includes all of my java and xml code. I've got two .so libs each 5MB and 7 jars in my /libs folder.
See my attached screenshot. As you can see my CPU is maxed out at 100% the entire time. My iTunes music pauses, and I get a "Poor Performance" pop-up in the lower right hand corner of my windows taskbar. That's how bad it is.
I'm using Android Studio 1.2.1.1
Most of the time is spent during the preDex and dex operations.
Here's what I've tried so far (separately, I haven't tried them all together):
adding gradle.properties -> "org.gradle.daemon=true"
Power Saving
Mode Invalidate Caches /
Restart Global Gradle Setings -> Offline
work Compiler -> Make project automatically
Nothing has worked yet. I can't imagine that this is a common problem, am I right? Am I being too imaptient because this really is that much slower than Eclipse?
I guess my questions are:
Could this be due to the size of my jars or so files?
I tookover a project that had many nested views in XML files. Could this be causing a problem?
I'm really reaching for straws so if anyone has any information, esepecially why the dex operation is taking up so much CPU, that would be awesome.
I guess it goes without saying that this is happening if I edit an XML file, do a rebuild, and then launch the app. If there's nothing to clean and rebuild...
when I just do a Make Project... the average build time is 3 seconds.
Here are the three improvements I was able to make:
I was preDexing my JARs every time I built the project, so I found this solution:
dexOptions {
preDexLibraries = false
}
I was using the entire Google Play Services library:
compile('com.google.android.gms:play-services:+') {
exclude module: 'support-v4'
}
When all I needed was Google Cloud Messenger:
compile('com.google.android.gms:play-services-gcm:+') {
exclude module: 'support-v4'
}
In Eclipse, I would always do a Rebuild and then launch app with the play button. In Android Studio, now I am just doing a Clean and then launch app with the play button. Also the Run button in Android Studio does NOT work every time right after the Clean. This was causing what seemed to be delays because nothing was happening. So now I leave the Gradle Console open to make sure that the run button is working, and when it doesn't I just hit it a second time.
What I used to have:
Rebuild: 26 seconds
Launch: 36 seconds
Install: 15 seconds
and now:
Clean: 8 seconds
Launch: 22 seconds
Install: 15 seconds
which is a major improvement! Hopefully this helps someone else.
As stated on the tracker page for this issue, the team has identified this as the problem:
--parallel-threads only applies to project parallelization.
For android tasks that are running in parallel, we always create as
many threads as possible
From the page, it seems that they target release 1.3 to address this (see comment #13 there).
In the meantime, what has helped me to cope on Windows 7 is to set the CPU affinity for the Android Studio process (and its child processes) to spare at least one of the cores (as suggested by comment #9 on the page).
There are many ways to do this, but you might want to try the top-voted answer on this superuser question (which suggested to use Process Lasso) that appears to work well enough for me.
In addition to optimizations specific to Gradle (see below), I recommend that you try disabling anti-virus protection for your Gradle caches directory and your Android Studio project directory. For me, this reduces my build times by roughly 50%. Excluding those same directories from Windows Search indexing can also help.
Gradle optimizations I use, in ~/.gradle/gradle.properties.
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx6144m <-- Tweak this based on available RAM
org.gradle.caching=true
org.gradle.parallel=true
kotlin.incremental=true
Note that enabling caching means you sometimes have to explicitly clear your caches when switching branches. I run this script when I run into puzzling build issues.
#!/bin/bash
# Clean Android cache
./gradlew cleanBuildCache
# Clean Gradle cache, prompting for each directory
find ~/.gradle/caches -maxdepth 1 -name build-cache* -print -exec rm -rfI {} \;
# Clean Project
./gradlew clean
# Stop Gradle Daemon
./gradlew --stop
To be honest, Android Studio is hands down better than Eclipse because of the UI designer. The downside is that it uses gradle instead of Ant. Gradle is also better but slower - especially on Windows. It runs much better on Linux. If you haven't used Linux before, fear not. Linux Mint is a stable OS that has a UI that is similar to Windows. You'll be right at home in no time. It consumes fewer resources so that leaves more processing power for the gradle build. Make the switch. You'll never go back.
I'm using gradle 2.4 for a multi-project written in Java which has abount 15000 lines of code in 5 projects and i'm using Windows 7. I'm using the findbugs plugin in every sub-project.
The build itself is fast (enough) but while findbugs is running the reactivity of my PC is very bad. Most time the mouse hangs, opening websites takes a lot of time, music shutters, video hangs, etc.
If i reduce the priority of the corresponding java-process, everything is fine. For linux i found this https://askubuntu.com/questions/469709/gradle-compiling-slows-down-my-computer . I tried the suggested -PtaskThreads=x option, but that didn't help.
Is there a way to set the priority of the java-process which does the findbugs stuff to 'idle' or 'background' programmaticaly? Preferable with pure gradle options since i don't want to use some tools like CPULimit.
My project install was perfectly fine until yesterday but today my install gets stuck at the following,
Apache Maven 2.2.1 (r801777; 2009-08-06 20:16:01+0100)
Java version: 1.6.0_20
[INFO] Surefire report directory: C:\Perforce\project-name\target\surefire-reports
Basically after this line the install does not proceed at all. Any thoughts?
I have tried mvn -X and I get the same thing.
I have even upgraded to version 2.6 the latest and still get the same issue
I have ensured that there are no debug options i.e, the JVM is not waiting for any debugger to attach(-Xdebug options)
Make a thread dump of the correct process using jstack and submit an issue
I passed the forkMode=never and now I noticed that one of the tests was not starting up at all. The reason was that it was using a ehcache and stored entries in the "java.io.tmpdir" directory which was my user's temporary directory.
The system also started being slow from today. Then I noticed that my C:/users/../AppData/Local/Temp folder had about 2 million files most of them either p4ticket234234.txt or Visual studio log files.
Once I cleared these log files, my build went successful. A jconsole or some thread dump would have more indicated the same I think.
Surefire waits for all non-daemon threads in your application to finish. It's easy to miss one or another. For example make sure to call the shutdown method on your Executors if you use any. If you do thread handling on your own you basically have to either make them daemon threads or make sure they terminate. A thread dump might help to spot the lingering threads.
Use jps, jstack or jvisualvm tools from JDK to get list of processes and their thread dumps.
I had the same problem. All of a sudden my "mvn test" was hanging seemingly forever and the related org.apache.maven.surefire.booter.ForkedBooter
process was taking 1.7GB! After much investigation it turns out that the problem was that I had deleted a class that was being instantiated by spring-core as a spring bean within the spring XML configuration. Once I removed the element corresponding to the deleted class from the spring XML configuration all was well. This seems like a bug in spring and surefire usage where no reasonable warning or error is produced.