Why is the 20x Thread Ratio a sweet spot for IO? [previously: What ExecutionContext to use in playframework?]

I know how to create my own ExecutionContext or import a global playback platform. But I must admit that I am far from being an expert on how several context / executionServices functions will work in the opposite direction.

So my question is: for the best performance / behavior of my service, which should I use ExecutionContext?

I checked two options:

import play.api.libs.concurrent.Execution.defaultContext

and

implicit val executionContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()))

Both results lead to comparable characteristics.

The action I'm using is implemented in playframework 2.1.x. SedisPool is my own object with additional future packaging for the regular sedis / jedis client pool.

def testaction(application: String, platform: String) = Action {
    Async(
      SedisPool.withAsyncClient[Result] { client =>
        client.get(StringBuilder.newBuilder.append(application).append('-').append(platform).toString) match {
          case Some(x) => Ok(x)
          case None => Results.NoContent
        }
      })
  }

, Node.js Go. , . , Java ( redis jedis ). gatling. "" redis, " ". fyrie (, , API), , Sedis.

. playframework/ scala.

? - ? scala , , .

.

- !

, : Runtime.getRuntime(). AvailableProcessors() * 20

15% 20% ( ), , Node.js, ( ). :  - 15x 25x 20, , . ? ?  - , ? " "?  - 20x /jvm, ?

-

. http://www.playframework.com/documentation/2.1.0/ThreadPools

IO -, , Akka.dispatchers, *.conf ( ).

,

implicit val redis_lookup_context: ExecutionContext = Akka.system.dispatchers.lookup("simple-redis-lookup")

,

akka{
    event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
    loglevel = WARNING
    actor {
        simple-redis-lookup = {
            fork-join-executor {
                parallelism-factor = 20.0   
                #parallelism-min = 40
                #parallelism-max = 400
            }
        }
    }
}

5% - ( ) , JVM "". , .

. ?

+5
2

, , :

  • ,
  • , ,
  • , .

, , , :

  • A , ( ). JVM . (, JProfiler) )
    • , / .
  • A paging ,
    • , , .
  • , , , .
    • , (, → SSD), (1GE → 10GE) ( )

, . , CPU ( CPU). , ?

, 50% CPU 50% -. , 2x. 1% CPU, ( ) 100 .

, :

  • () . , , . , n x, n x. , n, .
  • , . , , ( ) . , . , - , , . , , 10 , , . , , , 1000 /10 100. .
  • . parallelism . , , . , parallelism . :
    • -
    • (, ). , Java , .

, , , , parallelism.

, ,

, . , / , :

  • , , :
    • SMT SMT
  • RAM .
  • :
    • .
    • Windows/Linux/BSD/etc
    • JVM ( , )
    • .
    • ,

, . ( ), . , , .

:

  • ​​- , .
  • - , ( LWP) CPU. , , , , , .

, . (, DTrace Solaris), JVM ( JProfiler). , .

, , , Scala, JVM, , Redis, , - 95% . ( , , 5%).

20 .

, :

  • , ,
  • :
    • (, RAM), ( , ~ 90%)
    • ( , ~ 95%)
+11

:

  • CachedThreadPool FixedThreadPool, , , ThreadPool, ,
  • 1 , 2?
+1

All Articles