Dataflow threads pool get exhausted with a large number of tasks
Hi,
first of all, thanks. Nextflow works like a charm and made our life a lot easier. Now my question is: how can I avoid this error ?
ERROR ~ Error executing process > 'getFasta'
Caused by:
The thread pool executor cannot run the task. The upper limit of the thread pool size has probably been reached. Current pool size: 1000 Maximum pool size: 1000
I have tried to limit the maximal thread pool size via maxforks(), but that did not work. Now I am out auf ideas. Is there a method to increase the pool size or temporarily halt without crashing if the max size is reached ?
Thanks in advance !
Frankly I've never seen this error message before. Could you please include the content of the .nextflow.log file?
Have you tried to limit the number of parallel getFasta processes adding a maxForks directive? For example:
process getFasta {
maxForks 50
:
}
Yes, the maxForks = 5000 I used in this run, I used to quickly reproduce this error. Normally we use maxForks = 300 which was pretty stable up until recently. Now even a maxForks <100 is sometimes not enough to avoid this type of error. I cloud reduce it to 50 or less, but it would be great if there where another way. Our grid is good enough to handle more, in terms of performance and speed it would be sad if I had to restrict our pipeline like that.
Wait, is it this the code repoting that error?
I see there executor 'local' thus makes almost no sense to have maxForks > num-cpus. Could you please confirm that.
I've upload a new snapshot that should address this problem. You can try it declaring the NXF_VER=0.16.4-SNAPSHOT in your environment and then launching nextflow.
However I won't suggest to use such large number of maxForks. The directive is meant to bound the number of parallel processes to the available local cpus.
So, sorry for the late reply. I had to rewrite a sub-process, so it took me a while until I could test the whole thing again. But it seems to work fine. Up until now two big runs without maxForks () restrictions. Both finished without any errors. Thanks a lot!!
Good. I think the problem was a too big maxForks value. As a rule of thumb it should be <= num of avail cpus.
If you continue to experience this problem, please reopen this issue.
Just saw the same thing:
May-31 14:46:45.803 [Actor Thread 1133] ERROR nextflow.processor.TaskProcessor - Error executing process > 'blast_uniprot_parse'
Caused by:
The thread pool executor cannot run the task. The upper limit of the thread pool size has probably been reached. Current pool size: 1000 Maximum pool size: 1000
java.lang.IllegalStateException: The thread pool executor cannot run the task. The upper limit of the thread pool size has probably been reached. Current pool size: 1000 Maximum pool size: 1000
at groovyx.gpars.scheduler.ResizeablePool$2.rejectedExecution(ResizeablePool.java:87)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369)
at groovyx.gpars.scheduler.DefaultPool.execute(DefaultPool.java:155)
at groovyx.gpars.dataflow.operator.ForkingDataflowOperatorActor.startTask(ForkingDataflowOperatorActor.java:54)
at groovyx.gpars.dataflow.operator.DataflowOperatorActor.onMessage(DataflowOperatorActor.java:108)
at groovyx.gpars.actor.impl.SDAClosure$1.call(SDAClosure.java:43)
at groovyx.gpars.actor.AbstractLoopingActor.runEnhancedWithoutRepliesOnMessages(AbstractLoopingActor.java:293)
at groovyx.gpars.actor.AbstractLoopingActor.access$400(AbstractLoopingActor.java:30)
at groovyx.gpars.actor.AbstractLoopingActor$1.handleMessage(AbstractLoopingActor.java:93)
at groovyx.gpars.util.AsyncMessagingCore.run(AsyncMessagingCore.java:132)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
May-31 14:46:45.822 [Actor Thread 1133] DEBUG nextflow.Session - Session aborted -- Cause: The thread pool executor cannot run the task. The upper limit of the thread pool size has probably been reached. Current pool size: 1000 Maximu
m pool size: 1000
May-31 14:46:45.833 [Thread-1] DEBUG n.processor.TaskPollingMonitor - <<< barrier arrives (monitor: local)
The pipeline was executing locally on a machine with 64 cpus. The pipeline had already completed about 1300 processes before we ran into this error. There were no maxForks directives for any of the processes in the pipeline. Some of processes involved were executing blast and in each case the blast -num_threads argument had been set to 1.
We tried to resume the pipeline and got the exact same error.
This was using nextflow 0.24.4.
Tried running the above case with:
nextflow -Dnxf.pool.maxThreads=2000 run ...
and we still see the same exception mentioning the 1000 thread max.
Well the first question is what is spawning so many thread? Processes are bound to the avail cpus, so it should not be the problem. Do you have some operators processing a large dataset? This may requires to change/tune the underlying thread pool by using a sync or unbound thread pool.
The input is fairly large: a fasta file with ~11,000 sequences which we call splitFasta(by: 50, file: true) on. After that the channel of small fasta files splits into 11 channels. For each channel there is one process that executes a tool (e.g. blast), then a process to parse the output of said tool, and then there's a collectFile operator on the output of the final process. The pipeline is shallow, but wide. The exception comes after only about 320 processes have completed.
Try to use a different thread pool factory as suggested above.
So nextflow -Dnxf.pool.type=unbound run ... doesn't seem to work at all - nextflow just hangs at startup. Trying nextflow -Dnxf.pool.type=sync run ... kind of works. By that I mean we no longer see the thread error above, but the pipeline seems to pause for long periods of time. The nextflow process is still running, but we can't see any other activity. I don't see anything with ps -ef | grep command.run. I see a task submitted in the .nextflow.log, then I look in the work dir for that task and see a successful .exitcode, but then I see nothing in trace.txt.
What if you increase the max threads to 1000? Unfortunately this is a grey area, you may need try to tune some of these settings.
Setting -Dnxf.pool.type=sync -Dnxf.pool.maxThreads=1000 seems to produce the same behavior, which is to say a bunch of tasks get started, some even complete, and then everything just pauses. Nextflow is still running and tasks finish executing, but don't get recorded as complete and no new tasks get submitted. Given that the pool type is sync I'm wondering if the ThreadPoolExecutor is just waiting for the SynchronousQueue to give it a new thread?
I'm thinking that this problem really comes down to how our pipeline is structured. We start with this:
Channel
.fromPath(params.protInput)
.splitFasta(by: 50, file: true)
.into {
blast_nr_input
blast_uniprot_input
blast_enzyme_input
blast_cazy_input
blast_clusters_input
hmmscan_pfam_input
hmmscan_superfam_input
hmmscan_gene3d_input
hmmscan_tigrfam_input
rpsp_input
philius_input
}
With the input we have, the splitFasta results in a channel of about 220 files. 220 files times 11 channels, means there are 2420 tasks queued up to start. If each process has the default maxForks set to 64 (the number of cpus on this machine) does that mean there are potentially 64 * 11 (different processes) tasks starting at once?
I realize that each process limits how many tasks from that process can run concurrently, but does nextflow itself have any similar limit for all tasks from all processes?
To test this we've set process.maxForks = 8 in the nextflow.config and things now seem to be running and not stalling. However even now I see more than 64 .command.run.1 processes running at once...
With the input we have, the splitFasta results in a channel of about 220 files. 220 files times 11 channels, means there are 2420 tasks queued up to start.
I'm starting to think that there's something wrong at application level each data chunk does not consume a thread neither. Instead it seems that each thread is never released, thus the thread pool get quickly exhausted. Could it be there's some kind of deadlock? Is this problem happens with a specific dataset ? or does it happen on a specific machine?
If each process has the default maxForks set to 64 (the number of cpus on this machine) does that mean there are potentially 64 * 11 (different processes) tasks starting at once?
Depends. If you are using the local executor, it's caped to the avail number of cpus. If you are using a batch scheduler the limit is 100 jobs in parallel.
What executor are you using?
We've only seen this problem on one machine with one (reasonably large) data set. We're using the local executor and the machine has 64 cpus. I agree that it seems like threads aren't being released. This would explain the deadlock behavior we were seeing with the sync thread pool type. I'm also very curious why we're seeing more than 64 tasks running at once. Any ideas on how we might debug when threads are or are not getting released?
There should not be more than 64 processes. How many they are exactly? If you could include the complete nextflow log, it would help a lot.
On 2 Jun 2017 5:47 p.m., "msmootsgi" [email protected] wrote:
We've only seen this problem on one machine with one (reasonably large) data set. We're using the local executor and the machine has 64 cpus. I agree that it seems like threads aren't being released. This would explain the deadlock behavior we were seeing with the sync thread pool type. I'm also very curious why we're seeing more than 64 tasks running at once. Any ideas on how we might debug when threads are or are not getting released?
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/nextflow-io/nextflow/issues/92#issuecomment-305826929, or mute the thread https://github.com/notifications/unsubscribe-auth/AAx3SC3km--QHiME9JpfzEZI4KxnlKvnks5sAC6lgaJpZM4GtYma .
@msmootsgi Any progress on this issue ?