Reputation: 4502
Suppose that Play framework is used, are these methods effectively the same in terms of performance?
def requestA(): Future[Response] = Future {
blockingIoRequest()
}
def requestB(): Future[Response] = {
nonBlockingIoRequest()
}
Upvotes: 0
Views: 85
Reputation: 4063
In case you described, it depends more on the fact which ExecutionContext
you use, then blocking or non blocking operation you invoke.
Basically, if in case of
def requestA(): Future[Response] = Future {
blockingIoRequest()
}
you will use same ExecutionContext
which is used in controllers (for instance for Action.async
handling), Filters
or other request handling places, then yes - it will impact performance, because blocking the thread inside such Future
execution, will impact other incoming request handling. Hence, it is recommended to perform such blocking operations inside another ExecutionContext
intended to be used for blocking operation (like DB access, network operations etc.)
Please, take a look for more details at doc page: https://www.playframework.com/documentation/2.8.x/ThreadPools
Hope this helps!
Upvotes: 1
Reputation: 1586
I think:
Nonblocking I/O will give you the best performance (thousands of requests) at the expense of being the most difficult to understand and implement correctly.
Basically everything boils down to performance vs. programming complexity.
Let me know if it helps!!
Upvotes: 1