Yonatan Karp-Rudin
11/04/2023, 9:01 AMdelay()
for a very long time and the other not using coroutines and using Thread.sleep()
, as you can see here:
@RestController()
@RequestMapping("users")
class UserController {
data class User(val name: String)
@GetMapping(
value = ["/delay"],
produces = ["application/json"]
)
suspend fun getDelayedUser(@RequestParam(value="name", defaultValue="Jane" ) name: String): User {
delay(10000)
return User(name)
}
@GetMapping(
value = ["/sleep"],
produces = ["application/json"]
)
fun getSleepyUser(@RequestParam(value="name", defaultValue="Jane" ) name: String): User {
Thread.sleep(10000)
return User(name)
}
}
The application is configured to use only 1 thread in the thread poll:
server.tomcat.accept-count=1
server.tomcat.threads.max=1
server.tomcat.threads.min-spare=0
server.tomcat.connection-timeout=100000
server.tomcat.keep-alive-timeout=100000
And now we're running a benchmark on the suspended endpoint:
ab -n 20 -c 10 <http://localhost:8080/users/delay>
The problem we're facing here is that the above command timing out, which is not very expected to me, as the code should be suspended, and the thread should be able to pick up a new request... so... what are we doing wrong here? 🤔kqr
11/04/2023, 12:47 PMYonatan Karp-Rudin
11/04/2023, 1:36 PMkqr
11/05/2023, 1:06 PMYonatan Karp-Rudin
11/05/2023, 5:27 PM