0
Scala에서 AkkaHttp를 사용하면 다음 코드는 /api/endpoint/{DoubleNumber}
의 끝점을 제공합니다. 이 끝점을 쿼리하면 많은 양의 계산이 수행 된 후 결과가 application/json
으로 반환됩니다. 하나는 브라우저의 콘솔, 말에서 여러 동시 요청을 보내는 경우 각 요청이 완료 될 (그리고 응답이 반환)에 대한AkkaHttp : 들어오는 요청을 여러 프로세스와 병렬로 처리
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
object Run {
def main(args: Array[String]) = {
implicit val system = ActorSystem("myApi")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
val e = get {
path("api/endpoint"/DoubleNumber) {
case (myNumberArgument) {
val result = someHeavyComputation(myNumberArgument)
complete(HttpEntity(ContentTypes.`application/json`, result.toString))
}
}
}
}
}
, 위의 코드는 다음 중 하나를 처리하기 위해 시작하기 전에 대기합니다.
위의 코드를 병렬로 작동하도록 수정하는 방법, 즉 이전 요청이 아직 처리중인 경우 들어오는 요청마다 추가 프로세스를 시작 하시겠습니까?