How to control number of gradle daemons


I’m using gradle tooling API to run a gradle task. When i fire 100 parallel threads. It is producing 100 daemons. Now i want to restrict the maximum no.of gradle daemons . At any point of time i need only 20 gradle daemon. when all the 20 daemons are occupied. Others should wait till gradle daemon become free. Is there any way to achieve this?


If you only want 20 to run in parallel, why do you want 100 threads? Could you just limit the number of threads you create?

To address your actual question, I’m not aware of any options to limit the number. Daemon management has been something I’ve struggled with too (primarily from having a bunch of daemons with different versions created).

Andrew is right, there’s no real way to control this right now.

To work out a good solution, we’d need to know a bit more about what you are doing.

If you are interested in helping us improve this situation, let us know and we can start spec’ing out a way forward.

Here is my scenario:

We are working on a Deployment Tool which creates setups, where each setup has set of services. Each service owns, deploy.gradle which tells details about service like from where we need to checkout service assets and where to copy etc…

Before proceeding to deployment of service, we execute deploy.gradle of that service. So if we create multiple setups (say 5, parallelly) with each setup is having around 20 services which means tool invokes 100 deploy.gradle files for all setups which inherently creating 100 gradle daemons which we want to avoid. We need pool of daemon threads (say 20, will be good if it is configurable) which will be reused for other service’s deploy.gradle whenever they are free.

I’m curious as to why you can’t do the throttling on your side? That seems like a better option than having so many processes just sitting waiting for resources, that may timeout while waiting.