Skip to content

Commit

Permalink
Replace fixedThreadPool with custom ThreadPoolExecutor instance
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Aug 17, 2013
1 parent c7c85e7 commit e750947
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions swarm-core/src/main/scala/swarm/Swarm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package swarm
import data.{Store, Ref}
import transport._
import util.continuations._
import java.util.concurrent.Executors
import java.util.concurrent.{ThreadPoolExecutor, TimeUnit, LinkedBlockingQueue}
import java.util.UUID

/**
Expand All @@ -15,8 +15,25 @@ object Swarm {

type swarm = cpsParam[Bee, Bee]

// TODO this is pretty hacktastic
val executor = Executors.newFixedThreadPool(10)
/**
* Mix behavior of fixedThreadPool and cachedThreadPool
* to achieve maximum performance. Creates threads as needed
* up until the maximum of 20 threads per core, kills idle threads
* after 60 seconds of inactivity, reuses threads if available, and
* will not reject thread creation if max limit is reached (those
* tasks will be queued until a thread is available)
*/
private val processorCount = Runtime.getRuntime.availableProcessors
val executor = new ThreadPoolExecutor(
// Min # of threads
processorCount,
// Max of 20 threads per core
processorCount * 20,
// Kill extra (more than processorCount) threads after 60 seconds of inactivity
60L, TimeUnit.SECONDS,
// Queue type
new LinkedBlockingQueue[Runnable]()
)

/**
* Called from concrete implementations to run the continuation
Expand Down

0 comments on commit e750947

Please sign in to comment.