Last active
January 4, 2017 10:50
-
-
Save nimatrueway/f369999c615bebb9a53f0b9ac27282aa to your computer and use it in GitHub Desktop.
An example that demonstrates how asynchronous mechanism in Scala should and should not be used.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ir.taheri | |
import play.api.mvc._ | |
import scala.concurrent._ | |
import ExecutionContext.Implicits.global | |
class Controller01 { | |
def method01 = Action.async { | |
Future { | |
blocking { // We use blocking to cover the blocking area (same thing applies for cpu-intensive areas) | |
myBlocker() | |
} | |
Results.Ok("") | |
} | |
} | |
def method01C = Action.async { // an exact copy of method01 | |
Future { | |
blocking { | |
myBlocker() | |
} | |
Results.Ok("") | |
} | |
} | |
def method02 = Action.async { | |
Future { | |
myBlocker() | |
Results.Ok("") | |
} | |
} | |
private def myBlocker() { | |
Thread.sleep(1100L) | |
// you could use a cpu-intensive job like | |
// "for (i <- 0 to 999999999) {}" as well | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /method01 ir.taheri.Controller01.method01 | |
GET /method02 ir.taheri.Controller01.method02 | |
GET /method01C ir.taheri.Controller01.method01C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# these lines of code execute "method01" and "method01C" services each for #{cpu-cores} times in parallel | |
for run in {1..$(nproc --all)}; do; (time curl http://localhost:9000/method01 &); done; | |
for run in {1..$(nproc --all)}; do; (time curl http://localhost:9000/method01C &); done; | |
# Console output will be: (my system has 12 cores) | |
# | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.126 total | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.128 total | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.125 total | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.122 total | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.127 total | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.121 total | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.127 total | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.121 total | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.119 total | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.126 total | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.128 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 0% cpu 1.120 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 0% cpu 1.123 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 0% cpu 1.119 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 0% cpu 1.123 total | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.131 total | |
# curl http://localhost:9000/method01C 0.00s user 0.00s system 0% cpu 1.119 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 1% cpu 1.129 total | |
# curl http://localhost:9000/method01C 0.00s user 0.00s system 0% cpu 1.118 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 0% cpu 1.122 total | |
# curl http://localhost:9000/method01C 0.00s user 0.01s system 0% cpu 1.119 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 0% cpu 1.116 total | |
# curl http://localhost:9000/method01C 0.01s user 0.00s system 0% cpu 1.117 total | |
# curl http://localhost:9000/method01C 0.00s user 0.00s system 0% cpu 1.127 total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These lines of code execute "method01" service #{cpu-cores * 5} times | |
# and then "method02" service #{cpu-cores * 2} times | |
# all services should be invoked almost parallel, but the first group starts probably just less than a millisecond earlier | |
for run in {1..$(($(nproc --all) * 5))}; do; (time curl http://localhost:9000/method01 &); done; | |
for run in {1..$(($(nproc --all) * 2))}; do; (time curl http://localhost:9000/method02 &); done; | |
# Console output will be: (my system has 12 cores) | |
# The maximum number of active threads in forkjoinpool has become 59 | |
# | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.162 total // 1 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.171 total // 2 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.157 total // 3 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.170 total // 4 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.140 total // 5 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.179 total // 6 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.164 total // 7 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.156 total // 8 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.181 total // 9 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.169 total // 10 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.158 total // 11 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.149 total // 12 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.145 total // 13 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.170 total // 14 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.149 total // 15 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.167 total // 16 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.143 total // 17 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.159 total // 18 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.175 total // 19 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.184 total // 20 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.159 total // 21 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.173 total // 22 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.140 total // 23 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.154 total // 24 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.158 total // 25 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.156 total // 26 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.140 total // 27 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.125 total // 28 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.139 total // 29 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.127 total // 30 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.142 total // 31 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.157 total // 32 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.139 total // 33 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.153 total // 34 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.153 total // 35 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.132 total // 36 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.125 total // 37 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.157 total // 38 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.125 total // 39 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.122 total // 40 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.125 total // 41 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.167 total // 42 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.174 total // 43 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.127 total // 44 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.142 total // 45 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.125 total // 46 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.158 total // 47 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.171 total // 48 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.142 total // 49 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.141 total // 50 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.150 total // 51 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.154 total // 52 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.157 total // 53 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.134 total // 54 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.164 total // 55 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.165 total // 56 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.124 total // 57 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.140 total // 58 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.135 total // 59 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.176 total // ! //60 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.174 total // 61 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.205 total // 62 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.173 total // 63 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.156 total // 64 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.159 total // 65 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.154 total // 66 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.157 total // 67 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.155 total // 68 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.152 total // 69 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.156 total // 70 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.152 total // 71 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.152 total // 72 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.201 total // 73 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.183 total // 74 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.155 total // 75 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.176 total // 76 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.167 total // 77 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.170 total // 78 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.178 total // 79 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.158 total // 80 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.173 total // 81 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.185 total // 82 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.173 total // 83 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.173 total // 84 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These lines of code execute "method01" service #{cpu-cores * 2} times | |
# and "method02" service #{cpu-cores * 5} times | |
# all services should be invoked almost parallel, but the first group starts probably just less than a millisecond earlier | |
for run in {1..$(($(nproc --all) * 2))}; do; (time curl http://localhost:9000/method01 &); done; | |
for run in {1..$(($(nproc --all) * 5))}; do; (time curl http://localhost:9000/method02 &); done; | |
# Console output will be: (my system has 12 cores) | |
# The maximum number of active threads in forkjoinpool has become 23 | |
# | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.180 total // 1 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.159 total // 2 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.165 total // 3 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.174 total // 4 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.179 total // 5 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.172 total // 6 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.173 total // 7 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.176 total // 8 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.181 total // 9 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.164 total // 10 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.168 total // 11 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.148 total // 12 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.182 total // 13 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.167 total // 14 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.144 total // 15 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.151 total // 16 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.156 total // 17 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.159 total // 18 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.166 total // 19 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.151 total // 20 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.170 total // 21 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.153 total // 22 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 1.148 total // 23 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.229 total // ! // 24 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.233 total // 25 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.241 total // 26 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.186 total // 27 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.200 total // 28 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.213 total // 29 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.208 total // 30 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.176 total // 31 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.178 total // 32 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.260 total // 33 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.212 total // 34 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.220 total // 35 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.186 total // 36 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.212 total // 37 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.213 total // 38 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.229 total // 39 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.199 total // 40 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.220 total // 41 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.242 total // 42 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.203 total // 43 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.237 total // 44 | |
# curl http://localhost:9000/method02 0.00s user 0.01s system 0% cpu 2.194 total // 45 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.212 total // 46 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.247 total // ! // 47 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.326 total // 48 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.255 total // 49 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.283 total // 50 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.295 total // 51 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.330 total // 52 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.321 total // 53 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.252 total // 54 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.255 total // 55 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.294 total // 56 | |
# curl http://localhost:9000/method02 0.00s user 0.01s system 0% cpu 3.274 total // 57 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.284 total // 58 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.291 total // 59 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.269 total // 60 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.305 total // 61 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.244 total // 62 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.249 total // 63 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.273 total // 64 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.275 total // 65 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.247 total // 66 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.250 total // 67 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.251 total // 68 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.299 total // 69 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.374 total // ! // 70 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.354 total // 71 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 4.363 total // 72 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.362 total // 73 | |
# curl http://localhost:9000/method02 0.00s user 0.01s system 0% cpu 4.376 total // 74 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.348 total // 75 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 4.363 total // 76 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.377 total // 77 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 4.346 total // 78 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.332 total // 79 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.344 total // 80 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 4.346 total // 81 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.344 total // 82 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.343 total // 83 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.343 total // 84 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These lines of code execute "method01" and "method02" services each #{cpu-cores * 2} times | |
# and then "method01" service #{cpu-cores * 3} times | |
# all services should be invoked almost parallel, but the first group starts probably just less than a millisecond earlier | |
for run in {1..$(($(nproc --all) * 2))}; do; (time curl http://localhost:9000/method01 &); (time curl http://localhost:9000/method02 &); done; | |
for run in {1..$(($(nproc --all) * 3))}; do; (time curl http://localhost:9000/method01 &); done; | |
# Console output will be: (my system has 12 cores) | |
# The maximum number of active threads in forkjoinpool has become 12 | |
# | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.121 total // 1 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 1.120 total // 2 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.123 total // 3 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 1.124 total // 4 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.120 total // 5 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.122 total // 6 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.116 total // 7 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 1% cpu 1.120 total // 8 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.121 total // 9 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.124 total // 10 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.120 total // 11 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.119 total // 12 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.202 total // ! // 13 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 2.199 total // 14 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 2.198 total // 15 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.203 total // 16 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.188 total // 17 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.190 total // 18 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.191 total // 19 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.186 total // 20 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 2.186 total // 21 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.190 total // 22 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 2.205 total // 23 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.189 total // 24 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.273 total // ! // 25 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 3.276 total // 26 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.272 total // 27 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.291 total // 28 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 3.267 total // 29 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 3.266 total // 30 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 3.276 total // 31 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 3.265 total // 32 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.259 total // 33 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 3.258 total // 34 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 3.256 total // 35 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 3.296 total // 36 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 4.383 total // ! // 37 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 4.311 total // 38 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 4.306 total // 39 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 4.305 total // 40 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 4.303 total // 41 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 4.305 total // 42 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.383 total // 43 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 4.306 total // 44 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 4.378 total // 45 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 4.374 total // 46 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 4.377 total // 47 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 4.360 total // 48 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 5.451 total // ! // 49 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 5.464 total // 50 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 5.443 total // 51 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 5.464 total // 52 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 5.448 total // 53 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 5.447 total // 54 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 5.441 total // 55 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 5.481 total // 56 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 5.447 total // 57 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 5.449 total // 58 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 5.440 total // 59 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 5.457 total // 60 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.520 total // ! // 61 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 6.521 total // 62 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.522 total // 63 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 6.520 total // 64 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.519 total // 65 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 6.562 total // 66 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.518 total // 67 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.517 total // 68 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 6.557 total // 69 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 6.589 total // 70 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.521 total // 71 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.515 total // 72 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 6.515 total // 73 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 6.560 total // 74 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 6.564 total // 75 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 7.638 total // ! // 76 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 7.632 total // 77 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 7.632 total // 78 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 7.627 total // 79 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 7.631 total // 80 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 7.625 total // 81 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 7.630 total // 82 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 7.612 total // 83 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 7.618 total // 84 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "Scala Execution Example" | |
version := "1.0" | |
scalaVersion := "2.11.7" | |
enablePlugins(PlayScala) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this line of code executes "method01" service #{cpu-cores+1} times in parallel | |
for run in {1..$(($(nproc --all) + 1))}; do; (time curl http://localhost:9000/method01 &); done; | |
# Console output will be: (my system has 12 cores) | |
# | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.121 total // 1 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.120 total // 2 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 0% cpu 1.120 total // 3 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.119 total // 4 | |
# curl http://localhost:9000/method01 0.00s user 0.00s system 0% cpu 1.117 total // 5 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.118 total // 6 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.118 total // 7 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 1% cpu 1.120 total // 8 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.122 total // 9 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.118 total // 10 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.120 total // 11 | |
# curl http://localhost:9000/method01 0.00s user 0.01s system 1% cpu 1.122 total // 12 | |
# curl http://localhost:9000/method01 0.01s user 0.00s system 0% cpu 1.118 total // ! // 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this line of code executes "method02" service #{cpu-cores+1} times in parallel | |
for run in {1..$(($(nproc --all) + 1))}; do; (time curl http://localhost:9000/method02 &); done; | |
# Console output will be: (my system has 12 cores) | |
# | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 1.121 total // 1 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.120 total // 2 | |
# curl http://localhost:9000/method02 0.00s user 0.01s system 0% cpu 1.120 total // 3 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 1.119 total // 4 | |
# curl http://localhost:9000/method02 0.00s user 0.00s system 0% cpu 1.117 total // 5 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.118 total // 6 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.118 total // 7 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 1% cpu 1.120 total // 8 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.122 total // 9 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.118 total // 10 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 1.120 total // 11 | |
# curl http://localhost:9000/method02 0.00s user 0.01s system 1% cpu 1.122 total // 12 | |
# curl http://localhost:9000/method02 0.01s user 0.00s system 0% cpu 2.202 total // ! // 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment