Skip to content

Recursion on ExecutorService with >1 Thread is Slow #711

Closed
@benjchristensen

Description

@benjchristensen

Recursion on NewThreadScheduler or ExecutorScheduler with 1 thread is fast. As number of threads increase in the pool it increasingly slows down. My guess is it's adding overhead jumping between threads and/or CPUs and thus having cache misses or something along those lines.

I found this while testing TestRecursionMemoryUsage and trying Schedulers.threadPoolForComputation() versus Schedulers.newThread().

I confirmed that this changes the performance: Executors.newScheduledThreadPool(2) vs Executors.newScheduledThreadPool(1)

The real code uses numCores for that value which is worse.

We need to look at a way of using a thread-pool sized to the number of threads on the machine so we're not launching new threads every time a scheduler is used, but that recursion efficiently uses the same thread.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions